tmux-fingers/scripts/fingers.sh

77 lines
1.3 KiB
Bash
Raw Normal View History

2016-05-02 21:15:29 +02:00
#!/usr/bin/env bash
2016-04-26 21:44:18 +02:00
2016-04-30 01:26:43 +02:00
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/config.sh
source $CURRENT_DIR/actions.sh
2016-04-30 02:42:56 +02:00
source $CURRENT_DIR/hints.sh
2016-04-30 00:35:52 +02:00
2016-05-12 09:11:58 +02:00
FINGERS_COPY_COMMAND=$(tmux show-option -gqv @fingers-copy-command)
2016-04-26 21:44:18 +02:00
current_pane_id=$1
fingers_pane_id=$2
tmp_path=$3
2016-04-24 01:36:09 +02:00
2016-04-30 01:36:21 +02:00
BACKSPACE=$'\177'
2016-04-24 01:36:09 +02:00
2016-04-28 22:27:40 +02:00
function clear_screen() {
clear
tmux clearhist -t $fingers_pane_id
2016-04-28 22:27:40 +02:00
}
2016-04-30 02:42:56 +02:00
function has_capitals() {
echo $1 | grep [A-Z] | wc -l
2016-04-24 01:36:09 +02:00
}
2016-04-28 22:27:40 +02:00
clear_screen
2016-04-30 02:42:56 +02:00
print_hints
2016-05-12 08:46:57 +02:00
tmux swap-pane -s "$current_pane_id" -t "$fingers_pane_id"
2016-04-24 01:36:09 +02:00
2016-04-26 21:44:18 +02:00
function handle_exit() {
2016-05-02 21:15:29 +02:00
tmux swap-pane -s "$current_pane_id" -t "$fingers_pane_id"
tmux kill-pane -t "$fingers_pane_id"
rm -rf $tmp_path
2016-04-26 21:44:18 +02:00
}
2016-04-30 02:42:56 +02:00
function copy_result() {
local result=$1
2016-05-12 09:11:58 +02:00
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
2016-05-12 09:11:58 +02:00
fi
2016-04-30 02:42:56 +02:00
}
2016-04-26 21:44:18 +02:00
trap "handle_exit" EXIT
2016-04-24 01:36:09 +02:00
input=''
2016-04-28 22:27:40 +02:00
while read -r -s -n1 char
2016-04-24 01:36:09 +02:00
do
2016-04-30 02:42:56 +02:00
if [[ $char == "$BACKSPACE" ]]; then
2016-04-30 01:36:21 +02:00
input=""
else
input="$input$char"
fi
2016-04-30 02:42:56 +02:00
result=$(lookup_match "$input")
2016-04-24 01:36:09 +02:00
2016-04-26 21:44:18 +02:00
tmux display-message "$input"
2016-04-30 02:42:56 +02:00
if [[ -z $result ]]; then
continue
fi
2016-04-26 21:44:18 +02:00
2016-05-01 19:50:57 +02:00
copy_result "$result"
revert_to_original_pane $current_pane_id $fingers_pane_id
2016-04-30 02:42:56 +02:00
exit 0
2016-04-26 21:44:18 +02:00
done < /dev/tty