diff --git a/README.md b/README.md index 49a8ca1..630012d 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,6 @@ Here is a list of the stuff highlighted by default. It also works on copy mode, but requires *tmux 2.2* or newer to properly take the scroll position into account. -Additionally, you can install -[tmux-yank](https://github.com/tmux-plugins/tmux-yank) for system clipboard -integration. - ## Key shortcuts While in **[fingers]** mode, you can use the following shortcuts: diff --git a/docs/health-check.md b/docs/health-check.md index 695eb92..a155e70 100644 --- a/docs/health-check.md +++ b/docs/health-check.md @@ -51,12 +51,8 @@ git submodule update --init --recursive" tmux source ~/.tmux.conf" ``` -## reattach-to-user-namespace is recommended +## system clipboard integration -If you are using tmux 2.5 or less and OSX, it's recommended that you install `reattach-to-user-namespace` in for system clipboard integration. +In order for system clipboard integration to work, you need to have program in your system that manages that. -``` -brew install reattach-to-user-namespace -``` - -Remember that you need to install [tmux-yank](https://github.com/tmux-plugins/tmux-yank) as well. +Check [tmux-yank documentation](https://github.com/tmux-plugins/tmux-yank#requirements) to check what program do you need to install, depending on your platform. diff --git a/scripts/config.sh b/scripts/config.sh index c3b9a69..a34ba68 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -50,6 +50,37 @@ function strip_format () { echo "$1" | sed "s/#\[[^]]*\]//g" } +function default_copy_command () { + # installing reattach-to-user-namespace is recommended on OS X + if [[ $(program_exists "pbcopy") = "1" ]]; then + if [[ $(program_exists "reattach-to-user-namespace") = "1" ]]; then + echo "reattach-to-user-namespace pbcopy" + else + echo "pbcopy" + fi + elif [[ $(program_exists "clip.exe") = "1" ]]; then # WSL clipboard command + echo "cat | clip.exe" + elif [[ $(program_exists "wl-copy") = "1" ]]; then # wl-clipboard: Wayland clipboard utilities + echo "wl-copy" + elif [[ $(program_exists "xsel") = "1" ]]; then + echo "xsel -i --clipboard" + elif [[ $(program_exists "xclip") = "1" ]]; then + echo "xclip -selection clipboard" + elif [[ $(program_exists "putclip") = "1" ]]; then # cygwin clipboard command + echo "putclip" + fi +} + +function default_open_command () { + if [[ $(program_exists "open") = "1" ]]; then + echo "xargs open" + elif [[ $(program_exists "xdg-open") = "1" ]]; then + echo "xargs xdg-open" + elif [[ $(program_exists "cygstart") = "1" ]]; then + echo "xargs cygstart" + fi +} + PATTERNS_LIST=( "((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)" "([[:digit:]]{4,})" @@ -84,8 +115,8 @@ PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}") fingers_defaults=( \ [fingers-patterns]="$PATTERNS" \ [fingers-compact-hints]=1 \ - [fingers-copy-command]="" \ - [fingers-copy-command-uppercase]="" \ + [fingers-copy-command]="$(default_copy_command)" \ + [fingers-copy-command-uppercase]="$(default_open_command)" \ [fingers-hint-position]="left" \ [fingers-hint-format]="#[fg=yellow,bold]%s" \ diff --git a/scripts/fingers.sh b/scripts/fingers.sh index 9833dea..27f77d7 100755 --- a/scripts/fingers.sh +++ b/scripts/fingers.sh @@ -8,9 +8,6 @@ source $CURRENT_DIR/hints.sh source $CURRENT_DIR/utils.sh source $CURRENT_DIR/help.sh -HAS_TMUX_YANK=$([ "$(tmux list-keys | grep -c tmux-yank)" == "0" ]; echo $?) -tmux_yank_copy_command=$(tmux_list_vi_copy_keys | grep -E "(vi-copy|copy-mode-vi) *y" | sed -E 's/.*copy-pipe(-and-cancel)? *(.*)/\2/g') - current_pane_id=$1 fingers_pane_id=$2 last_pane_id=$3 @@ -130,10 +127,6 @@ function copy_result() { local hint="$2" tmux set-buffer "$result" - - if [[ $HAS_TMUX_YANK = 1 ]]; then - tmux run-shell -b "printf \"$result\" | $EXEC_PREFIX $(echo "$tmux_yank_copy_command")" - fi } function run_fingers_copy_command() { diff --git a/scripts/health-check.sh b/scripts/health-check.sh index 4bf84d5..9b15e20 100755 --- a/scripts/health-check.sh +++ b/scripts/health-check.sh @@ -31,17 +31,6 @@ function version_minor() { echo "$1" | cut -f2 -d. | grep -Eo "[0-9]" } -function program_exists() { - local prog="$1" - - which "$prog" &> /dev/null - - if [[ $? == "0" ]]; then - echo "1" - else - echo "0" - fi -} function log_message() { log_messages+=("$1") diff --git a/scripts/utils.sh b/scripts/utils.sh index 1e4cc49..e8dec22 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -146,3 +146,15 @@ function resolve_path() { echo "$(readlink -f "$path")" fi } + +function program_exists() { + local prog="$1" + + which "$prog" &> /dev/null + + if [[ $? == "0" ]]; then + echo "1" + else + echo "0" + fi +} diff --git a/test/conf/tmux-yank.conf b/test/conf/tmux-yank.conf deleted file mode 100644 index 2a8a11e..0000000 --- a/test/conf/tmux-yank.conf +++ /dev/null @@ -1,5 +0,0 @@ -set -g prefix C-a -set -g @fingers-compact-hints '0' -bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "bash /home/vagrant/shared/test/stubs/tmux-yank.sh" - -run /home/vagrant/shared/tmux-fingers.tmux diff --git a/test/specs/tmux-yank-integration_spec.sh b/test/specs/tmux-yank-integration_spec.sh deleted file mode 100755 index f397b24..0000000 --- a/test/specs/tmux-yank-integration_spec.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $CURRENT_DIR/../tmuxomatic.sh -source $CURRENT_DIR/../helpers.sh - -tmuxomatic__begin begin_hook - -begin_with_conf "tmux-yank" -init_pane - -tmuxomatic__exec "cat ./test/fixtures/grep-output" -invoke_fingers -tmuxomatic send-keys "d" - -tmuxomatic__sleep 1 -tmuxomatic__exec "cat /tmp/tmux-yank-result" - -tmuxomatic__expect "tmux-yank yolo" -tmuxomatic__end end_hook diff --git a/test/stubs/tmux-yank.sh b/test/stubs/tmux-yank.sh deleted file mode 100755 index cb662ea..0000000 --- a/test/stubs/tmux-yank.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo "tmux-yank yolo" > /tmp/tmux-yank-result