From a5daac5e48007a5ee759a4633ff3be0322fa03bc Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Sun, 2 Apr 2017 17:55:39 +0200 Subject: [PATCH 01/20] initial health check implementation --- README.md | 4 +-- scripts/health-check.sh | 77 +++++++++++++++++++++++++++++++++++++++++ tmux-fingers.tmux | 2 ++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100755 scripts/health-check.sh diff --git a/README.md b/README.md index a79b6a4..18b2e11 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,9 @@ While in **[fingers]** mode, you can use the following shortcuts: # Requirements -* bash 4+ * tmux 2.1+ ( 2.2 recommended ) -* gawk ( optional but recommended ) +* bash 4+ +* gawk # Installation diff --git a/scripts/health-check.sh b/scripts/health-check.sh new file mode 100755 index 0000000..65d9c8c --- /dev/null +++ b/scripts/health-check.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $CURRENT_DIR/utils.sh +source $CURRENT_DIR/debug.sh + +REQUIRED_BASH_MAJOR=4 +REQUIRED_TMUX_MAJOR=2 +RECOMMENDED_TMUX_MINOR=3 +HELP_LINK="https://github.com/Morantron/tmux-fingers/blob/master/docs/health-check.md" + +health_tmp=$(fingers_tmp) + +function is_tmux_ready() { + local num_windows=$(tmux list-windows | wc -l) + + if [[ $num_windows -gt 0 ]]; then + echo 1 + else + echo 0 + fi +} + +function program_exists() { + local prog="$1" + + if [[ $(which "$prog" &> /dev/null) ]]; then + echo "0" + else + echo "1" + fi +} + +function log_health() { + echo "$1" >> "$health_tmp" +} + +function perform_health_check() { + local healthy=1 + + if [[ $(program_exists "gawk") = "0" ]]; then + log_health "* 'gawk' not found" + healthy=0 + fi + + BASH_MAJOR=$(echo "$BASH_VERSION" | grep -Eo "^[0-9]") + + if [[ "$BASH_MAJOR" -lt "$REQUIRED_BASH_MAJOR" ]]; then + log_health "* Bash version \"$BASH_VERSION\" is too old." + healthy=0 + fi + + TMUX_VERSION=$(tmux -V | grep -Eio "[0-9]+(\.[0-9a-z])*$") + TMUX_MAJOR=$(echo "$TMUX_VERSION" | cut -f1 -d.) + TMUX_MINOR=$(echo "$TMUX_VERSION" | cut -f2 -d. | grep -Eo "[0-9]") + + if [[ $TMUX_MAJOR -lt $REQUIRED_TMUX_MAJOR ]]; then + log_health "* tmux version \"$TMUX_VERSION\" is too old." + healthy=0 + fi + + if [[ $TMUX_MAJOR -eq $REQUIRED_TMUX_MAJOR ]] && [[ $TMUX_MINOR -lt $RECOMMENDED_TMUX_MINOR ]]; then + echo "* WARNING: tmux 2.2+ is recommended" + fi + + if [[ $healthy -eq 0 ]]; then + while [[ $(is_tmux_ready) = 0 ]]; do + : # waiting for-tmux + done + + tmux run "echo -e 'tmux-fingers health-check:\\n\\n'; cat $health_tmp" + fi + + rm -rf "$health_tmp" +} + +perform_health_check diff --git a/tmux-fingers.tmux b/tmux-fingers.tmux index 8f36124..940ee57 100755 --- a/tmux-fingers.tmux +++ b/tmux-fingers.tmux @@ -1,8 +1,10 @@ #!/usr/bin/env bash CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + DEFAULT_FINGERS_KEY="F" FINGERS_KEY=$(tmux show-option -gqv @fingers-key) FINGERS_KEY=${FINGERS_KEY:-$DEFAULT_FINGERS_KEY} +tmux run -b "$CURRENT_DIR/scripts/health-check.sh" tmux bind-key $FINGERS_KEY run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh" From 2f0487280d712f990ab99c18c23add841c66adbc Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Sun, 2 Apr 2017 18:19:15 +0200 Subject: [PATCH 02/20] gawk all the things --- scripts/config.sh | 30 +++++++----------------------- scripts/hints.sh | 2 +- scripts/utils.sh | 8 -------- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/scripts/config.sh b/scripts/config.sh index 9b23fd7..1099334 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -14,31 +14,15 @@ function check_pattern() { fi } -HAS_GAWK=$(which gawk &> /dev/null && echo $(($? == 0))) - -function supports_intervals_in_awk() { - echo "wtfwtfwtf" | __awk__ "/(wtf){3}/ { print \"wtf\" }" | grep -c wtf -} - source "$CURRENT_DIR/utils.sh" -if [[ $(supports_intervals_in_awk) == "1" ]]; then - PATTERNS_LIST=( - "((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)" - "([[:digit:]]{4,})" - "([0-9a-f]{7,40})" - "((https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*)" - "([[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})" - ) -else - PATTERNS_LIST=( - "((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)" - "([[:digit:]][[:digit:]][[:digit:]][[:digit:]]([[:digit:]])*)" - "([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]|[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])" - "((https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*)" - "([[:digit:]][[:digit:]]?[[:digit:]]?\.[[:digit:]][[:digit:]]?[[:digit:]]?\.[[:digit:]][[:digit:]]?[[:digit:]]?\.[[:digit:]][[:digit:]]?[[:digit:]]?)" - ) -fi +PATTERNS_LIST=( +"((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)" +"([[:digit:]]{4,})" +"([0-9a-f]{7,40})" +"((https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*)" +"([[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})" +) IFS=$'\n' USER_DEFINED_PATTERNS=($(tmux show-options -g | sed -n 's/^@fingers-pattern-[0-9]\{1,\} "\(.*\)"$/(\1)/p')) diff --git a/scripts/hints.sh b/scripts/hints.sh index 9356d47..64c3854 100755 --- a/scripts/hints.sh +++ b/scripts/hints.sh @@ -30,7 +30,7 @@ function show_hints() { local compact_hints=$2 clear_screen "$fingers_pane_id" - get_stdin | COMPACT_HINTS=$compact_hints FINGER_PATTERNS=$PATTERNS __awk__ -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table + get_stdin | COMPACT_HINTS=$compact_hints FINGER_PATTERNS=$PATTERNS gawk -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table } function show_hints_and_swap() { diff --git a/scripts/utils.sh b/scripts/utils.sh index ab03151..c64ff12 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -87,14 +87,6 @@ function fingers_tmp() { echo "$tmp_path" } -function __awk__() { - if hash gawk 2>/dev/null; then - gawk "$@" - else - awk "$@" - fi -} - function clear_screen() { local fingers_pane_id=$1 clear From f41464ca71f3d15a23e17092c7814447f0feb51d Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Sun, 2 Apr 2017 19:51:19 +0200 Subject: [PATCH 03/20] add docs and docs link --- docs/health-check.md | 28 ++++++++++++++++++++++++++++ scripts/health-check.sh | 4 +++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 docs/health-check.md diff --git a/docs/health-check.md b/docs/health-check.md new file mode 100644 index 0000000..a3274e3 --- /dev/null +++ b/docs/health-check.md @@ -0,0 +1,28 @@ +# Health check troubleshooting + +*tmux-fingers* performs a health check on startup to ensure that your system has all dependencies needed to run smoothly. + +They are not much, and in most GNU/linux environments these are the defaults anyway. + +## gawk not found + +Install `gawk` package. + +### OSX + +`$ brew install gawk` + +### Linux + +* Ubuntu: `$ sudo aptitude install gawk` +* Arch linux: `$ sudo pacman -S install gawk` + +## bash version is too old + +This probably means you are running OSX, which ships with *bash 3*. In order to upgrade to *bash 4* you need need to run: + +`$ brew install bash` + +## tmux version is too old + +You can install latest *tmux* from source, check https://github.com/tmux/tmux diff --git a/scripts/health-check.sh b/scripts/health-check.sh index 65d9c8c..51545e2 100755 --- a/scripts/health-check.sh +++ b/scripts/health-check.sh @@ -68,7 +68,9 @@ function perform_health_check() { : # waiting for-tmux done - tmux run "echo -e 'tmux-fingers health-check:\\n\\n'; cat $health_tmp" + log_health "For more info check $HELP_LINK" + log_health "To skip this check add \"set -g @fingers-skip-health-check 1\" to your tmux conf" + tmux run "echo -e \"tmux-fingers health-check:\"; cat $health_tmp" fi rm -rf "$health_tmp" From 45a99c88230d570dcd2a3f0cd50c07332cde0dcb Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 7 Apr 2017 08:29:13 +0200 Subject: [PATCH 04/20] better formatting in health check --- docs/health-check.md | 8 ++++ scripts/health-check.sh | 95 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 93 insertions(+), 10 deletions(-) diff --git a/docs/health-check.md b/docs/health-check.md index a3274e3..6bfd954 100644 --- a/docs/health-check.md +++ b/docs/health-check.md @@ -26,3 +26,11 @@ This probably means you are running OSX, which ships with *bash 3*. In order to ## tmux version is too old You can install latest *tmux* from source, check https://github.com/tmux/tmux + +## How to skip the check + +If can't skip this check by adding the following in your .tmux.conf file: + +``` +set -g @fingers-skip-health-check '1' +``` diff --git a/scripts/health-check.sh b/scripts/health-check.sh index 51545e2..a4d10da 100755 --- a/scripts/health-check.sh +++ b/scripts/health-check.sh @@ -2,7 +2,6 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $CURRENT_DIR/utils.sh -source $CURRENT_DIR/debug.sh REQUIRED_BASH_MAJOR=4 REQUIRED_TMUX_MAJOR=2 @@ -10,6 +9,7 @@ RECOMMENDED_TMUX_MINOR=3 HELP_LINK="https://github.com/Morantron/tmux-fingers/blob/master/docs/health-check.md" health_tmp=$(fingers_tmp) +log_messages=() function is_tmux_ready() { local num_windows=$(tmux list-windows | wc -l) @@ -31,22 +31,88 @@ function program_exists() { fi } -function log_health() { - echo "$1" >> "$health_tmp" +function log_message() { + log_messages+=("$1") +} + +function repeat_char() { + local char="$1" + local n_times="$2" + local i=0 + local output="" + + while [[ $i -lt "$n_times" ]]; do + output="$output$char" + i=$((i + 1)) + done + + echo "$output" +} + +function right_pad() { + local str="$1" + local char="$2" + local max_length="$3" + local padding=$(($max_length - ${#str})) + + if [[ padding -lt 0 ]]; then + padding=0 + fi + + echo "$str$(repeat_char "$char" "$padding")" +} + +function dump_log() { + log_messages=("tmux-fingers health-check:" "" "${log_messages[@]}") + + # pad messages + local i=0 + for message in "${log_messages[@]}" ; do + log_messages[$i]=" $message " + i=$((i + 1)) + done + + # calculate max_length + local lengths="" + for message in "${log_messages[@]}" ; do + lengths="$lengths\n${#message}" + done + local max_length=$(echo -e "$lengths" | sort -r | head -n 1) + + local horizontal_border="+$(repeat_char "-" $((max_length)))+" + + # wrap messages within pipe chars + i=0 + for message in "${log_messages[@]}" ; do + log_messages[$i]="|$(right_pad "$message" " " $((max_length)))|" + i=$((i + 1)) + done + + log_messages=($horizontal_border "${log_messages[@]}" $horizontal_border) + + for message in "${log_messages[@]}" ; do + echo -e "$message" >> "$health_tmp" + done } function perform_health_check() { local healthy=1 + FINGERS_SKIP_HEALTH_CHECK=$(tmux show-option -gqv @fingers-skip-health-check) + + if [[ $FINGERS_SKIP_HEALTH_CHECK -eq 1 ]]; then + return + fi + if [[ $(program_exists "gawk") = "0" ]]; then - log_health "* 'gawk' not found" + log_message "* 'gawk' not found" healthy=0 fi BASH_MAJOR=$(echo "$BASH_VERSION" | grep -Eo "^[0-9]") if [[ "$BASH_MAJOR" -lt "$REQUIRED_BASH_MAJOR" ]]; then - log_health "* Bash version \"$BASH_VERSION\" is too old." + log_message " * Bash version \"$BASH_VERSION\" is too old." healthy=0 fi @@ -55,12 +121,12 @@ function perform_health_check() { TMUX_MINOR=$(echo "$TMUX_VERSION" | cut -f2 -d. | grep -Eo "[0-9]") if [[ $TMUX_MAJOR -lt $REQUIRED_TMUX_MAJOR ]]; then - log_health "* tmux version \"$TMUX_VERSION\" is too old." + log_message " * tmux version \"$TMUX_VERSION\" is too old." healthy=0 fi if [[ $TMUX_MAJOR -eq $REQUIRED_TMUX_MAJOR ]] && [[ $TMUX_MINOR -lt $RECOMMENDED_TMUX_MINOR ]]; then - echo "* WARNING: tmux 2.2+ is recommended" + echo " * WARNING: tmux 2.2+ is recommended" fi if [[ $healthy -eq 0 ]]; then @@ -68,9 +134,18 @@ function perform_health_check() { : # waiting for-tmux done - log_health "For more info check $HELP_LINK" - log_health "To skip this check add \"set -g @fingers-skip-health-check 1\" to your tmux conf" - tmux run "echo -e \"tmux-fingers health-check:\"; cat $health_tmp" + log_message "" + log_message "For a better tmux-fingers experience, please install the required versions." + log_message "" + log_message "For more info check:" + log_message " $HELP_LINK" + log_message "" + log_message "To skip this check add \"set -g @fingers-skip-health-check '1'\" to your tmux conf" + log_message "" + + dump_log + + tmux run "cat $health_tmp" fi rm -rf "$health_tmp" From e3a2bccabd95ea1619fb353360f754775a83cedf Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 7 Apr 2017 09:22:34 +0200 Subject: [PATCH 05/20] add gawk to BSD provisioning --- test/provisioning/bsd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/provisioning/bsd.sh b/test/provisioning/bsd.sh index bf043ea..e4a7a48 100644 --- a/test/provisioning/bsd.sh +++ b/test/provisioning/bsd.sh @@ -1,6 +1,6 @@ #!/bin/sh -pkg install -y bash tmux expect fish +pkg install -y bash tmux expect fish gawk chsh -s bash vagrant echo "fishman" | pw user add -n fishman -h 0 -s "/usr/local/bin/fish" From 0c9bf307a912878a65008ba3855d5c2fe3913221 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 7 Apr 2017 09:26:04 +0200 Subject: [PATCH 06/20] add version to help screen --- scripts/help.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/help.sh b/scripts/help.sh index 8aa3574..e6e8c92 100644 --- a/scripts/help.sh +++ b/scripts/help.sh @@ -3,12 +3,16 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $CURRENT_DIR/utils.sh +pushd $CURRENT_DIR +FINGERS_VERSION=$(git describe --tags | sed "s/-.*//g") +popd + function show_help() { fingers_pane_id=$1 clear_screen "$fingers_pane_id" cat << ENDOFHELP -tmux-fingers help: +tmux-fingers ( $FINGERS_VERSION ) help: - a-z: yank a highlighted hint - : toggle compact hints on/off From 85f8f9ec6474472b79b99ba0ec17bde642f3b986 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 7 Apr 2017 09:27:29 +0200 Subject: [PATCH 07/20] updated CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c83da7e..4bc8e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.4.0 - 07 Apr 2017 + +* `gawk` is now a required dependency. +* Added a system health check on startup. + ## 0.3.8 - 14 Feb 2017 * Fixed support for fish shell. From a604664af71e575d9788f0097a8dd928797d28e6 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Sun, 9 Apr 2017 13:23:56 +0200 Subject: [PATCH 08/20] add newest gawk to ubuntu provisioning --- circle.yml | 2 ++ test/provisioning/ubuntu.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/circle.yml b/circle.yml index dde07e8..973ed0a 100644 --- a/circle.yml +++ b/circle.yml @@ -3,6 +3,8 @@ dependencies: - if [[ ! -e tmux-2.2 ]]; then sudo bash ./test/provisioning/ubuntu.sh; fi - sudo mkdir -p /home/vagrant/ && sudo chmod a+w /home/vagrant && ln -s $(pwd) /home/vagrant/shared - tmux -V + - gawk -W version + - bash --version test: override: - ./test/run.sh within-vm diff --git a/test/provisioning/ubuntu.sh b/test/provisioning/ubuntu.sh index 9e222b4..e79c61e 100644 --- a/test/provisioning/ubuntu.sh +++ b/test/provisioning/ubuntu.sh @@ -2,6 +2,7 @@ apt-get remove -y tmux apt-get install -y libevent-dev libncurses5-dev expect fish +apt-get install -y gawk useradd -m -p "$(perl -e "print crypt('fishman','sa');")" -s "/usr/bin/fish" fishman From e669ed18508a294e44c99ba1626cc6c3de8e9653 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Sun, 9 Apr 2017 17:40:15 +0200 Subject: [PATCH 09/20] improving health cheack and adding at least gawk 4 --- circle.yml | 2 +- scripts/health-check.sh | 43 +++++++++++++++++++++++++------------ test/provisioning/ubuntu.sh | 8 ++++--- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/circle.yml b/circle.yml index 973ed0a..8487f6c 100644 --- a/circle.yml +++ b/circle.yml @@ -1,6 +1,6 @@ dependencies: pre: - - if [[ ! -e tmux-2.2 ]]; then sudo bash ./test/provisioning/ubuntu.sh; fi + - sudo bash ./test/provisioning/ubuntu.sh - sudo mkdir -p /home/vagrant/ && sudo chmod a+w /home/vagrant && ln -s $(pwd) /home/vagrant/shared - tmux -V - gawk -W version diff --git a/scripts/health-check.sh b/scripts/health-check.sh index a4d10da..5351fca 100755 --- a/scripts/health-check.sh +++ b/scripts/health-check.sh @@ -4,7 +4,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $CURRENT_DIR/utils.sh REQUIRED_BASH_MAJOR=4 -REQUIRED_TMUX_MAJOR=2 +REQUIRED_GAWK_MAJOR=4 RECOMMENDED_TMUX_MINOR=3 HELP_LINK="https://github.com/Morantron/tmux-fingers/blob/master/docs/health-check.md" @@ -21,6 +21,14 @@ function is_tmux_ready() { fi } +function version_major() { + echo "$1" | cut -f1 -d. | grep -Eo "[0-9]" +} + +function version_minor() { + echo "$1" | cut -f2 -d. | grep -Eo "[0-9]" +} + function program_exists() { local prog="$1" @@ -98,34 +106,41 @@ function dump_log() { function perform_health_check() { local healthy=1 + # BASH_VERSION is a global + local TMUX_VERSION=$(tmux -V | grep -Eio "[0-9]+(\.[0-9a-z])*$") + local GAWK_VERSION="" + + if [[ $(program_exists "gawk") = "1" ]]; then + GAWK_VERSION=$(gawk -W version | grep -Eo "[0-9]+\.[0-9]\.[0-9]" | head -n 1) + fi + FINGERS_SKIP_HEALTH_CHECK=$(tmux show-option -gqv @fingers-skip-health-check) if [[ $FINGERS_SKIP_HEALTH_CHECK -eq 1 ]]; then return fi - if [[ $(program_exists "gawk") = "0" ]]; then - log_message "* 'gawk' not found" + if [[ $(program_exists "gawk") = 0 ]]; then + log_message " * 'gawk' not found" healthy=0 fi - BASH_MAJOR=$(echo "$BASH_VERSION" | grep -Eo "^[0-9]") - - if [[ "$BASH_MAJOR" -lt "$REQUIRED_BASH_MAJOR" ]]; then - log_message " * Bash version \"$BASH_VERSION\" is too old." + if [[ $(version_major "$BASH_VERSION") -lt "$REQUIRED_BASH_MAJOR" ]]; then + log_message " * bash version \"$BASH_VERSION\" is too old. bash $REQUIRED_BASH_MAJOR.x+ is required." healthy=0 fi - TMUX_VERSION=$(tmux -V | grep -Eio "[0-9]+(\.[0-9a-z])*$") - TMUX_MAJOR=$(echo "$TMUX_VERSION" | cut -f1 -d.) - TMUX_MINOR=$(echo "$TMUX_VERSION" | cut -f2 -d. | grep -Eo "[0-9]") - - if [[ $TMUX_MAJOR -lt $REQUIRED_TMUX_MAJOR ]]; then - log_message " * tmux version \"$TMUX_VERSION\" is too old." + if [[ $(program_exists "gawk") = 1 ]] && [[ $(version_major "$GAWK_VERSION") -lt "$REQUIRED_GAWK_MAJOR" ]]; then + log_message " * gawk version \"$GAWK_VERSION\" is too old. gawk $REQUIRED_GAWK_MAJOR.x+ is required." healthy=0 fi - if [[ $TMUX_MAJOR -eq $REQUIRED_TMUX_MAJOR ]] && [[ $TMUX_MINOR -lt $RECOMMENDED_TMUX_MINOR ]]; then + if [[ $(version_major "$TMUX_VERSION") -lt $REQUIRED_TMUX_MAJOR ]]; then + log_message " * tmux version \"$TMUX_VERSION\" is too old. tmux $REQUIRED_TMUX_MAJOR.$RECOMMENDED_TMUX_MINOR+ is required." + healthy=0 + fi + + if [[ $(version_major "$TMUX_VERSION") -eq $REQUIRED_TMUX_MAJOR ]] && [[ $(version_minor "$TMUX_VERSION") -lt $RECOMMENDED_TMUX_MINOR ]]; then echo " * WARNING: tmux 2.2+ is recommended" fi diff --git a/test/provisioning/ubuntu.sh b/test/provisioning/ubuntu.sh index e79c61e..2d20a80 100644 --- a/test/provisioning/ubuntu.sh +++ b/test/provisioning/ubuntu.sh @@ -1,13 +1,15 @@ #!/bin/sh -apt-get remove -y tmux -apt-get install -y libevent-dev libncurses5-dev expect fish -apt-get install -y gawk +sudo aptitude update +sudo aptitude install -y expect fish gawk useradd -m -p "$(perl -e "print crypt('fishman','sa');")" -s "/usr/bin/fish" fishman wget https://github.com/tmux/tmux/releases/download/2.2/tmux-2.2.tar.gz +# install tmux from source +sudo aptitude remove -y tmux +sudo aptitude install -y libevent-dev libncurses5-dev tar xvzf tmux-2.2.tar.gz cd tmux-2.2/ || echo "Could not find tmux-2.2/ folder" || exit 1 From 7d89dbf40fc159977fdac80b5110436e38d3fde9 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Sun, 9 Apr 2017 20:32:40 +0200 Subject: [PATCH 10/20] updated CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bc8e1f..79f51bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.4.1 - 09 Apr 2017 + +* Looks like `gawk` should be 4+ for things to go smooth. +* Improved output of system health check. + ## 0.4.0 - 07 Apr 2017 * `gawk` is now a required dependency. From b25d08d25e0e1d88f4d13d7347d3979ff2f2c494 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Mon, 10 Apr 2017 19:32:33 +0200 Subject: [PATCH 11/20] New bindings for tmux 2.3 --- scripts/actions.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/actions.sh b/scripts/actions.sh index 17ea5e5..46a35f8 100755 --- a/scripts/actions.sh +++ b/scripts/actions.sh @@ -10,7 +10,7 @@ function start_copy_mode() { function start_selection() { if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys "Space" + tmux send-keys -X begin-selection else tmux send-keys "C-Space" fi @@ -18,7 +18,7 @@ function start_selection() { function top_of_buffer() { if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys "H" + tmux send-keys -X top-line else tmux send-keys "M-R" fi @@ -26,7 +26,7 @@ function top_of_buffer() { function start_of_line() { if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys "0" + tmux send-keys -X start-of-line else tmux send-keys "C-a" fi @@ -34,7 +34,7 @@ function start_of_line() { function end_of_line() { if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys "$" + tmux send-keys -X end-of-line else tmux send-keys "C-e" fi @@ -42,7 +42,7 @@ function end_of_line() { function cursor_left() { if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys "h" + tmux send-keys -X cursor-left fi } @@ -53,7 +53,7 @@ function copy_selection() { fi if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys "Enter" + tmux send-keys -X copy-selection-and-cancel else tmux send-keys "M-w" fi From 0325e70e3c408902e6eff6a9ede6ea171fe6bca1 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Tue, 11 Apr 2017 10:06:57 +0000 Subject: [PATCH 12/20] Remove actions --- scripts/actions.sh | 60 ---------------------------------------------- scripts/fingers.sh | 32 +++++++------------------ 2 files changed, 9 insertions(+), 83 deletions(-) delete mode 100755 scripts/actions.sh diff --git a/scripts/actions.sh b/scripts/actions.sh deleted file mode 100755 index 46a35f8..0000000 --- a/scripts/actions.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash - -CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -TMUX_COPY_MODE=$(tmux show-option -gwv mode-keys) -HAS_TMUX_YANK=$([ "$(tmux list-keys | grep -c tmux-yank)" == "0" ]; echo $?) - -function start_copy_mode() { - tmux copy-mode -} - -function start_selection() { - if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys -X begin-selection - else - tmux send-keys "C-Space" - fi -} - -function top_of_buffer() { - if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys -X top-line - else - tmux send-keys "M-R" - fi -} - -function start_of_line() { - if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys -X start-of-line - else - tmux send-keys "C-a" - fi -} - -function end_of_line() { - if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys -X end-of-line - else - tmux send-keys "C-e" - fi -} - -function cursor_left() { - if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys -X cursor-left - fi -} - -function copy_selection() { - if [ "$HAS_TMUX_YANK" == "1" ]; then - tmux send-keys "y" - return - fi - - if [ "$TMUX_COPY_MODE" == "vi" ]; then - tmux send-keys -X copy-selection-and-cancel - else - tmux send-keys "M-w" - fi -} diff --git a/scripts/fingers.sh b/scripts/fingers.sh index 1c70a57..7620c7a 100755 --- a/scripts/fingers.sh +++ b/scripts/fingers.sh @@ -3,7 +3,6 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $CURRENT_DIR/config.sh -source $CURRENT_DIR/actions.sh source $CURRENT_DIR/hints.sh source $CURRENT_DIR/utils.sh source $CURRENT_DIR/help.sh @@ -39,24 +38,6 @@ function handle_exit() { rm -rf "$pane_input_temp" "$pane_output_temp" "$match_lookup_table" } -function copy_result() { - local result=$1 - - clear - echo -n "$result" - start_copy_mode - top_of_buffer - start_of_line - start_selection - end_of_line - cursor_left - copy_selection - - if [ ! -z "$FINGERS_COPY_COMMAND" ]; then - echo -n "$result" | eval "nohup $FINGERS_COPY_COMMAND" > /dev/null - fi -} - function is_valid_input() { local input=$1 local is_valid=1 @@ -152,15 +133,20 @@ while read -rsn1 char; do show_hints "$fingers_pane_id" $compact_state fi - result=$(lookup_match "$input") - - tmux display-message "$input" + result=$(lookup_match "$input" | head -n 1) if [[ -z $result ]]; then continue fi - copy_result "$result" + tmux display-message "'$result' copied!" + + if [ ! -z "$FINGERS_COPY_COMMAND" ]; then + echo -n "$result" | eval "nohup $FINGERS_COPY_COMMAND" > /dev/null + else + tmux set-buffer "$result" + fi + revert_to_original_pane "$current_pane_id" "$fingers_pane_id" exit 0 From 695bbc7b3e19bfe0f538e11e36ff2f5a9d74a45f Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Wed, 12 Apr 2017 08:37:18 +0200 Subject: [PATCH 13/20] small changes in tmux-next send-keys breaking change --- scripts/fingers.sh | 20 ++++++++++++-------- scripts/hints.sh | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/fingers.sh b/scripts/fingers.sh index 7620c7a..bdddb4c 100755 --- a/scripts/fingers.sh +++ b/scripts/fingers.sh @@ -90,6 +90,16 @@ function toggle_help() { fi } +function copy_result() { + local result="$1" + + tmux set-buffer "$result" + + if [ ! -z "$FINGERS_COPY_COMMAND" ]; then + echo -n "$result" | eval "nohup $FINGERS_COPY_COMMAND" > /dev/null + fi +} + while read -rsn1 char; do # Escape sequence, flush input if [[ "$char" == $'\x1b' ]]; then @@ -133,19 +143,13 @@ while read -rsn1 char; do show_hints "$fingers_pane_id" $compact_state fi - result=$(lookup_match "$input" | head -n 1) + result=$(lookup_match "$input") if [[ -z $result ]]; then continue fi - tmux display-message "'$result' copied!" - - if [ ! -z "$FINGERS_COPY_COMMAND" ]; then - echo -n "$result" | eval "nohup $FINGERS_COPY_COMMAND" > /dev/null - else - tmux set-buffer "$result" - fi + copy_result "$result" revert_to_original_pane "$current_pane_id" "$fingers_pane_id" diff --git a/scripts/hints.sh b/scripts/hints.sh index 64c3854..6a5ae7f 100755 --- a/scripts/hints.sh +++ b/scripts/hints.sh @@ -13,7 +13,7 @@ export pane_output_temp function lookup_match() { local input=$1 - echo "$(cat $match_lookup_table | grep "^$input:" | sed "s/^$input://")" + echo "$(cat $match_lookup_table | grep "^$input:" | sed "s/^$input://" | head -n 1)" } function get_stdin() { From 665be3ad58c1a39dd1916d012fc0dd2ee3cc1540 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Wed, 19 Apr 2017 19:46:00 +0200 Subject: [PATCH 14/20] rewrite specs in bash --- test/conf/fish.conf | 1 - test/conf/tmuxomatic.conf | 4 + test/helpers.sh | 59 ++++++++++++ test/provisioning/bsd.sh | 1 + test/run.sh | 2 +- test/specs/basic-yank_spec.exp | 23 ----- test/specs/basic-yank_spec.sh | 20 ++++ test/specs/fish-support_spec.exp | 23 ----- test/specs/fish-support_spec.sh | 18 ++++ test/specs/matches-custom-patterns_spec.exp | 32 ------- test/specs/matches-custom-patterns_spec.sh | 26 ++++++ .../more-than-one-match-per-line_spec.exp | 23 ----- .../more-than-one-match-per-line_spec.sh | 20 ++++ test/specs/preserve-zoom-state_spec.exp | 32 ------- test/specs/preserve-zoom-state_spec.sh | 23 +++++ test/specs/tmux-yank-integration_spec.exp | 27 ------ test/specs/tmux-yank-integration_spec.sh | 20 ++++ .../specs/works-with-custom-bindings_spec.exp | Bin 386 -> 0 bytes test/specs/works-with-custom-bindings_spec.sh | 21 +++++ test/tmuxomatic.rFvj4QV | 0 test/tmuxomatic.sh | 87 ++++++++++++++++++ tmuxomatic-test.sh | 4 + 22 files changed, 304 insertions(+), 162 deletions(-) create mode 100644 test/conf/tmuxomatic.conf create mode 100644 test/helpers.sh delete mode 100755 test/specs/basic-yank_spec.exp create mode 100755 test/specs/basic-yank_spec.sh delete mode 100755 test/specs/fish-support_spec.exp create mode 100755 test/specs/fish-support_spec.sh delete mode 100755 test/specs/matches-custom-patterns_spec.exp create mode 100755 test/specs/matches-custom-patterns_spec.sh delete mode 100755 test/specs/more-than-one-match-per-line_spec.exp create mode 100755 test/specs/more-than-one-match-per-line_spec.sh delete mode 100755 test/specs/preserve-zoom-state_spec.exp create mode 100755 test/specs/preserve-zoom-state_spec.sh delete mode 100755 test/specs/tmux-yank-integration_spec.exp create mode 100755 test/specs/tmux-yank-integration_spec.sh delete mode 100755 test/specs/works-with-custom-bindings_spec.exp create mode 100755 test/specs/works-with-custom-bindings_spec.sh create mode 100644 test/tmuxomatic.rFvj4QV create mode 100644 test/tmuxomatic.sh create mode 100644 tmuxomatic-test.sh diff --git a/test/conf/fish.conf b/test/conf/fish.conf index 2121c4e..5a92f92 100644 --- a/test/conf/fish.conf +++ b/test/conf/fish.conf @@ -1,4 +1,3 @@ set -g prefix C-a set -g @fingers-compact-hints '0' -set-option -g default-shell "/usr/bin/fish" run /home/vagrant/shared/tmux-fingers.tmux diff --git a/test/conf/tmuxomatic.conf b/test/conf/tmuxomatic.conf new file mode 100644 index 0000000..ea26666 --- /dev/null +++ b/test/conf/tmuxomatic.conf @@ -0,0 +1,4 @@ +set -g prefix F12 +set -g status off +set-window-option -g force-width 80 +set-window-option -g force-height 24 diff --git a/test/helpers.sh b/test/helpers.sh new file mode 100644 index 0000000..5650ca1 --- /dev/null +++ b/test/helpers.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# this assumes tmuxomatic has been already sourced +TMUX_PREFIX=C-a + +function test_clean_up() { + tmuxomatic__exec "tmux kill-session -t test" +} + +function tmux_send() { + local key=$1 + sleep 0.5 + tmuxomatic send-keys "$TMUX_PREFIX" + sleep 0.5 + tmuxomatic send-keys "$key" + sleep 0.5 +} + +function tmux_paste() { + tmux_send "]" +} + +function init_pane() { + tmux_send "c" + tmuxomatic__exec "export PS1='# '; clear" +} + +function init_pane_fish() { + tmux_send "c" + tmuxomatic__exec "function fish_prompt; echo '# '; end" + tmuxomatic__exec "clear" +} + +function invoke_fingers() { + tmux_send "F" + sleep 1.0 +} + +function echo_yanked() { + sleep 0.5 + tmuxomatic__exec "clear" + tmuxomatic send-keys "echo yanked text is " + tmux_paste + tmuxomatic send-keys Enter +} + +function begin_with_conf() { + tmuxomatic__exec "tmux -f ./test/conf/$1.conf new -s test" +} + +function begin_hook() { + tmuxomatic set-window-option force-width 80 + tmuxomatic set-window-option force-height 24 + tmuxomatic__exec "tmux kill-session -t test" +} + +function end_hook() { + tmuxomatic__exec "tmux kill-session -t test" +} diff --git a/test/provisioning/bsd.sh b/test/provisioning/bsd.sh index e4a7a48..6ae2d9d 100644 --- a/test/provisioning/bsd.sh +++ b/test/provisioning/bsd.sh @@ -3,5 +3,6 @@ pkg install -y bash tmux expect fish gawk chsh -s bash vagrant +#TODO fuck /usr/bin/fish in ubuntu, /usr/local/bin/fish in BSD echo "fishman" | pw user add -n fishman -h 0 -s "/usr/local/bin/fish" echo "run /home/vagrant/shared/tmux-fingers.tmux" > .tmux.conf diff --git a/test/run.sh b/test/run.sh index fe21d52..908623f 100755 --- a/test/run.sh +++ b/test/run.sh @@ -12,7 +12,7 @@ if [[ "$target" == "within-vm" ]]; then stty cols 80 stty rows 24 fail_count=0 - for test_file in $(ls $CURRENT_DIR/specs/*_spec.exp); do + for test_file in $(ls $CURRENT_DIR/specs/*_spec.sh); do result="* $test_file ..." sleep 1 echo "Running $test_file" >> $SPEC_OUTPUT_LOG diff --git a/test/specs/basic-yank_spec.exp b/test/specs/basic-yank_spec.exp deleted file mode 100755 index 8ea5c7f..0000000 --- a/test/specs/basic-yank_spec.exp +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env expect - -set timeout 1; -set tmux_prefix ""; - -source "./test/helpers.exp" - -exec "tmux kill-session -t test"; -spawn tmux -f ./test/conf/basic.conf new -s test; -sleep 0.5; - -init_pane -exec "cat ./test/fixtures/grep-output"; -invoke_fingers; -send "i"; -echo_yanked; - -expect { - "yanked text is scripts/hints.sh" { exit_ok } - timeout { exit_fail } -} - -exit $exit_code; diff --git a/test/specs/basic-yank_spec.sh b/test/specs/basic-yank_spec.sh new file mode 100755 index 0000000..6d0d1ab --- /dev/null +++ b/test/specs/basic-yank_spec.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +#set -x + +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 "basic" +init_pane + +tmuxomatic__exec "cat ./test/fixtures/grep-output" +invoke_fingers +tmuxomatic send-keys "i" +echo_yanked + +tmuxomatic__expect "yanked text is scripts/hints.sh" +tmuxomatic__end end_hook diff --git a/test/specs/fish-support_spec.exp b/test/specs/fish-support_spec.exp deleted file mode 100755 index 1ee51c7..0000000 --- a/test/specs/fish-support_spec.exp +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env expect - -set timeout 1; -set tmux_prefix ""; - -source "./test/helpers.exp" - -exec "tmux kill-session -t test"; -spawn sudo -u fishman SHELL=/usr/bin/fish tmux -f /home/vagrant/shared/test/conf/fish.conf new -s test; - -init_pane_fish -exec "cat ./test/fixtures/grep-output"; -invoke_fingers; -sleep 30 -send "i"; -echo_yanked; - -expect { - "yanked text is scripts/hints.sh" { exit_ok } - timeout { exit_fail } -} - -exit $exit_code; diff --git a/test/specs/fish-support_spec.sh b/test/specs/fish-support_spec.sh new file mode 100755 index 0000000..fca3244 --- /dev/null +++ b/test/specs/fish-support_spec.sh @@ -0,0 +1,18 @@ +#!/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 + +tmuxomatic__exec "sudo su fishman" +tmuxomatic__exec "tmux -f /home/vagrant/shared/test/conf/basic.conf new -s test" +init_pane_fish +tmuxomatic__exec "cat ./test/fixtures/grep-output" +invoke_fingers +tmuxomatic send-keys "i" +echo_yanked + +tmuxomatic__expect "yanked text is scripts/hints.sh" +tmuxomatic__end end_hook diff --git a/test/specs/matches-custom-patterns_spec.exp b/test/specs/matches-custom-patterns_spec.exp deleted file mode 100755 index 3c03d7e..0000000 --- a/test/specs/matches-custom-patterns_spec.exp +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env expect - -set timeout 1; -set tmux_prefix ""; - -source "./test/helpers.exp" - -exec "tmux kill-session -t test"; -spawn tmux -f ./test/conf/custom-patterns.conf new -s test; -sleep 0.5; - -init_pane -exec "cat ./test/fixtures/custom-patterns"; - -send "echo yanked text is " -invoke_fingers; -send "i"; -tmux_paste; - -invoke_fingers; -send "o"; -tmux_paste; - -send "\r"; -sleep 0.5; - -expect { - "yanked text is W00TW00TW00TYOLOYOLOYOLO" { exit_ok } - timeout { exit_fail } -} - -exit $exit_code; diff --git a/test/specs/matches-custom-patterns_spec.sh b/test/specs/matches-custom-patterns_spec.sh new file mode 100755 index 0000000..01b4ada --- /dev/null +++ b/test/specs/matches-custom-patterns_spec.sh @@ -0,0 +1,26 @@ +#!/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 "custom-patterns" +init_pane +tmuxomatic__exec "cat ./test/fixtures/custom-patterns" + +tmuxomatic send-keys "echo yanked text is " + +invoke_fingers +tmuxomatic send-keys "i" +tmux_paste + +invoke_fingers +tmuxomatic send-keys "o" +tmux_paste + +tmuxomatic send-keys Enter + +tmuxomatic__expect "yanked text is W00TW00TW00TYOLOYOLOYOLO" +tmuxomatic__end end_hook diff --git a/test/specs/more-than-one-match-per-line_spec.exp b/test/specs/more-than-one-match-per-line_spec.exp deleted file mode 100755 index 29ff30b..0000000 --- a/test/specs/more-than-one-match-per-line_spec.exp +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env expect - -set timeout 1; -set tmux_prefix ""; - -source "./test/helpers.exp" - -exec "tmux kill-session -t test"; -spawn tmux -f ./test/conf/basic.conf new -s test; -sleep 0.5; - -init_pane -exec "cat ./test/fixtures/ip-output"; -invoke_fingers; -send "t"; -echo_yanked; - -expect { - "yanked text is 10.0.3.1" { exit_ok } - timeout { exit_fail } -} - -exit $exit_code; diff --git a/test/specs/more-than-one-match-per-line_spec.sh b/test/specs/more-than-one-match-per-line_spec.sh new file mode 100755 index 0000000..92cdd13 --- /dev/null +++ b/test/specs/more-than-one-match-per-line_spec.sh @@ -0,0 +1,20 @@ +#!/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 "basic" +init_pane + +tmuxomatic__exec "cat ./test/fixtures/ip-output" +sleep 1.0 +invoke_fingers + +tmuxomatic send-keys "t" +echo_yanked + +tmuxomatic__expect "yanked text is 10.0.3.1" +tmuxomatic__end end_hook diff --git a/test/specs/preserve-zoom-state_spec.exp b/test/specs/preserve-zoom-state_spec.exp deleted file mode 100755 index 7274086..0000000 --- a/test/specs/preserve-zoom-state_spec.exp +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env expect - -set timeout 1; -set tmux_prefix ""; - -source "./test/helpers.exp" - -exec "tmux kill-session -t test"; -exec "rm -rf /tmp/tmux-yank-result" - -spawn tmux -f ./test/conf/basic.conf new -s test; -sleep 0.5; - -init_pane -tmux_send "%" -tmux_send "%" -tmux_send "%" -tmux_send "z" - -exec "cat ./test/fixtures/grep-output"; -invoke_fingers; - -send "" - -exec "echo \"current pane is \$(tmux list-panes -F '#{?window_zoomed_flag,zoomed,not_zoomed}' | head -1)\"" - -expect { - "current pane is zoomed" { exit_ok } - timeout { exit_fail } -} - -exit $exit_code; diff --git a/test/specs/preserve-zoom-state_spec.sh b/test/specs/preserve-zoom-state_spec.sh new file mode 100755 index 0000000..2afaec0 --- /dev/null +++ b/test/specs/preserve-zoom-state_spec.sh @@ -0,0 +1,23 @@ +#!/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 "basic" +init_pane + +tmux_send "%" +tmux_send "%" +tmux_send "%" +tmux_send "z" +tmuxomatic__exec "cat ./test/fixtures/grep-output" + +invoke_fingers +tmuxomatic send-keys C-c + +tmuxomatic__exec "echo \"current pane is \$(tmux list-panes -F '#{?window_zoomed_flag,zoomed,not_zoomed}' | head -1)\"" +tmuxomatic__expect "current pane is zoomed" +tmuxomatic__end end_hook diff --git a/test/specs/tmux-yank-integration_spec.exp b/test/specs/tmux-yank-integration_spec.exp deleted file mode 100755 index 9a47c49..0000000 --- a/test/specs/tmux-yank-integration_spec.exp +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env expect - -set timeout 1; -set tmux_prefix ""; - -source "./test/helpers.exp" - -exec "tmux kill-session -t test"; -exec "rm -rf /tmp/tmux-yank-result" - -spawn tmux -f ./test/conf/tmux-yank.conf new -s test; -sleep 0.5; - -init_pane -exec "cat ./test/fixtures/grep-output"; -invoke_fingers; -send "i"; - -sleep 0.5; -exec "cat /tmp/tmux-yank-result"; - -expect { - "tmux-yank yolo" { exit_ok } - timeout { exit_fail } -} - -exit $exit_code; diff --git a/test/specs/tmux-yank-integration_spec.sh b/test/specs/tmux-yank-integration_spec.sh new file mode 100755 index 0000000..2113f3f --- /dev/null +++ b/test/specs/tmux-yank-integration_spec.sh @@ -0,0 +1,20 @@ +#!/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 "i" + +sleep 10 +tmuxomatic__exec "cat /tmp/tmux-yank-result" + +tmuxomatic__expect "tmux-yank yolo" +tmuxomatic__end end_hook diff --git a/test/specs/works-with-custom-bindings_spec.exp b/test/specs/works-with-custom-bindings_spec.exp deleted file mode 100755 index b5cc57bd720a0363c09fb6ad13add2c88c094e64..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 386 zcmXw#&2ob<41{~;DO9&taC_(}55rI+f(DR1mYmSZ>S=*FxpcUMkyO=4K91vXN6-E7sbHXf*F /dev/null + + if [[ $? -eq 1 ]]; then + tmuxomatic -f "$TMUXOMATIC_CURRENT_DIR/conf/tmuxomatic.conf" new-session -d -s tmuxomatic + wait + tmuxomatic__exec "export TMUX=''" + tmuxomatic__exec "clear" + fi + + call_hook "$1" +} + +function tmuxomatic__end() { + call_hook "$1" + tmuxomatic kill-server + exit $TMUXOMATIC_EXIT_CODE +} + +function call_hook() { + local fn_hook="$1" + + if [[ $(__fn_exists "$fn_hook") = "1" ]]; then + $fn_hook + fi +} + +function tmuxomatic__expect() { + local pattern=$1 + local n_matches + local expect_output + + TMUXOMATIC_FIRST_TS=$(__now) + + while [[ $(($(__now) - TMUXOMATIC_FIRST_TS)) -lt $TMUXOMATIC_TIMEOUT ]]; do + echo "Trying to match '$pattern' ..." + n_matches=$(tmuxomatic capture-pane -p | grep -E "$pattern" | wc -l) + + if [[ $n_matches -gt 0 ]]; then + # TODO echo when specified loglevel + echo "Matched '$pattern'! :)" + TMUXOMATIC_EXIT_CODE=0 + break + fi + sleep 0.5 + done + + if [[ $n_matches -le 0 ]]; then + # TODO echo when specified loglevel + # TODO dump pane and buffers + log_output_path=$(mktemp "$PWD/tmuxomatic.XXXXXXX") + mv "$log_output_path" "$log_output_path.log" + log_output_path="${log_output_path}.log" + + + tmuxomatic capture-pane -p > "$log_output_path" + echo "Timeout :( See log at $log_output_path" + TMUXOMATIC_EXIT_CODE=1 + fi +} + +# TODO not working in BSD, therefore end hook not being called and :skull: +function __fn_exists() { + local fn_type=$(type "$1" 2> /dev/null) + + echo "$fn_type" | head -n 1 | grep -c "^$1 is a function$" +} + +function __now() { + echo $(date +%s) +} diff --git a/tmuxomatic-test.sh b/tmuxomatic-test.sh new file mode 100644 index 0000000..e40a6e0 --- /dev/null +++ b/tmuxomatic-test.sh @@ -0,0 +1,4 @@ +source test/tmuxomatic.sh +source test/helpers.sh + +tmuxomatic__begin begin_hook From 21c6c06d65443389156ede7594861207c469857b Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Wed, 19 Apr 2017 22:52:55 +0200 Subject: [PATCH 15/20] make tmux-yank integration work with new set-buffer approach --- scripts/fingers.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/fingers.sh b/scripts/fingers.sh index bdddb4c..2a0fd40 100755 --- a/scripts/fingers.sh +++ b/scripts/fingers.sh @@ -8,6 +8,7 @@ source $CURRENT_DIR/utils.sh source $CURRENT_DIR/help.sh FINGERS_COPY_COMMAND=$(tmux show-option -gqv @fingers-copy-command) +HAS_TMUX_YANK=$([ "$(tmux list-keys | grep -c tmux-yank)" == "0" ]; echo $?) current_pane_id=$1 fingers_pane_id=$2 @@ -98,6 +99,12 @@ function copy_result() { if [ ! -z "$FINGERS_COPY_COMMAND" ]; then echo -n "$result" | eval "nohup $FINGERS_COPY_COMMAND" > /dev/null fi + + if [[ $HAS_TMUX_YANK = 1 ]]; then + tmux_yank_copy_command=$(tmux list-keys -t vi-copy | grep "vi-copy *y" | sed 's/.*copy-pipe "\(.*\)".*/\1/g') + + echo -n "$result" | eval "nohup $tmux_yank_copy_command" > /dev/null + fi } while read -rsn1 char; do From d9ffb4a1f937fce4e259a7d246fe404f6245ba88 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Thu, 20 Apr 2017 08:17:50 +0200 Subject: [PATCH 16/20] remove expect from provisioning --- test/provisioning/bsd.sh | 3 +-- test/provisioning/ubuntu.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/provisioning/bsd.sh b/test/provisioning/bsd.sh index 6ae2d9d..cfaac2e 100644 --- a/test/provisioning/bsd.sh +++ b/test/provisioning/bsd.sh @@ -1,8 +1,7 @@ #!/bin/sh -pkg install -y bash tmux expect fish gawk +pkg install -y bash tmux fish gawk chsh -s bash vagrant -#TODO fuck /usr/bin/fish in ubuntu, /usr/local/bin/fish in BSD echo "fishman" | pw user add -n fishman -h 0 -s "/usr/local/bin/fish" echo "run /home/vagrant/shared/tmux-fingers.tmux" > .tmux.conf diff --git a/test/provisioning/ubuntu.sh b/test/provisioning/ubuntu.sh index 2d20a80..0c9fc53 100644 --- a/test/provisioning/ubuntu.sh +++ b/test/provisioning/ubuntu.sh @@ -1,7 +1,7 @@ #!/bin/sh sudo aptitude update -sudo aptitude install -y expect fish gawk +sudo aptitude install -y fish gawk useradd -m -p "$(perl -e "print crypt('fishman','sa');")" -s "/usr/bin/fish" fishman From 3d2354f887d41121ffb1d7687e0854c8d6f55722 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Thu, 20 Apr 2017 08:19:43 +0200 Subject: [PATCH 17/20] updated CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f51bb..2f6b94e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.5.0 - 20 Apr 2017 + +* Added support for tmux of the future ( greater than 2.3 ). Thanks @fcsonline! +* Tests rewritten in bash. Bye bye `expect` tool! + ## 0.4.1 - 09 Apr 2017 * Looks like `gawk` should be 4+ for things to go smooth. From f4d5b3d7eb0dafcb246892105c703485082fa122 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 21 Apr 2017 08:49:11 +0200 Subject: [PATCH 18/20] remove unused helpers file --- test/helpers.exp | 67 ------------------------------------------------ 1 file changed, 67 deletions(-) delete mode 100644 test/helpers.exp diff --git a/test/helpers.exp b/test/helpers.exp deleted file mode 100644 index 6d8e0b6..0000000 --- a/test/helpers.exp +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env expect - -set exit_code 2 - -proc test_clean_up {} { - exec "tmux kill-session -t test"; - sleep 0.5; -} - -proc exec {cmd} { - sleep 0.5; - send "$cmd"; - sleep 0.5; - send "\r"; - sleep 0.5; -} - -proc tmux_send {key} { - global tmux_prefix; - sleep 0.5; - send $tmux_prefix; - sleep 0.5; - send "$key"; - sleep 0.5; -} - -proc init_pane {} { - tmux_send "c"; - exec "export PS1='# '; clear"; -} - -proc init_pane_fish {} { - tmux_send "c"; - exec "function fish_prompt; echo '# '; end" - exec "clear" -} - -proc invoke_fingers {} { - tmux_send "F"; - sleep 1.0; -} - -proc echo_yanked {} { - exec "clear"; - send "echo yanked text is "; - tmux_send "]"; - send "\r"; - sleep 0.5; -} - -proc tmux_paste {} { - tmux_send "]"; - sleep 0.5; -} - -proc exit_ok {} { - global exit_code - set exit_code 0; - test_clean_up; -} - -proc exit_fail {} { - global exit_code - set exit_code 1; - exec "tmux list-buffers >> ./spec-output.log" - test_clean_up; -} From a56aaaf5e614fa8db9302cbd9393a426d8b3fc6f Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 21 Apr 2017 09:01:12 +0200 Subject: [PATCH 19/20] testing sleepy tests in CI --- test/helpers.sh | 10 +++++----- test/specs/preserve-zoom-state_spec.sh | 1 + test/specs/tmux-yank-integration_spec.sh | 2 +- test/tmuxomatic.sh | 10 +++++++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/test/helpers.sh b/test/helpers.sh index 5650ca1..1303a20 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -9,11 +9,11 @@ function test_clean_up() { function tmux_send() { local key=$1 - sleep 0.5 + tmuxomatic__sleep 1 tmuxomatic send-keys "$TMUX_PREFIX" - sleep 0.5 + tmuxomatic__sleep 1 tmuxomatic send-keys "$key" - sleep 0.5 + tmuxomatic__sleep 1 } function tmux_paste() { @@ -33,11 +33,11 @@ function init_pane_fish() { function invoke_fingers() { tmux_send "F" - sleep 1.0 + tmuxomatic__sleep 1 } function echo_yanked() { - sleep 0.5 + tmuxomatic__sleep 1 tmuxomatic__exec "clear" tmuxomatic send-keys "echo yanked text is " tmux_paste diff --git a/test/specs/preserve-zoom-state_spec.sh b/test/specs/preserve-zoom-state_spec.sh index 2afaec0..611c6c5 100755 --- a/test/specs/preserve-zoom-state_spec.sh +++ b/test/specs/preserve-zoom-state_spec.sh @@ -17,6 +17,7 @@ tmuxomatic__exec "cat ./test/fixtures/grep-output" invoke_fingers tmuxomatic send-keys C-c +tmuxomatic__sleep 1 tmuxomatic__exec "echo \"current pane is \$(tmux list-panes -F '#{?window_zoomed_flag,zoomed,not_zoomed}' | head -1)\"" tmuxomatic__expect "current pane is zoomed" diff --git a/test/specs/tmux-yank-integration_spec.sh b/test/specs/tmux-yank-integration_spec.sh index 2113f3f..f6e09c1 100755 --- a/test/specs/tmux-yank-integration_spec.sh +++ b/test/specs/tmux-yank-integration_spec.sh @@ -13,7 +13,7 @@ tmuxomatic__exec "cat ./test/fixtures/grep-output" invoke_fingers tmuxomatic send-keys "i" -sleep 10 +tmuxomatic__sleep 1 tmuxomatic__exec "cat /tmp/tmux-yank-result" tmuxomatic__expect "tmux-yank yolo" diff --git a/test/tmuxomatic.sh b/test/tmuxomatic.sh index df2a6b3..adbb8dd 100644 --- a/test/tmuxomatic.sh +++ b/test/tmuxomatic.sh @@ -58,7 +58,7 @@ function tmuxomatic__expect() { TMUXOMATIC_EXIT_CODE=0 break fi - sleep 0.5 + tmuxomatic__sleep 1 done if [[ $n_matches -le 0 ]]; then @@ -75,6 +75,14 @@ function tmuxomatic__expect() { fi } +function tmuxomatic__sleep() { + if [[ -z $CI ]]; then + sleep "$1" + else + sleep "$(($1 * 5))" + fi +} + # TODO not working in BSD, therefore end hook not being called and :skull: function __fn_exists() { local fn_type=$(type "$1" 2> /dev/null) From 9a41e55f2aa57338dcfce2bb53b1b48c5f208e71 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Fri, 21 Apr 2017 09:13:16 +0200 Subject: [PATCH 20/20] add hack disclaimer --- test/tmuxomatic.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/tmuxomatic.sh b/test/tmuxomatic.sh index adbb8dd..3bcc910 100644 --- a/test/tmuxomatic.sh +++ b/test/tmuxomatic.sh @@ -75,6 +75,11 @@ function tmuxomatic__expect() { fi } +# TODO ideally specs shouldn't have any sleeps, but life is hard! Since +# circle-ci machine is kind of slow, sleeps need to be longer there. +# +# Ideally tmuxomatic__exec should now when a command has finished by using +# "tmux wait", or alert-silence hook, or some tmux sorcery like that. function tmuxomatic__sleep() { if [[ -z $CI ]]; then sleep "$1"