From 3a12a8d42a0d5162658007f4bc9f99606d50ca6c Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Sun, 2 Dec 2018 21:07:47 +0100 Subject: [PATCH] tweaks to fingers-copy-command * Exports variables so they can be referenced in tmux.conf * Run fingers-copy-command after swapping pane so they are run in current pane context. * Fixes heredoc string bug ( fixes #63 ) --- README.md | 16 ++++++++++++---- scripts/fingers.sh | 40 ++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 25b0656..268ae86 100644 --- a/README.md +++ b/README.md @@ -129,8 +129,10 @@ invoking the plugin. `default: NONE` -By default **tmux-fingers** will just yank matches using tmux clipboard ( or -[tmux-yank](https://github.com/tmux-plugins/tmux-yank) if present ). +By default **tmux-fingers** will just yank matches using tmux clipboard. For +system clipboard integration you'll also need to install +[tmux-yank](https://github.com/tmux-plugins/tmux-yank). + If you still want to set your own custom command you can do so like this: @@ -140,8 +142,8 @@ set -g @fingers-copy-command 'xclip -selection clipboard' This command will also receive the following: - * `IS_UPPERCASE`: environment variable set to `1` or `0` depending on how the hint was introduced. - * `HINT`: environment variable the selected letter hint itself ( ex: `q`, `as`, etc... ). + * `IS_UPPERCASE`: environment variable set to `1` or `0` depending on how the hint was introduced. + * `HINT`: environment variable the selected letter hint itself ( ex: `q`, `as`, etc... ). * `stdin`: copied text will be piped to `@fingers-copy-command`. ## @fingers-copy-command-uppercase @@ -157,6 +159,12 @@ For example, this open links in browser when holding SHIFT while sele set -g @fingers-copy-command-uppercase 'xargs xdg-open' ``` +Or, for automatically pasting: + +``` +set -g @fingers-copy-command-uppercase 'tmux paste-buffer' +``` + ## @fingers-compact-hints `default: 1` diff --git a/scripts/fingers.sh b/scripts/fingers.sh index 01ae989..eb9533c 100755 --- a/scripts/fingers.sh +++ b/scripts/fingers.sh @@ -20,6 +20,12 @@ original_rename_setting=$6 BACKSPACE=$'\177' +if [[ "$OSTYPE" == "linux-gnu" ]]; then + EXEC_PREFIX="nohup" +else + EXEC_PREFIX="" +fi + # TODO not sure this is truly working function force_dim_support() { tmux set -sa terminal-overrides ",*:dim=\\E[2m" @@ -41,7 +47,6 @@ function zoom_pane() { function revert_to_original_pane() { tmux swap-pane -s "$current_pane_id" -t "$fingers_pane_id" - tmux kill-window -t "$fingers_window_id" tmux set-window-option automatic-rename "$original_rename_setting" if [[ ! -z "$last_pane_id" ]]; then @@ -50,6 +55,7 @@ function revert_to_original_pane() { fi [[ $pane_was_zoomed == "1" ]] && zoom_pane "$current_pane_id" + } function handle_exit() { @@ -116,30 +122,25 @@ function copy_result() { tmux set-buffer "$result" - if [[ "$OSTYPE" == "linux-gnu" ]]; then - exec_prefix="nohup" - else - exec_prefix="" + if [[ $HAS_TMUX_YANK = 1 ]]; then + tmux run-shell -b "printf \"$result\" | $EXEC_PREFIX $tmux_yank_copy_command" fi +} + +function run_fingers_copy_command() { + local result="$1" + local hint="$2" is_uppercase=$(echo "$input" | grep -E '^[a-z]+$' &> /dev/null; echo $?) - copy_command_parameters=<<-EOS - printf \"$result\" | - IS_UPPERCASE=$is_uppercase - HINT=$hint - CURRENT_PANE_ID=$current_pane_id - $exec_prefix - EOS - if [[ $is_uppercase == "1" ]] && [ ! -z "$FINGERS_COPY_COMMAND_UPPERCASE" ]; then - tmux run-shell -b "$copy_command_parameters $FINGERS_COPY_COMMAND_UPPERCASE" + command_to_run="$FINGERS_COPY_COMMAND_UPPERCASE" elif [ ! -z "$FINGERS_COPY_COMMAND" ]; then - tmux run-shell -b "$copy_command_parameters $FINGERS_COPY_COMMAND" + command_to_run="$FINGERS_COPY_COMMAND" fi - if [[ $HAS_TMUX_YANK = 1 ]]; then - tmux run-shell -b "printf \"$result\" | $exec_prefix $tmux_yank_copy_command" + if [[ ! -z "$command_to_run" ]]; then + tmux run-shell -b "export IS_UPPERCASE=\"$is_uppercase\" HINT=\"$hint\" && printf \"$result\" | $EXEC_PREFIX $command_to_run" fi } @@ -198,8 +199,7 @@ while read -rsn1 char; do fi copy_result "$result" "$input" - revert_to_original_pane - - exit 0 + run_fingers_copy_command "$result" "$input" + tmux kill-window -t "$fingers_window_id" done < /dev/tty