vi/emacs mode-keys support without EOL

This commit is contained in:
Jorge Morante 2016-04-30 01:26:43 +02:00
parent b822109b31
commit 74cd4fa5e2
2 changed files with 66 additions and 7 deletions

56
scripts/actions.sh Executable file
View File

@ -0,0 +1,56 @@
#!/bin/bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMUX_COPY_MODE=$(tmux show-option -gwv mode-keys)
function start_copy_mode() {
tmux copy-mode
}
function start_selection() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
tmux send-keys "Space"
else
tmux send-keys "C-Space"
fi
}
function top_of_buffer() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
tmux send-keys "h"
else
tmux send-keys "M-R"
fi
}
function start_of_line() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
tmux send-keys "0"
else
tmux send-keys "C-a"
fi
}
function end_of_line() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
tmux send-keys "$"
else
tmux send-keys "C-e"
fi
}
function cursor_left() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
tmux send-keys "h"
else
tmux send-keys "Left"
fi
}
function copy_selection() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
tmux send-keys "Enter"
else
tmux send-keys "M-w"
fi
}

View File

@ -1,7 +1,8 @@
#!/bin/bash
DIRNAME="$(dirname "$0")"
source $DIRNAME/config.sh
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/config.sh
source $CURRENT_DIR/actions.sh
#TODO move this out of here!
current_pane_id=$1
@ -74,11 +75,13 @@ do
clear
echo -n "$result"
tmux copy-mode
tmux send-key "H" # top of buffer
tmux send-key "v" # start selection
tmux send-key "$" # end of word
tmux send-key "y" # yank
start_copy_mode
top_of_buffer
start_of_line
start_selection
end_of_line
cursor_left
copy_selection
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
tmux kill-pane -t $fingers_pane_id