tmux-fingers/scripts/fingers.sh

74 lines
1.3 KiB
Bash
Raw Normal View History

2016-04-24 01:36:09 +02:00
#!/bin/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-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
}
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-04-24 01:36:09 +02:00
2016-04-26 21:44:18 +02:00
function handle_exit() {
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
clear
echo -n "$result"
start_copy_mode
top_of_buffer
start_of_line
start_selection
end_of_line
cursor_left
copy_selection
}
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
#TODO meeec, still not working
#if [[ $(has_capitals $input) == "1" ]]; then
#tmux command-prompt -p "fingers-exec:" "run-shell -t $fingers_pane_id $CURRENT_DIR/exec.sh '%%' '$result' '${current_pane_id//%}' '${fingers_pane_id//%}'"
#else
copy_result "$result"
revert_to_original_pane $current_pane_id $fingers_pane_id
#fi
2016-04-30 02:42:56 +02:00
exit 0
2016-04-26 21:44:18 +02:00
done < /dev/tty