-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpaste-image.tmux
More file actions
38 lines (30 loc) · 1.33 KB
/
Copy pathpaste-image.tmux
File metadata and controls
38 lines (30 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# paste-image.tmux
# A helper function to get tmux options with a default value.
get_tmux_option() {
local option_name="$1"
local default_value="$2"
local option_value=$(tmux show-option -gqv "$option_name")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
# Get the directory of the current script to reliably find our `paster.sh`
# Use readlink to resolve the absolute path, works with run-shell
SCRIPT_PATH="$(readlink -f "${BASH_SOURCE[0]:-$0}")"
CURRENT_DIR="$(dirname "$SCRIPT_PATH")"
PASTER_SCRIPT="$CURRENT_DIR/scripts/paster.sh"
# --- User Configurable Options ---
# 1. Keybinding: User can set `@paste-image-key` in their .tmux.conf
# Default key is 'P'.
paste_key=$(get_tmux_option "@paste-image-key" "P")
# 2. Save Path: User can set `@paste-image-path` in their .tmux.conf
# Default is a cache directory, which is good practice.
save_path=$(get_tmux_option "@paste-image-path" "$HOME/.cache/tmux-paste-image")
# --- Main Plugin Logic ---
# Create the keybinding.
# We pass the configured save path as an argument to the script.
tmux bind-key "$paste_key" "run-shell 'bash $PASTER_SCRIPT \"$save_path\"'"
# Optional: Display a message on load (good for debugging)
# tmux display-message "tmux-paste-image plugin loaded. Press (prefix)+$paste_key to use."