delete the old stuff
This commit is contained in:
parent
b5ab752b98
commit
ab6aca59b7
|
@ -3,7 +3,7 @@ rvm:
|
|||
- 2.6
|
||||
- 2.7
|
||||
- 3.0
|
||||
install: ./test/provisioning/ci.sh
|
||||
install: ./spec/provisioning/ci.sh
|
||||
script:
|
||||
- bash -c 'echo $BASH_VERSION'
|
||||
- bundle exec rspec
|
||||
|
|
|
@ -11,6 +11,6 @@ Vagrant.configure(2) do |config|
|
|||
config.vm.define 'ubuntu' do |machine|
|
||||
machine.vm.box = 'ubuntu/focal64'
|
||||
machine.vm.synced_folder '.', '/home/vagrant/shared'
|
||||
machine.vm.provision 'shell', path: './test/provisioning/ubuntu.sh'
|
||||
machine.vm.provision 'shell', path: './spec/provisioning/ubuntu.sh'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,168 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CONF_CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CONF_CURRENT_DIR/utils.sh
|
||||
|
||||
TMUX_PRINTER="$CONF_CURRENT_DIR/../vendor/tmux-printer/tmux-printer"
|
||||
|
||||
declare -A fingers_defaults
|
||||
|
||||
# TODO empty patterns are invalid
|
||||
function check_pattern() {
|
||||
echo "beep beep" | grep -e "$1" 2> /dev/null
|
||||
|
||||
if [[ $? == "2" ]]; then
|
||||
echo 0
|
||||
else
|
||||
echo 1
|
||||
fi
|
||||
}
|
||||
|
||||
function envify() {
|
||||
echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g"
|
||||
}
|
||||
|
||||
function set_tmux_env() {
|
||||
local option_name="$(envify $1)"
|
||||
local default_value="${fingers_defaults[$1]}"
|
||||
local transform_fn="$2"
|
||||
|
||||
option_value=$(read_from_config "$1")
|
||||
|
||||
local final_value="${option_value:-$default_value}"
|
||||
|
||||
if [[ ! -z "$transform_fn" ]]; then
|
||||
final_value="$($transform_fn "$final_value")"
|
||||
fi
|
||||
|
||||
tmux setenv -g "$option_name" "$final_value"
|
||||
}
|
||||
|
||||
function read_from_config() {
|
||||
tmux show-option -gqv "@$1"
|
||||
}
|
||||
|
||||
function process_format () {
|
||||
echo -ne "$($TMUX_PRINTER "$1")"
|
||||
}
|
||||
|
||||
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 "cygstart") = "1" ]]; then
|
||||
echo "xargs cygstart"
|
||||
elif [[ $(program_exists "xdg-open") = "1" ]]; then
|
||||
echo "xargs xdg-open"
|
||||
elif [[ $(program_exists "open") = "1" ]]; then
|
||||
echo "xargs open"
|
||||
fi
|
||||
}
|
||||
|
||||
PATTERNS_LIST=(
|
||||
"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
|
||||
"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
||||
"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
|
||||
"[0-9a-f]{7,128}"
|
||||
"[0-9]{4,}"
|
||||
"((https?://|git@|git://|ssh://|ftp://|file:///)[^ ]+)"
|
||||
"(([.\w\-~\$@]+)?(/[.\w\-@]+)+/?)"
|
||||
)
|
||||
|
||||
if [[ $(tmux show-options -g | grep -q @fingers-pattern && echo $?) ]]; then
|
||||
IFS=$'\n'
|
||||
USER_DEFINED_PATTERNS=($(tmux show-options -gv | sed -n -e "$(echo "$(tmux show-options -g | grep -n '@fingers-pattern' | cut -f1 -d: | xargs | sed 's/ /p;/g')p")"))
|
||||
unset IFS
|
||||
|
||||
PATTERNS_LIST=("${PATTERNS_LIST[@]}" "${USER_DEFINED_PATTERNS[@]}")
|
||||
fi
|
||||
|
||||
PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}")
|
||||
|
||||
fingers_defaults=( \
|
||||
[fingers-patterns]="$PATTERNS" \
|
||||
[fingers-compact-hints]=1 \
|
||||
|
||||
[fingers-main-action]=":copy:" \
|
||||
[fingers-ctrl-action]=":open:" \
|
||||
[fingers-shift-action]=":paste:" \
|
||||
[fingers-alt-action]="" \
|
||||
|
||||
[fingers-hint-position]="left" \
|
||||
[fingers-hint-format]="#[fg=yellow,bold]%s" \
|
||||
[fingers-selected-hint-format]="#[fg=green,bold]%s" \
|
||||
[fingers-selected-highlight-format]="#[fg=green,nobold,dim]%s" \
|
||||
[fingers-highlight-format]="#[fg=yellow,nobold,dim]%s" \
|
||||
|
||||
[fingers-hint-position-nocompact]="right" \
|
||||
[fingers-hint-format-nocompact]="#[fg=yellow,bold][%s]" \
|
||||
[fingers-selected-hint-format-nocompact]="#[fg=green,bold][%s]" \
|
||||
[fingers-selected-highlight-format-nocompact]="#[fg=green,nobold,dim][%s]" \
|
||||
[fingers-highlight-format-nocompact]="#[fg=yellow,nobold,dim]%s" \
|
||||
|
||||
[fingers-keyboard-layout]="qwerty" \
|
||||
|
||||
[fingers-system-copy-command]="$(default_copy_command)" \
|
||||
[fingers-system-open-command]="$(default_open_command)" \
|
||||
|
||||
# TODO deprecated options
|
||||
[fingers-copy-command]="DEPRECATED" \
|
||||
[fingers-copy-command-uppercase]="DEPRECATED" \
|
||||
)
|
||||
|
||||
set_tmux_env 'fingers-patterns'
|
||||
set_tmux_env 'fingers-compact-hints'
|
||||
set_tmux_env 'fingers-copy-command' # DEPRECATED
|
||||
set_tmux_env 'fingers-copy-command-uppercase' # DEPRECATED
|
||||
|
||||
set_tmux_env 'fingers-main-action'
|
||||
set_tmux_env 'fingers-ctrl-action'
|
||||
set_tmux_env 'fingers-shift-action'
|
||||
set_tmux_env 'fingers-alt-action'
|
||||
|
||||
set_tmux_env 'fingers-system-copy-command'
|
||||
set_tmux_env 'fingers-system-open-command'
|
||||
|
||||
set_tmux_env 'fingers-hint-position'
|
||||
set_tmux_env 'fingers-hint-format' process_format
|
||||
set_tmux_env 'fingers-highlight-format' process_format
|
||||
|
||||
set_tmux_env 'fingers-hint-position-nocompact'
|
||||
set_tmux_env 'fingers-hint-format-nocompact' process_format
|
||||
set_tmux_env 'fingers-highlight-format-nocompact' process_format
|
||||
|
||||
set_tmux_env 'fingers-selected-hint-format' process_format
|
||||
set_tmux_env 'fingers-selected-highlight-format' process_format
|
||||
set_tmux_env 'fingers-selected-hint-format-nocompact' process_format
|
||||
set_tmux_env 'fingers-selected-highlight-format-nocompact' process_format
|
||||
|
||||
set_tmux_env 'fingers-keyboard-layout'
|
||||
|
||||
for option in fingers-{selected-hint,selected-highlight,hint,highlight}-format{,-nocompact}; do
|
||||
env_name="$(envify "$option")_NOCOLOR"
|
||||
option_value="$(read_from_config "$option")"
|
||||
default_value="${fingers_defaults[$option]}"
|
||||
tmux setenv -g "$env_name" "$(strip_format "${option_value:-$default_value}")"
|
||||
done
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Source this file and call `tail -f fingers.log` when you don't know WTF is
|
||||
# going on.
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
function current_ms() {
|
||||
echo $(($(date +%s%N)/1000000))
|
||||
}
|
||||
|
||||
function log() {
|
||||
echo "$1" >> "$CURRENT_DIR/../fingers.log"
|
||||
}
|
||||
|
||||
function log_array() {
|
||||
declare -a arg_arr=(${!1})
|
||||
|
||||
for i in "${arg_arr[@]}"
|
||||
do
|
||||
log "> $i"
|
||||
done
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source $CURRENT_DIR/utils.sh
|
||||
|
||||
function handle_exit() {
|
||||
echo "exit" >> /tmp/fingers-command-queue
|
||||
cat /dev/null > /tmp/fingers-command-queue
|
||||
}
|
||||
|
||||
trap "handle_exit" EXIT
|
||||
|
||||
function is_valid_input() {
|
||||
local input=$1
|
||||
local is_valid=1
|
||||
|
||||
if [[ $input == "" ]] || [[ $input == "<ESC>" ]] || [[ $input == "?" ]]; then
|
||||
is_valid=1
|
||||
else
|
||||
for (( i=0; i<${#input}; i++ )); do
|
||||
char=${input:$i:1}
|
||||
|
||||
if [[ ! $(is_alpha $char) == "1" ]]; then
|
||||
is_valid=0
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo $is_valid
|
||||
}
|
||||
|
||||
while read -rsn1 char; do
|
||||
# Escape sequence, flush input
|
||||
if [[ "$char" == $'\x1b' ]]; then
|
||||
read -rsn1 -t 0.1 next_char
|
||||
|
||||
if [[ "$next_char" == "[" ]]; then
|
||||
read -rsn1 -t 0.1
|
||||
continue
|
||||
elif [[ "$next_char" == "" ]]; then
|
||||
char="<ESC>"
|
||||
else
|
||||
continue
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [[ ! $(is_valid_input "$char") == "1" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
is_uppercase=$(echo "$char" | grep -E '^[a-z]+$' &> /dev/null; echo $?)
|
||||
|
||||
if [[ $char == "$BACKSPACE" ]]; then
|
||||
continue
|
||||
elif [[ $char == "<ESC>" ]]; then
|
||||
echo "exit" >> /tmp/fingers-command-queue
|
||||
elif [[ $char == "q" ]]; then
|
||||
echo "exit" >> /tmp/fingers-command-queue
|
||||
elif [[ $char == "?" ]]; then
|
||||
echo "toggle-help" >> /tmp/fingers-command-queue
|
||||
elif [[ $is_uppercase == "1" ]]; then
|
||||
echo "hint:$char:shift" >> /tmp/fingers-command-queue
|
||||
else
|
||||
echo "hint:$char:main" >> /tmp/fingers-command-queue
|
||||
fi
|
||||
done < /dev/tty
|
|
@ -1,272 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
eval "$(tmux show-env -g -s | grep ^FINGERS)"
|
||||
|
||||
tmux set-window-option automatic-rename off
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source $CURRENT_DIR/hints.sh
|
||||
source $CURRENT_DIR/utils.sh
|
||||
source $CURRENT_DIR/help.sh
|
||||
|
||||
current_pane_id=$1
|
||||
fingers_pane_id=$2
|
||||
last_pane_id=$3
|
||||
fingers_window_id=$4
|
||||
pane_input_temp=$5
|
||||
original_window_name=$6
|
||||
input_method=$7
|
||||
|
||||
function rename_fingers_window() {
|
||||
tmux rename-window -t "$fingers_window_id" "$1"
|
||||
}
|
||||
|
||||
function is_pane_zoomed() {
|
||||
local pane_id=$1
|
||||
|
||||
tmux list-panes \
|
||||
-F "#{pane_id}:#{?pane_active,active,nope}:#{?window_zoomed_flag,zoomed,nope}" \
|
||||
| grep -c "^${pane_id}:active:zoomed$"
|
||||
}
|
||||
|
||||
function zoom_pane() {
|
||||
local pane_id=$1
|
||||
|
||||
tmux resize-pane -Z -t "$pane_id"
|
||||
}
|
||||
|
||||
function enable_fingers_mode () {
|
||||
tmux set-window-option key-table fingers
|
||||
tmux switch-client -T fingers
|
||||
state[tmux_prefix]="$(tmux show -gqv prefix)"
|
||||
tmux set-option -g prefix None
|
||||
}
|
||||
|
||||
function hide_cursor() {
|
||||
echo -n "$(tput civis)"
|
||||
}
|
||||
|
||||
function copy_final_result() {
|
||||
local result="${state[final_result]}"
|
||||
|
||||
tmux set-buffer "$result"
|
||||
}
|
||||
|
||||
function revert_to_original_pane() {
|
||||
tmux swap-pane -s "$current_pane_id" -t "$fingers_pane_id"
|
||||
tmux rename-window "$original_window_name"
|
||||
|
||||
if [[ ! -z "$last_pane_id" ]]; then
|
||||
tmux select-pane -t "$last_pane_id"
|
||||
tmux select-pane -t "$current_pane_id"
|
||||
fi
|
||||
|
||||
# FIXME tiny flicker?
|
||||
[[ "${state[pane_was_zoomed]}" == "1" ]] && zoom_pane "$current_pane_id"
|
||||
}
|
||||
|
||||
compact_state=$FINGERS_COMPACT_HINTS
|
||||
|
||||
declare -A state=()
|
||||
declare -A prev_state=()
|
||||
|
||||
function toggle_state() {
|
||||
local key="$1"
|
||||
local value="${state[$key]}"
|
||||
|
||||
((value ^= 1))
|
||||
|
||||
state[$key]="$value"
|
||||
}
|
||||
|
||||
function track_state() {
|
||||
for key in "${!state[@]}"; do
|
||||
prev_state[$key]="${state[$key]}"
|
||||
done
|
||||
}
|
||||
|
||||
function did_state_change() {
|
||||
local key="$1"
|
||||
local transition="$2"
|
||||
local did_change='0'
|
||||
|
||||
if [[ "${prev_state[$key]}" != "${state[$key]}" ]]; then
|
||||
did_change='1'
|
||||
fi
|
||||
|
||||
if [[ -z "$transition" ]]; then
|
||||
echo "$did_change"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "${prev_state[$key]} => ${state[$key]}" == "$transition" ]]; then
|
||||
echo '1'
|
||||
else
|
||||
echo '0'
|
||||
fi
|
||||
}
|
||||
|
||||
function accept_hint() {
|
||||
local statement="$1"
|
||||
IFS=: read -r _command hint modifier <<<$(echo "$statement")
|
||||
|
||||
state[input]="${state[input]}$hint"
|
||||
state[modifier]="$modifier"
|
||||
}
|
||||
|
||||
function run_shell_action() {
|
||||
local command_to_run="$1"
|
||||
|
||||
if [[ ! -z $command_to_run ]]; then
|
||||
tmux run-shell -b "printf \"$(escape_quotes "${state[final_result]}")\" | MODIFIER=${state[modifier]} HINT=${state[input]} $EXEC_PREFIX $command_to_run"
|
||||
fi
|
||||
}
|
||||
|
||||
function run_action() {
|
||||
action_variable="FINGERS_$(echo "${state[modifier]}_ACTION" | tr '[:lower:]' '[:upper:]')"
|
||||
action="$(eval "echo \$$action_variable")"
|
||||
|
||||
if [[ -z "$action" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$action" == ":open:" ]]; then
|
||||
run_shell_action "$FINGERS_SYSTEM_OPEN_COMMAND"
|
||||
elif [[ "$action" == ":copy:" ]]; then
|
||||
run_shell_action "$FINGERS_SYSTEM_COPY_COMMAND"
|
||||
elif [[ "$action" == ":paste:" ]]; then
|
||||
tmux paste-buffer
|
||||
else
|
||||
run_shell_action "$action"
|
||||
fi
|
||||
}
|
||||
|
||||
function handle_exit() {
|
||||
revert_to_original_pane
|
||||
|
||||
run_action
|
||||
|
||||
cat /dev/null > /tmp/fingers-command-queue
|
||||
|
||||
# exported from scripts/hints.sh
|
||||
rm -rf "$pane_input_temp" "$match_lookup_table" "$pane_output_temp" /tmp/fingers-command-queue
|
||||
|
||||
tmux set-option -g prefix "${state[tmux_prefix]}"
|
||||
|
||||
tmux set-window-option key-table root
|
||||
tmux switch-client -Troot
|
||||
|
||||
tmux kill-window -t "$fingers_window_id"
|
||||
}
|
||||
|
||||
function read_statement() {
|
||||
statement=''
|
||||
|
||||
while read -rsn1 char; do
|
||||
if [[ "$char" == "" ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
statement="$statement$char"
|
||||
done < /dev/tty
|
||||
|
||||
export statement
|
||||
}
|
||||
|
||||
trap "handle_exit" EXIT
|
||||
|
||||
state[pane_was_zoomed]=$(is_pane_zoomed "$current_pane_id")
|
||||
state[show_help]=0
|
||||
state[compact_mode]="$FINGERS_COMPACT_HINTS"
|
||||
state[multi_mode]=0
|
||||
state[input]=''
|
||||
state[modifier]=''
|
||||
selected_matches=()
|
||||
selected_hints=()
|
||||
|
||||
hide_cursor
|
||||
show_hints_and_swap "$current_pane_id" "$fingers_pane_id" "$compact_state"
|
||||
[[ "${state[pane_was_zoomed]}" == "1" ]] && zoom_pane "$fingers_pane_id"
|
||||
|
||||
touch /tmp/fingers-command-queue
|
||||
chmod a+w /tmp/fingers-command-queue
|
||||
|
||||
echo "exit" >> /tmp/fingers-command-queue
|
||||
cat /dev/null > /tmp/fingers-command-queue
|
||||
|
||||
if [[ $input_method == "fingers-mode" ]]; then
|
||||
enable_fingers_mode
|
||||
else
|
||||
($CURRENT_DIR/fingers-legacy-input.sh) &
|
||||
fi
|
||||
|
||||
# %BENCHMARK_END%
|
||||
|
||||
while read -r -s statement
|
||||
do
|
||||
track_state
|
||||
|
||||
case $statement in
|
||||
toggle-help)
|
||||
toggle_state "show_help"
|
||||
;;
|
||||
toggle-compact-mode)
|
||||
toggle_state "compact_mode"
|
||||
;;
|
||||
toggle-multi-mode)
|
||||
toggle_state "multi_mode"
|
||||
;;
|
||||
hint:*)
|
||||
accept_hint "$statement"
|
||||
;;
|
||||
noop)
|
||||
continue
|
||||
;;
|
||||
exit)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $(did_state_change "show_help" "0 => 1") == 1 ]]; then
|
||||
show_help "$fingers_pane_id"
|
||||
fi
|
||||
|
||||
if [[ $(did_state_change "show_help" "1 => 0") == 1 ]]; then
|
||||
show_hints "$fingers_pane_id" "${state[compact_mode]}" "${state[multi_mode]}" "${selected_hints[@]}"
|
||||
fi
|
||||
|
||||
if [[ $(did_state_change "compact_mode") == 1 ]]; then
|
||||
show_hints "$fingers_pane_id" "${state[compact_mode]}" "${state[multi_mode]}" "${selected_hints[@]}"
|
||||
fi
|
||||
|
||||
if [[ $(did_state_change "multi_mode" "0 => 1") == 1 ]]; then
|
||||
rename_fingers_window "[fingers:multi]"
|
||||
fi
|
||||
|
||||
# Exiting multi mode makes an early exit
|
||||
if [[ $(did_state_change "multi_mode" "1 => 0") == 1 ]]; then
|
||||
state[final_result]=$(array_join " " "${selected_matches[@]}")
|
||||
copy_final_result
|
||||
break
|
||||
fi
|
||||
|
||||
input="${state[input]}"
|
||||
|
||||
state[current_match]=$(lookup_match "$input")
|
||||
|
||||
if [[ -n "${state[current_match]}" ]]; then
|
||||
if [[ "${state[multi_mode]}" == "1" ]]; then
|
||||
selected_matches+=(${state[current_match]})
|
||||
selected_hints+=(${state[input]})
|
||||
state[input]=''
|
||||
show_hints "$fingers_pane_id" "${state[compact_mode]}" "${state[multi_mode]}" "${selected_hints[@]}"
|
||||
else
|
||||
state[final_result]="${state[current_match]}"
|
||||
copy_final_result
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done < <(tail -f /tmp/fingers-command-queue)
|
||||
|
||||
exit 0
|
|
@ -1,185 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/utils.sh
|
||||
|
||||
REQUIRED_BASH_MAJOR=4
|
||||
REQUIRED_GAWK_MAJOR=4
|
||||
RECOMMENDED_TMUX_MINOR=3
|
||||
HELP_LINK="https://github.com/Morantron/tmux-fingers/blob/master/docs/health-check.md"
|
||||
TMUX_FINGERS_ROOT="$(resolve_path "$CURRENT_DIR/..")"
|
||||
|
||||
health_tmp=$(fingers_tmp)
|
||||
tmux_term_tmp=$(fingers_tmp)
|
||||
log_messages=()
|
||||
|
||||
function is_tmux_ready() {
|
||||
local attached_sessions="$(tmux list-sessions -F "#{session_id}:#{session_attached}" | grep ':1$' | wc -l)"
|
||||
|
||||
if [[ $attached_sessions -gt 0 ]]; then
|
||||
echo 1
|
||||
else
|
||||
echo 0
|
||||
fi
|
||||
}
|
||||
|
||||
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() {
|
||||
#TODO warn about deprecated options
|
||||
|
||||
local healthy=1
|
||||
|
||||
# BASH_VERSION is a global
|
||||
local TMUX_VERSION=$(get_tmux_version)
|
||||
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
|
||||
|
||||
if [[ $(program_exists "gawk") = 0 ]]; then
|
||||
log_message " * 'gawk' not found"
|
||||
healthy=0
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
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 [[ $(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
|
||||
|
||||
tmux run-shell -b "tmux wait-for -S tmux_term_value && echo \"\$TERM\" > $tmux_term_tmp"
|
||||
tmux wait-for tmux_term_value
|
||||
TMUX_TERM=$(cat "$tmux_term_tmp")
|
||||
|
||||
# TODO it would be better to check for 256color or true color support
|
||||
if [[ "$TMUX_TERM" == "screen" ]]; then
|
||||
log_message " * Wrong \$TERM value '$TMUX_TERM'. Please add this to your .tmux.conf:"
|
||||
log_message ""
|
||||
log_message " set -g default-terminal 'screen-256color'"
|
||||
log_message " tmux source ~/.tmux.conf"
|
||||
log_message ""
|
||||
healthy=0
|
||||
fi
|
||||
|
||||
if [[ $(is_dir_empty "$CURRENT_DIR/../vendor/tmux-printer") == "1" ]]; then
|
||||
log_message " * Submodules not initialized properly. Please run:"
|
||||
log_message ""
|
||||
log_message " cd $TMUX_FINGERS_ROOT"
|
||||
log_message " git submodule update --init --recursive"
|
||||
log_message " tmux source ~/.tmux.conf"
|
||||
log_message ""
|
||||
healthy=0
|
||||
fi
|
||||
|
||||
if [[ $(version_major "$TMUX_VERSION") -le "2" ]] && \
|
||||
[[ $(version_minor "$TMUX_VERSION") -lt "6" ]] && \
|
||||
[[ "$OSTYPE" == "darwin"* ]] && \
|
||||
[[ $(program_exists "reattach-to-user-namespace") == "0" ]];
|
||||
then
|
||||
log_message " * It's recommended to install 'reattach-to-user-namespace' for better"
|
||||
log_message " clipboard integration in OSX. Please run:"
|
||||
log_message ""
|
||||
log_message " brew install reattach-to-user-namespace"
|
||||
log_message ""
|
||||
healthy=0
|
||||
fi
|
||||
|
||||
if [[ $healthy -eq 0 ]]; then
|
||||
log_message ""
|
||||
log_message "Follow this link for help on fixing issues:"
|
||||
log_message ""
|
||||
log_message " $HELP_LINK"
|
||||
log_message ""
|
||||
|
||||
dump_log
|
||||
|
||||
while [[ $(is_tmux_ready) = 0 ]]; do
|
||||
: # waiting for-tmux
|
||||
done
|
||||
|
||||
cat $health_tmp
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
rm -rf "$health_tmp"
|
||||
rm -rf "$tmux_term_tmp"
|
||||
}
|
||||
|
||||
perform_health_check
|
|
@ -1,33 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
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 ( $FINGERS_VERSION ) help:
|
||||
|
||||
- a-z: copies selected match to the clipboard
|
||||
- <ctrl> + a-z: copies selected match to the clipboard and triggers
|
||||
@fingers-ctrl-action. By default it triggers :open: action, which is useful
|
||||
for opening links in the browser for example.
|
||||
- <shift> + a-z: copies selected match to the clipboard and triggers
|
||||
@fingers-shift-action. By default it triggers :paste: action, which
|
||||
automatically pastes selected matches.
|
||||
- <alt> + a-z: copies selected match to the clipboard and triggers
|
||||
@fingers-alt-action. There is no default, configurable by the user.
|
||||
- <Tab>: toggle multi mode. First press enters multi mode, which allows
|
||||
to select multiple matches. Second press will exit with the selected matches
|
||||
copied to the clipboard.
|
||||
- <space>: toggle compact hints on/off
|
||||
- ?: show/hide this help
|
||||
- <Ctrl-C>, <esc> or q: exit [fingers] mode
|
||||
ENDOFHELP
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
BEGIN {
|
||||
n_matches = 0;
|
||||
n_lines = 0;
|
||||
|
||||
finger_patterns = ENVIRON["FINGERS_PATTERNS"];
|
||||
fingers_compact_hints = ENVIRON["FINGERS_COMPACT_HINTS"];
|
||||
|
||||
if (fingers_compact_hints)
|
||||
fingers_hint_position = ENVIRON["FINGERS_HINT_POSITION"];
|
||||
else
|
||||
fingers_hint_position = ENVIRON["FINGERS_HINT_POSITION_NOCOMPACT"];
|
||||
|
||||
if (fingers_compact_hints) {
|
||||
hint_format = ENVIRON["FINGERS_HINT_FORMAT"]
|
||||
hint_format_nocolor = ENVIRON["FINGERS_HINT_FORMAT_NOCOLOR"]
|
||||
highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT"]
|
||||
highlight_format_nocolor = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOLOR"]
|
||||
selected_highlight_format = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT"]
|
||||
selected_highlight_format_nocolor = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT_NOCOLOR"]
|
||||
selected_hint_format = ENVIRON["FINGERS_SELECTED_HINT_FORMAT"]
|
||||
selected_hint_format_nocolor = ENVIRON["FINGERS_SELECTED_HINT_FORMAT_NOCOLOR"]
|
||||
} else {
|
||||
hint_format = ENVIRON["FINGERS_HINT_FORMAT_NOCOMPACT"]
|
||||
highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOMPACT"]
|
||||
hint_format_nocolor = ENVIRON["FINGERS_HINT_FORMAT_NOCOMPACT_NOCOLOR"]
|
||||
highlight_format_nocolor = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOMPACT_NOCOLOR"]
|
||||
selected_highlight_format = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT_NOCOMPACT"]
|
||||
selected_highlight_format_nocolor = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT_NOCOMPACT_NOCOLOR"]
|
||||
selected_hint_format = ENVIRON["FINGERS_SELECTED_HINT_FORMAT_NOCOMPACT"]
|
||||
selected_hint_format_nocolor = ENVIRON["FINGERS_SELECTED_HINT_FORMAT_NOCOMPACT_NOCOLOR"]
|
||||
}
|
||||
|
||||
if (fingers_hint_position == "left") {
|
||||
general_compound_format = hint_format highlight_format
|
||||
selected_compound_format = selected_hint_format selected_highlight_format
|
||||
} else {
|
||||
general_compound_format = highlight_format hint_format
|
||||
selected_compound_format = selected_highlight_format selected_hint_format
|
||||
}
|
||||
|
||||
hint_lookup = ""
|
||||
|
||||
split(ENVIRON["FINGERS_SELECTED_HINTS"], selected_hints_arr, ":")
|
||||
|
||||
for (i = 1; i <= length(selected_hints_arr); ++i) {
|
||||
selected_hints_lookup[selected_hints_arr[i]] = 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
lines[n_lines] = $0
|
||||
|
||||
pos = 0;
|
||||
n_tokens = 0
|
||||
|
||||
line = $0
|
||||
|
||||
while (match(line, finger_patterns)) {
|
||||
n_matches++
|
||||
col_pos = RSTART;
|
||||
|
||||
pre_match = substr(line, 0, col_pos - 1);
|
||||
post_match = substr(line, col_pos + RLENGTH, length(line) - 1);
|
||||
match_token = substr(line, RSTART, RLENGTH);
|
||||
|
||||
tokens_by_line[n_lines][n_tokens]["value"] = pre_match
|
||||
tokens_by_line[n_lines][n_tokens]["type"] = "text"
|
||||
|
||||
n_tokens++
|
||||
|
||||
tokens_by_line[n_lines][n_tokens]["value"] = match_token
|
||||
tokens_by_line[n_lines][n_tokens]["type"] = "match"
|
||||
|
||||
n_tokens++
|
||||
|
||||
line = post_match;
|
||||
}
|
||||
|
||||
|
||||
if (n_tokens == 0) {
|
||||
tokens_by_line[n_lines][n_tokens]["value"] = line
|
||||
tokens_by_line[n_lines][n_tokens]["type"] = "text"
|
||||
} else if (length(post_match) > 0) {
|
||||
tokens_by_line[n_lines][n_tokens]["value"] = post_match
|
||||
tokens_by_line[n_lines][n_tokens]["type"] = "text"
|
||||
|
||||
n_tokens++
|
||||
}
|
||||
|
||||
n_lines++
|
||||
}
|
||||
|
||||
END {
|
||||
hints_path = ENVIRON["FINGERS_ALPHABET_DIR"] n_matches
|
||||
getline raw_hints < hints_path
|
||||
split(raw_hints, hints, " ")
|
||||
|
||||
hint_index = 1
|
||||
|
||||
for (line_index = 0; line_index < n_lines; line_index++) {
|
||||
tokens_in_this_line = length(tokens_by_line[line_index])
|
||||
|
||||
for (token_index = 0; token_index < tokens_in_this_line; token_index++) {
|
||||
token = tokens_by_line[line_index][token_index]["value"]
|
||||
token_type = tokens_by_line[line_index][token_index]["type"]
|
||||
|
||||
if (token_type == "match") {
|
||||
hint = hint_by_match[token]
|
||||
|
||||
if (!hint) {
|
||||
hint = hints[hint_index]
|
||||
hint_by_match[token] = hint
|
||||
hint_index = hint_index + 1
|
||||
hint_lookup = hint_lookup hint ":" token "\n"
|
||||
}
|
||||
|
||||
if (selected_hints_lookup[hint]) {
|
||||
this_hint_format_nocolor = selected_hint_format_nocolor
|
||||
this_compound_format = selected_compound_format
|
||||
} else {
|
||||
this_hint_format_nocolor = hint_format_nocolor
|
||||
this_compound_format = general_compound_format
|
||||
}
|
||||
|
||||
if (fingers_compact_hints) {
|
||||
hint_len = length(sprintf(this_hint_format_nocolor, hint))
|
||||
if (fingers_hint_position == "left")
|
||||
token = substr(token, hint_len + 1, length(token) - hint_len);
|
||||
else
|
||||
token = substr(token, 1, length(token) - hint_len);
|
||||
}
|
||||
|
||||
if (fingers_hint_position == "left")
|
||||
token = sprintf(this_compound_format, hint, token);
|
||||
else
|
||||
token = sprintf(this_compound_format, token, hint);
|
||||
}
|
||||
|
||||
printf "%s", token
|
||||
}
|
||||
|
||||
if (line_index < n_lines - 1) {
|
||||
printf "\n"
|
||||
}
|
||||
}
|
||||
|
||||
print hint_lookup | "cat 1>&3"
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/utils.sh
|
||||
|
||||
match_lookup_table=$(fingers_tmp)
|
||||
pane_output_temp=$(fingers_tmp)
|
||||
flushed_input=0
|
||||
|
||||
# exporting them so they can be properly deleted at fingers.sh handle_exit trap
|
||||
export match_lookup_table
|
||||
export pane_output_temp
|
||||
|
||||
function lookup_match() {
|
||||
local input=$1
|
||||
|
||||
input="$(echo "$input" | tr "A-Z" "a-z")"
|
||||
echo "$(cat $match_lookup_table | grep -i "^$input:" | sed "s/^$input://" | head -n 1)"
|
||||
}
|
||||
|
||||
function get_stdin() {
|
||||
if [[ $(cat $pane_output_temp | wc -l) -gt 0 ]]; then
|
||||
cat $pane_output_temp
|
||||
else
|
||||
flushed_input="1"
|
||||
tee $pane_output_temp
|
||||
fi
|
||||
}
|
||||
|
||||
function show_hints() {
|
||||
local fingers_pane_id=$1
|
||||
shift
|
||||
local compact_hints=$1
|
||||
shift
|
||||
local multi_mode=$1
|
||||
shift
|
||||
declare -a selected_hints=(${@})
|
||||
|
||||
FINGERS_ALPHABET_DIR="$CURRENT_DIR/../alphabets/$FINGERS_KEYBOARD_LAYOUT/"
|
||||
|
||||
clear_screen "$fingers_pane_id"
|
||||
echo "call_hinter $(($(date +%s%N)/1000000))" >> /tmp/fingers.log
|
||||
get_stdin | FINGERS_SELECTED_HINTS="$(array_join ":" "${selected_hints[@]}")" FINGERS_COMPACT_HINTS="$compact_hints" FINGERS_ALPHABET_DIR="$FINGERS_ALPHABET_DIR" $CURRENT_DIR/hinter.rb 3> $match_lookup_table
|
||||
}
|
||||
|
||||
function show_hints_and_swap() {
|
||||
current_pane_id=$1
|
||||
fingers_pane_id=$2
|
||||
compact_state=$3
|
||||
show_hints "$fingers_pane_id" "$compact_state"
|
||||
tmux swap-pane -s "$current_pane_id" -t "$fingers_pane_id"
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
tmux wait-for -L fingers-input
|
||||
|
||||
echo "$1" >> /tmp/fingers-command-queue
|
||||
|
||||
tmux wait-for -U fingers-input
|
||||
|
||||
exit 0
|
|
@ -1,40 +0,0 @@
|
|||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
function fingers_bind() {
|
||||
local key="$1"
|
||||
local command="$2"
|
||||
|
||||
tmux bind-key -Tfingers "$key" run-shell -b "$CURRENT_DIR/../fingers/cli.rb send_input '$command'"
|
||||
}
|
||||
|
||||
for char in {a..z}
|
||||
do
|
||||
# Disallowed characters
|
||||
#
|
||||
# * C-c is used for exit
|
||||
# * C-i is the same keycode as Tab ( reserving it for future usage )
|
||||
# * C-m is the same keycode as Enter ( reserving it for future usage )
|
||||
# * q is used for exit
|
||||
if [[ "$char" =~ [cimq] ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
fingers_bind "$char" "hint:$char:main"
|
||||
fingers_bind "$(echo "$char" | tr '[:lower:]' '[:upper:]')" "hint:$char:shift"
|
||||
fingers_bind "C-$char" "hint:$char:ctrl"
|
||||
fingers_bind "M-$char" "hint:$char:alt"
|
||||
done
|
||||
|
||||
fingers_bind "C-c" "exit"
|
||||
fingers_bind "q" "exit"
|
||||
fingers_bind "Escape" "exit"
|
||||
|
||||
fingers_bind "?" "toggle-help"
|
||||
fingers_bind "Space" "toggle-compact-mode"
|
||||
|
||||
fingers_bind "Enter" "noop"
|
||||
fingers_bind "Tab" "toggle-multi-mode"
|
||||
|
||||
fingers_bind "Any" "noop"
|
||||
|
||||
exit 0
|
|
@ -1,75 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/utils.sh
|
||||
|
||||
input_method="$1"
|
||||
|
||||
function init_fingers_pane() {
|
||||
local fingers_ids=$(tmux new-window -F "#{pane_id}:#{window_id}" -P -d -n "[fingers]" "$(init_pane_cmd)")
|
||||
local fingers_pane_id=$(echo "$fingers_ids" | cut -f1 -d:)
|
||||
local fingers_window_id=$(echo "$fingers_ids" | cut -f2 -d:)
|
||||
|
||||
local current_size=$(tmux list-panes -F "#{pane_width}:#{pane_height}:#{?pane_active,active,nope}" | grep active)
|
||||
local current_width=$(echo "$current_size" | cut -f1 -d:)
|
||||
local current_height=$(echo "$current_size" | cut -f2 -d:)
|
||||
|
||||
local current_window_size=$(tmux list-windows -F "#{window_width}:#{window_height}:#{?window_active,active,nope}" | grep active)
|
||||
local current_window_width=$(echo "$current_window_size" | cut -f1 -d:)
|
||||
local current_window_height=$(echo "$current_window_size" | cut -f2 -d:)
|
||||
|
||||
resize_to_width="$(expr "$current_window_width" - "$current_width" - 1)"
|
||||
resize_to_height="$(expr "$current_window_height" - "$current_height" - 1)"
|
||||
|
||||
if [[ ! $resize_to_width -eq -1 ]]; then
|
||||
tmux split-window -d -t "$fingers_pane_id" -h -l "$(expr "$current_window_width" - "$current_width" - 1)" '/bin/nop'
|
||||
tmux split-window -d -t "$fingers_pane_id" -l "$(expr "$current_window_height" - "$current_height" - 1)" '/bin/nop'
|
||||
fi
|
||||
|
||||
echo "$fingers_pane_id:$fingers_window_id"
|
||||
}
|
||||
|
||||
function capture_pane() {
|
||||
local pane_id=$1
|
||||
local out_path=$2
|
||||
local pane_info=$(tmux list-panes -s -F "#{pane_id}:#{pane_height}:#{scroll_position}:#{?pane_in_mode,1,0}" | grep "^$pane_id")
|
||||
|
||||
local pane_height=$(echo $pane_info | cut -d: -f2)
|
||||
local pane_scroll_position=$(echo $pane_info | cut -d: -f3)
|
||||
local pane_in_copy_mode=$(echo $pane_info | cut -d: -f4)
|
||||
|
||||
local start_capture=""
|
||||
|
||||
if [[ "$pane_in_copy_mode" == "1" ]]; then
|
||||
start_capture=$((-$pane_scroll_position))
|
||||
end_capture=$(($pane_height - $pane_scroll_position - 1))
|
||||
else
|
||||
start_capture=0
|
||||
end_capture="-"
|
||||
fi
|
||||
|
||||
tmux capture-pane -J -p -t $pane_id -E $end_capture -S $start_capture > $out_path
|
||||
}
|
||||
|
||||
function prompt_fingers_for_pane() {
|
||||
local current_pane_id=$1
|
||||
local last_pane_id=$2
|
||||
local fingers_init_data=$(init_fingers_pane)
|
||||
local fingers_pane_id=$(echo "$fingers_init_data" | cut -f1 -d':')
|
||||
local fingers_window_id=$(echo "$fingers_init_data" | cut -f2 -d':')
|
||||
local tmp_path=$(fingers_tmp)
|
||||
|
||||
wait
|
||||
|
||||
capture_pane "$current_pane_id" "$tmp_path"
|
||||
|
||||
local original_window_name=$(tmux display-message -p '#{window_name}')
|
||||
tmux set-window-option automatic-rename off
|
||||
pane_exec "$fingers_pane_id" "cat $tmp_path | $CURRENT_DIR/fingers-mode.sh \"$current_pane_id\" \"$fingers_pane_id\" \"$last_pane_id\" \"$fingers_window_id\" \"$tmp_path\" \"$original_window_name\" \"$input_method\""
|
||||
|
||||
echo $fingers_pane_id
|
||||
}
|
||||
|
||||
last_pane_id=$2
|
||||
current_pane_id=$(tmux list-panes -F "#{pane_id}:#{?pane_active,active,nope}" | grep active | cut -d: -f1)
|
||||
fingers_pane_id=$(prompt_fingers_for_pane "$current_pane_id" "$last_pane_id")
|
205
scripts/utils.sh
205
scripts/utils.sh
|
@ -1,205 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#TODO split all this crap in lib/ folder
|
||||
|
||||
function array_join() {
|
||||
local IFS="$1"; shift; echo "$*";
|
||||
}
|
||||
|
||||
function ord() {
|
||||
LC_CTYPE=C printf '%d' "'$1"
|
||||
}
|
||||
|
||||
function chr() {
|
||||
[ "$1" -lt 256 ] || return 1
|
||||
printf "\\$(printf '%03o' "$1")"
|
||||
}
|
||||
|
||||
function escape_quotes() {
|
||||
echo $1 | sed 's/"/\\"/g' | sed "s/'/\\'/g"
|
||||
}
|
||||
|
||||
function is_between() {
|
||||
local value=$1
|
||||
local lower=$2
|
||||
local upper=$3
|
||||
|
||||
if [[ $value -ge $lower ]] && [[ $value -le $upper ]]; then
|
||||
echo 1
|
||||
else
|
||||
echo 0
|
||||
fi
|
||||
}
|
||||
|
||||
A_CODE=$(ord "a")
|
||||
Z_CODE=$(ord "z")
|
||||
CAPITAL_A_CODE=$(ord "A")
|
||||
CAPITAL_Z_CODE=$(ord "Z")
|
||||
|
||||
function is_letter() {
|
||||
echo $(is_between $(ord $1) $A_CODE $Z_CODE)
|
||||
}
|
||||
|
||||
function is_capital_letter() {
|
||||
echo $(is_between $(ord $1) $CAPITAL_A_CODE $CAPITAL_Z_CODE)
|
||||
}
|
||||
|
||||
function is_alpha() {
|
||||
if [[ $(is_letter $1) == "1" ]] || [[ $(is_capital_letter $1) == "1" ]]; then
|
||||
echo 1
|
||||
else
|
||||
echo 0
|
||||
fi
|
||||
}
|
||||
|
||||
function str_to_ascii() {
|
||||
local input=$1
|
||||
local output=''
|
||||
|
||||
for (( i=0; i<${#input}; i++ )); do
|
||||
output="${output}$(ord "${input:$i:1}") "
|
||||
done
|
||||
|
||||
echo "${output// $//}"
|
||||
}
|
||||
|
||||
function display_message() {
|
||||
local original_display_time=$(tmux show-option -gqv display-time)
|
||||
tmux set-option -g display-time $2
|
||||
tmux display-message "$1"
|
||||
tmux set-option -g display-time $original_display_time
|
||||
}
|
||||
|
||||
function revert_to_original_pane() {
|
||||
local current_pane_id=$1
|
||||
local fingers_pane_id=$2
|
||||
local fingers_window_id=$3
|
||||
local last_pane_id=$4
|
||||
local pane_was_zoomed=$5
|
||||
tmux swap-pane -s "$current_pane_id" -t "$fingers_pane_id"
|
||||
tmux kill-window -t "$fingers_window_id"
|
||||
[[ $pane_was_zoomed == "1" ]] && zoom_pane "$current_pane_id"
|
||||
|
||||
if [[ ! -z "$last_pane_id" ]]; then
|
||||
tmux select-pane -t "$last_pane_id"
|
||||
tmux select-pane -t "$current_pane_id"
|
||||
fi
|
||||
}
|
||||
|
||||
function pane_exec() {
|
||||
local pane_id=$1
|
||||
local pane_command=$2
|
||||
|
||||
tmux send-keys -t $pane_id " $pane_command"
|
||||
tmux send-keys -t $pane_id Enter
|
||||
}
|
||||
|
||||
function fingers_tmp() {
|
||||
local tmp_path=$(mktemp "${TMPDIR:-/tmp}/tmux-fingers.XXXXXXXX")
|
||||
chmod 600 "$tmp_path"
|
||||
echo "$tmp_path"
|
||||
}
|
||||
|
||||
function clear_screen() {
|
||||
local fingers_pane_id=$1
|
||||
clear
|
||||
tmux clearhist -t $fingers_pane_id
|
||||
}
|
||||
|
||||
function current_shell() {
|
||||
echo "$SHELL" | grep -o "\w*$"
|
||||
}
|
||||
|
||||
function init_pane_cmd() {
|
||||
init_bash="bash --norc --noprofile"
|
||||
if [[ $(current_shell) == "fish" ]]; then
|
||||
set_env="set -x HISTFILE /dev/null; "
|
||||
else
|
||||
set_env="HISTFILE=/dev/null "
|
||||
fi
|
||||
|
||||
echo "$set_env $init_bash"
|
||||
}
|
||||
|
||||
function tmux_list_vi_copy_keys() {
|
||||
output=$(tmux list-keys -t vi-copy 2> /dev/null)
|
||||
|
||||
if [[ -z $output ]]; then
|
||||
output=$(tmux list-keys -Tcopy-mode-vi)
|
||||
fi
|
||||
|
||||
echo "$output"
|
||||
}
|
||||
|
||||
function is_dir_empty() {
|
||||
local dir_path="$1"
|
||||
|
||||
if [[ $(ls -1 "$dir_path" | wc -l) -gt 0 ]]; then
|
||||
echo 0
|
||||
else
|
||||
echo 1
|
||||
fi
|
||||
}
|
||||
|
||||
function resolve_path() {
|
||||
local path=$1
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
echo "$(stat -f "%N" "$path")"
|
||||
else
|
||||
echo "$(readlink -f "$path")"
|
||||
fi
|
||||
}
|
||||
|
||||
function program_exists() {
|
||||
local prog="$1"
|
||||
|
||||
which "$prog" &> /dev/null
|
||||
|
||||
if [[ $? == "0" ]]; then
|
||||
echo "1"
|
||||
else
|
||||
echo "0"
|
||||
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 version_compare_ge() {
|
||||
local NUMBER_OF_VERSION_COMPONENTS=2
|
||||
local version=$1
|
||||
local target=$2
|
||||
|
||||
if [[ $version == $target ]]; then
|
||||
echo 1
|
||||
else
|
||||
local result=0
|
||||
|
||||
for i in $(seq 1 "$NUMBER_OF_VERSION_COMPONENTS"); do
|
||||
version_component=$(echo "$version" | cut -f "$i" -d'.')
|
||||
target_component=$(echo "$target" | cut -f "$i" -d'.')
|
||||
|
||||
if [[ "$version_component" -gt "$target_component" ]]; then
|
||||
result=1
|
||||
break
|
||||
elif [[ "$version_component" -lt "$target_component" ]]; then
|
||||
result=0
|
||||
break
|
||||
elif [[ "$version_component" -eq "$target_component" ]]; then
|
||||
continue
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo $result
|
||||
}
|
||||
|
||||
function get_tmux_version() {
|
||||
echo "$(tmux -V | grep -Eio "([0-9]+(\.[0-9]))(?:-rc)?")"
|
||||
}
|
|
@ -7,7 +7,7 @@ describe 'acceptance', :retry => 3 do
|
|||
|
||||
context 'basic yank' do
|
||||
before do
|
||||
exec('cat test/fixtures/grep-output')
|
||||
exec('cat spec/fixtures/grep-output')
|
||||
|
||||
invoke_fingers
|
||||
|
||||
|
@ -23,7 +23,7 @@ describe 'acceptance', :retry => 3 do
|
|||
let(:config_name) { 'custom-patterns' }
|
||||
|
||||
before do
|
||||
exec('cat test/fixtures/custom-patterns')
|
||||
exec('cat spec/fixtures/custom-patterns')
|
||||
|
||||
send_keys('echo yanked text is ')
|
||||
|
||||
|
@ -45,7 +45,7 @@ describe 'acceptance', :retry => 3 do
|
|||
|
||||
context 'more than one match per line' do
|
||||
before do
|
||||
exec('cat test/fixtures/ip-output')
|
||||
exec('cat spec/fixtures/ip-output')
|
||||
|
||||
invoke_fingers
|
||||
send_keys('i')
|
||||
|
@ -83,7 +83,7 @@ describe 'acceptance', :retry => 3 do
|
|||
|
||||
before do
|
||||
`rm -rf /tmp/fingers-stub-output`
|
||||
exec('cat test/fixtures/grep-output')
|
||||
exec('cat spec/fixtures/grep-output')
|
||||
|
||||
invoke_fingers
|
||||
send_keys('M-y')
|
||||
|
@ -103,7 +103,7 @@ describe 'acceptance', :retry => 3 do
|
|||
|
||||
context 'shift action' do
|
||||
before do
|
||||
exec('cat test/fixtures/grep-output')
|
||||
exec('cat spec/fixtures/grep-output')
|
||||
|
||||
send_keys('yanked text is ')
|
||||
invoke_fingers
|
||||
|
@ -121,7 +121,7 @@ describe 'acceptance', :retry => 3 do
|
|||
|
||||
before do
|
||||
`rm -rf /tmp/fingers-stub-output`
|
||||
exec('cat test/fixtures/grep-output')
|
||||
exec('cat spec/fixtures/grep-output')
|
||||
|
||||
invoke_fingers
|
||||
send_keys(hint_to_press)
|
||||
|
@ -148,7 +148,7 @@ describe 'acceptance', :retry => 3 do
|
|||
|
||||
before do
|
||||
# zleep 3
|
||||
exec('cat test/fixtures/quotes')
|
||||
exec('cat spec/fixtures/quotes')
|
||||
send_keys('echo yanked text is ')
|
||||
invoke_fingers
|
||||
send_keys('b')
|
||||
|
|
|
@ -105,7 +105,7 @@ shared_context 'tmuxomatic setup', a: :b do
|
|||
def fingers_stubs_path
|
||||
File.expand_path(File.join(
|
||||
fingers_root,
|
||||
'./test/stubs'
|
||||
'./spec/stubs'
|
||||
))
|
||||
end
|
||||
|
||||
|
@ -113,7 +113,7 @@ shared_context 'tmuxomatic setup', a: :b do
|
|||
conf_path = File.expand_path(
|
||||
File.join(
|
||||
File.dirname(__FILE__),
|
||||
'../test/conf/',
|
||||
'../spec/conf/',
|
||||
"#{config_name}.conf"
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
target=$1
|
||||
benchmark_repo_path="/tmp/tmux-fingers-benchmark"
|
||||
|
||||
function setup_window_size() {
|
||||
stty cols 174
|
||||
stty rows 42
|
||||
}
|
||||
|
||||
function snippet_for {
|
||||
echo "echo \"\$(cat /tmp/benchmark-execution-id) $1 \$((\$(date +%s%N)/1000000))\" >> ~/shared/benchmark.log"
|
||||
}
|
||||
|
||||
SAMPLES=${SAMPLES:=50}
|
||||
|
||||
function setup_benchmark_repo() {
|
||||
echo "Setting up benchmark repo ..."
|
||||
rm -rf "$benchmark_repo_path"
|
||||
cp -r ~/shared "$benchmark_repo_path"
|
||||
|
||||
pushd "$benchmark_repo_path" &> /dev/null
|
||||
find . -type f | xargs sed -i "s!# %BENCHMARK_START%!$(snippet_for "start")!"
|
||||
find . -type f | xargs sed -i "s!# %BENCHMARK_END%!$(snippet_for "end")!"
|
||||
popd &> /dev/null
|
||||
}
|
||||
|
||||
function set_execution_id() {
|
||||
execution_id="$(mktemp -u "benchmark.XXXXXX")"
|
||||
echo "$execution_id" > /tmp/benchmark-execution-id
|
||||
}
|
||||
|
||||
if [[ "$target" == "within-vm" ]]; then
|
||||
setup_window_size
|
||||
setup_benchmark_repo
|
||||
set_execution_id
|
||||
|
||||
cat /dev/null > ~/shared/benchmark.log
|
||||
|
||||
echo "Will run benchmark $SAMPLES times"
|
||||
|
||||
pushd "$benchmark_repo_path" &> /dev/null
|
||||
for benchmark in $(ls $benchmark_repo_path/test/benchmarks/*.sh); do
|
||||
|
||||
for i in $(seq 1 "$SAMPLES"); do
|
||||
echo "* Running $benchmark [ $i ]"
|
||||
sleep 1
|
||||
$benchmark
|
||||
done
|
||||
done
|
||||
popd &> /dev/null
|
||||
elif [[ -z "$target" ]]; then
|
||||
echo "Running benchmarks"
|
||||
vagrant up "$target" &>> /dev/null
|
||||
vagrant ssh "$target" -c "cd shared && SAMPLES=$SAMPLES ./test/benchmark.sh within-vm" 2> /dev/null
|
||||
node dev/benchmark-report.js
|
||||
fi
|
|
@ -1,18 +0,0 @@
|
|||
#!/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 "benchmark"
|
||||
|
||||
init_pane
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "C-c"
|
||||
|
||||
tmuxomatic__end end_hook
|
|
@ -1,56 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# this assumes tmuxomatic has been already sourced
|
||||
TMUX_PREFIX=C-a
|
||||
|
||||
function tmux_send() {
|
||||
local key=$1
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic send-keys "$TMUX_PREFIX"
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic send-keys "$key"
|
||||
tmuxomatic__sleep 1
|
||||
}
|
||||
|
||||
function tmux_paste() {
|
||||
tmux_send "]"
|
||||
}
|
||||
|
||||
function init_pane() {
|
||||
tmux_send "c"
|
||||
tmuxomatic__exec "export PS1='# '; clear"
|
||||
}
|
||||
|
||||
function init_pane_fish() {
|
||||
tmux_send "c"
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic__exec "function fish_prompt; echo '# '; end"
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic__exec "clear"
|
||||
}
|
||||
|
||||
function invoke_fingers() {
|
||||
tmux_send "F"
|
||||
tmuxomatic__sleep 1
|
||||
}
|
||||
|
||||
function echo_yanked() {
|
||||
tmuxomatic__sleep 1
|
||||
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__exec "tmux kill-session -t test"
|
||||
}
|
||||
|
||||
function end_hook() {
|
||||
sudo rm -rf /tmp/fingers-*
|
||||
tmuxomatic__exec "tmux kill-session -t test"
|
||||
}
|
91
test/run.sh
91
test/run.sh
|
@ -1,91 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
SPEC_OUTPUT_LOG=$CURRENT_DIR/../spec-output.log
|
||||
TEST_LOG=$CURRENT_DIR/../test.log
|
||||
MAX_RETRIES=5
|
||||
target=$1
|
||||
|
||||
cat /dev/null > $SPEC_OUTPUT_LOG
|
||||
cat /dev/null > $TEST_LOG
|
||||
|
||||
if [[ -n "$CI_TMUX_VERSION" ]]; then
|
||||
VERSIONS=("$CI_TMUX_VERSION")
|
||||
else
|
||||
VERSIONS=("2.3" "2.4" "2.5" "2.6" "2.7" "2.8" "2.9" "2.9a" "3.0")
|
||||
fi
|
||||
|
||||
if [[ "$target" == "within-vm" ]]; then
|
||||
# clean previous ogs
|
||||
rm -rf $CURRENT_DIR/../tmuxomatic*
|
||||
|
||||
stty cols 80
|
||||
stty rows 24
|
||||
fail_count=0
|
||||
for version in "${VERSIONS[@]}"; do
|
||||
$CURRENT_DIR/use-tmux.sh "$version"
|
||||
echo "Running tests in tmux $version"
|
||||
|
||||
pgrep tmux | xargs kill -9
|
||||
|
||||
for test_file in $(ls $CURRENT_DIR/specs/*_spec.sh); do
|
||||
result="* $test_file ..."
|
||||
sleep 1
|
||||
|
||||
tries=0
|
||||
while [[ $tries -lt $MAX_RETRIES ]]; do
|
||||
echo "Running $test_file" >> $SPEC_OUTPUT_LOG
|
||||
$test_file &>> $TEST_LOG
|
||||
exit_code=$?
|
||||
|
||||
if [[ $exit_code -eq 0 ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ $exit_code -eq 2 ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
tries=$((tries + 1))
|
||||
done
|
||||
|
||||
if [[ $exit_code -eq 0 ]]; then
|
||||
result="$result OK"
|
||||
elif [[ $exit_code -eq 2 ]]; then
|
||||
result="$result SKIP"
|
||||
else
|
||||
fail_count=$((fail_count + 1))
|
||||
result="$result FAIL"
|
||||
fi
|
||||
|
||||
echo "$result" >> $SPEC_OUTPUT_LOG
|
||||
echo "$result"
|
||||
done
|
||||
done
|
||||
|
||||
if [[ $fail_count -gt 0 ]]; then
|
||||
echo "Displaying tmuxomatic logs"
|
||||
cat $CURRENT_DIR/../tmuxomatic*
|
||||
cat $CURRENT_DIR/../test.log
|
||||
fi
|
||||
|
||||
exit $fail_count
|
||||
elif [[ -z "$target" ]]; then
|
||||
$CURRENT_DIR/run.sh ubuntu
|
||||
ubuntu_fail_count=$?
|
||||
|
||||
total_fail_count=$((ubuntu_fail_count))
|
||||
|
||||
if [[ $total_fail_count == 0 ]]; then
|
||||
echo "All tests passed, awesome!"
|
||||
else
|
||||
echo "$total_fail_count tests failed."
|
||||
cat $SPEC_OUTPUT_LOG
|
||||
fi
|
||||
|
||||
exit $total_fail_count
|
||||
else
|
||||
echo "Running tests on $target"
|
||||
vagrant up "$target" &>> /dev/null
|
||||
vagrant ssh "$target" -c "cd shared && ./test/run.sh within-vm" 2> /dev/null
|
||||
fi
|
|
@ -1,25 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
if [[ ! $(version_compare_ge "$(get_tmux_version)" "2.8") == 1 ]]; then
|
||||
tmuxomatic__skip
|
||||
fi
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "alt-action"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "M-a"
|
||||
|
||||
tmuxomatic__sleep 1
|
||||
|
||||
tmuxomatic__exec "cat /tmp/fingers-stub-output"
|
||||
tmuxomatic__expect "action-stub => scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,18 +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 "basic"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "a"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__expect "yanked text is scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,29 +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 "quotes"
|
||||
init_pane
|
||||
|
||||
|
||||
tmuxomatic__exec "clear && cat ./test/fixtures/quotes"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "s"
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic__exec "cat /tmp/fingers-stub-output"
|
||||
tmuxomatic__expect 'action-stub => "laser"'
|
||||
|
||||
tmuxomatic__sleep 1
|
||||
|
||||
tmuxomatic__exec "clear && cat ./test/fixtures/quotes"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "a"
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic__exec "cat /tmp/fingers-stub-output"
|
||||
tmuxomatic__expect "action-stub => 'laser'"
|
||||
|
||||
tmuxomatic__end end_hook
|
|
@ -1,25 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
if [[ ! $(version_compare_ge "$(get_tmux_version)" "2.8") == 1 ]]; then
|
||||
tmuxomatic__skip
|
||||
fi
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "ctrl-action"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "C-a"
|
||||
|
||||
tmuxomatic__sleep 1
|
||||
|
||||
tmuxomatic__exec "cat /tmp/fingers-stub-output"
|
||||
tmuxomatic__expect "action-stub => scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,31 +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 "basic"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "a"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "C-c"
|
||||
|
||||
sleep 1
|
||||
|
||||
tmp_files_after=$(sudo ls -l /tmp/* | grep fingers | grep -v fingers-stub-output | wc -l)
|
||||
|
||||
if [[ "$tmp_files_after" -eq 0 ]]; then
|
||||
TMUXOMATIC_EXIT_CODE=0
|
||||
else
|
||||
TMUXOMATIC_EXIT_CODE=1
|
||||
fi
|
||||
|
||||
tmuxomatic__end end_hook
|
|
@ -1,30 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
|
||||
tmuxomatic__skip
|
||||
fi
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
tmuxomatic__exec "sudo su - fishman"
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic__exec "cd /opt/vagrant/shared"
|
||||
tmuxomatic__sleep 1
|
||||
tmuxomatic__exec "tmux -f /opt/vagrant/shared/test/conf/basic.conf new -s test"
|
||||
|
||||
init_pane_fish
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "a"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__sleep 1
|
||||
|
||||
tmuxomatic__expect "yanked text is scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,26 +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 "custom-patterns"
|
||||
init_pane
|
||||
tmuxomatic__exec "cat ./test/fixtures/custom-patterns"
|
||||
|
||||
tmuxomatic send-keys "echo yanked text is "
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "a"
|
||||
tmux_paste
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "d"
|
||||
tmux_paste
|
||||
|
||||
tmuxomatic send-keys Enter
|
||||
|
||||
tmuxomatic__expect "yanked text is W00TW00TW00TYOLOYOLOYOLO"
|
||||
tmuxomatic__end end_hook
|
|
@ -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 "basic"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/ip-output"
|
||||
tmuxomatic__sleep 1
|
||||
invoke_fingers
|
||||
|
||||
tmuxomatic send-keys "p"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__expect "yanked text is 10.0.3.255"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,24 +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 "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__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"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,19 +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 "basic"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
|
||||
tmuxomatic send-keys "yanked text is "
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "A"
|
||||
|
||||
tmuxomatic__expect "yanked text is scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -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
|
||||
|
||||
TMUX_PREFIX=C-space
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "custom-bindings"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "a"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__expect "yanked text is scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,113 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
TMUXOMATIC_CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
TMUXOMATIC_SOCKET=tmuxomatic
|
||||
TMUXOMATIC_TIMEOUT="10"
|
||||
TMUXOMATIC_EXIT_CODE=''
|
||||
|
||||
source $TMUXOMATIC_CURRENT_DIR/../scripts/utils.sh
|
||||
|
||||
function tmuxomatic() {
|
||||
TMUX='' tmux -L "$TMUXOMATIC_SOCKET" "$@"
|
||||
}
|
||||
|
||||
function tmuxomatic__exec() {
|
||||
tmuxomatic send-keys "$1"
|
||||
tmuxomatic send-keys Enter
|
||||
}
|
||||
|
||||
function tmuxomatic__skip() {
|
||||
exit 2
|
||||
}
|
||||
|
||||
function tmuxomatic__begin() {
|
||||
tmuxomatic list-sessions &> /dev/null
|
||||
|
||||
if [[ $? -eq 1 ]]; then
|
||||
tmuxomatic -f /dev/null new-session -d -s tmuxomatic
|
||||
|
||||
tmuxomatic set -g prefix F12
|
||||
tmuxomatic set -g status off
|
||||
|
||||
tmux_version=$(get_tmux_version)
|
||||
|
||||
if [[ $(version_compare_ge "$tmux_version" "2.9") == 1 ]]; then
|
||||
tmuxomatic resize-window -x 80 -y 24
|
||||
else
|
||||
tmuxomatic set-window-option force-width 80
|
||||
tmuxomatic set-window-option force-height 24
|
||||
fi
|
||||
|
||||
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
|
||||
tmuxomatic__sleep 1
|
||||
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
|
||||
#
|
||||
# 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() {
|
||||
sleep "$1"
|
||||
}
|
||||
|
||||
# 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)
|
||||
}
|
Loading…
Reference in New Issue