working in copy mode
This commit is contained in:
parent
970a7be611
commit
fce012bb93
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
clear
|
|
||||||
|
|
||||||
#TODO move this out of here!
|
#TODO move this out of here!
|
||||||
current_pane_id=$1
|
current_pane_id=$1
|
||||||
|
@ -9,6 +8,11 @@ ALPHABET=asdfqwertjkluiop
|
||||||
ALPHABET_SIZE=${#ALPHABET}
|
ALPHABET_SIZE=${#ALPHABET}
|
||||||
HINTS=(aa as ad af aq aw ae ar at aj ak al au ai ao ap sa ss sd sf sq sw se sr st sj sk sl su si so sp da ds dd df dq dw de dr dt dj dk dl du di do dp fa fs fd ff fq fw fe fr ft fj fk fl fu fi fo fp qa qs qd qf qq qw qe qr qt qj qk ql qu qi qo qp wa ws wd wf wq ww we wr wt wj e r t j k l u i o p)
|
HINTS=(aa as ad af aq aw ae ar at aj ak al au ai ao ap sa ss sd sf sq sw se sr st sj sk sl su si so sp da ds dd df dq dw de dr dt dj dk dl du di do dp fa fs fd ff fq fw fe fr ft fj fk fl fu fi fo fp qa qs qd qf qq qw qe qr qt qj qk ql qu qi qo qp wa ws wd wf wq ww we wr wt wj e r t j k l u i o p)
|
||||||
|
|
||||||
|
function clear_screen() {
|
||||||
|
clear
|
||||||
|
tmux clearhist
|
||||||
|
}
|
||||||
|
|
||||||
function get_hint() {
|
function get_hint() {
|
||||||
echo ${HINTS[$1]}
|
echo ${HINTS[$1]}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +21,8 @@ function fancy() {
|
||||||
printf "\033[1;33m$1\033[0m"
|
printf "\033[1;33m$1\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear_screen
|
||||||
|
|
||||||
PATTERNS=
|
PATTERNS=
|
||||||
|
|
||||||
lines=''
|
lines=''
|
||||||
|
@ -35,17 +41,16 @@ match_lookup=''
|
||||||
OLDIFS=$IFS
|
OLDIFS=$IFS
|
||||||
IFS=$(echo -en "\n\b") # wtf bash?
|
IFS=$(echo -en "\n\b") # wtf bash?
|
||||||
for match in $matches ; do
|
for match in $matches ; do
|
||||||
echo "for match [$match]"
|
|
||||||
hint=`get_hint $i`
|
hint=`get_hint $i`
|
||||||
linenumber=`echo $match | cut -f1 -d:`
|
linenumber=`echo $match | cut -f1 -d:`
|
||||||
text=`echo $match | cut -f2 -d:`
|
text=`echo $match | cut -f2 -d:`
|
||||||
output=`echo -e "$output" | sed "${linenumber}s!$text!$(fancy $text) $(fancy "[$hint]")!g"`
|
output=`echo -ne "$output" | sed "${linenumber}s!$text!$(fancy $text) $(fancy "[$hint]")!g"`
|
||||||
match_lookup="$match_lookup\n$hint:$text"
|
match_lookup="$match_lookup\n$hint:$text"
|
||||||
i=$(($i+1))
|
i=$(($i+1))
|
||||||
done
|
done
|
||||||
IFS=$OLDIFS
|
IFS=$OLDIFS
|
||||||
|
|
||||||
echo -e "$output"
|
echo -ne "$output"
|
||||||
|
|
||||||
function handle_exit() {
|
function handle_exit() {
|
||||||
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
|
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
|
||||||
|
@ -55,7 +60,7 @@ function handle_exit() {
|
||||||
trap "handle_exit" EXIT
|
trap "handle_exit" EXIT
|
||||||
|
|
||||||
input=''
|
input=''
|
||||||
while read -n 1 char
|
while read -r -s -n1 char
|
||||||
do
|
do
|
||||||
input="$input$char"
|
input="$input$char"
|
||||||
result=`echo -e $match_lookup | grep "^$input:" | cut -f2 -d:`
|
result=`echo -e $match_lookup | grep "^$input:" | cut -f2 -d:`
|
||||||
|
@ -64,7 +69,7 @@ do
|
||||||
|
|
||||||
if [[ ! -z $result ]]; then
|
if [[ ! -z $result ]]; then
|
||||||
clear
|
clear
|
||||||
echo "$result"
|
echo -n "$result"
|
||||||
|
|
||||||
tmux copy-mode
|
tmux copy-mode
|
||||||
tmux send-key "H" # top of buffer
|
tmux send-key "H" # top of buffer
|
||||||
|
|
|
@ -11,27 +11,47 @@ function pane_exec() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_fingers_pane() {
|
function init_fingers_pane() {
|
||||||
local pane_id=`tmux new-window -P -d -n "!fingers" | cut -d: -f2`
|
local pane_id=`tmux new-window -F "#{pane_id}" -P -d -n "!fingers"`
|
||||||
|
|
||||||
echo $pane_id
|
echo $pane_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 -p -t $pane_id -E $end_capture -S $start_capture > $out_path
|
||||||
|
}
|
||||||
|
|
||||||
function prompt_fingers_for_pane() {
|
function prompt_fingers_for_pane() {
|
||||||
local current_pane_id=$1
|
local current_pane_id=$1
|
||||||
local fingers_pane_id=`init_fingers_pane`
|
local fingers_pane_id=`init_fingers_pane`
|
||||||
local tmp_path=`mktemp --suffix "tmux-fingers"`
|
local tmp_path=`mktemp --suffix "tmux-fingers"`
|
||||||
wait
|
wait
|
||||||
|
|
||||||
tmux capture-pane -p -t $current_pane_id > $tmp_path
|
capture_pane "$current_pane_id" "$tmp_path"
|
||||||
pane_exec $fingers_pane_id "cat $tmp_path | $CURRENT_DIR/fingers.sh $current_pane_id $fingers_pane_id"
|
pane_exec $fingers_pane_id "cat $tmp_path | $CURRENT_DIR/fingers.sh $current_pane_id $fingers_pane_id"
|
||||||
|
|
||||||
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
|
tmux swap-pane -s $current_pane_id -t $fingers_pane_id
|
||||||
|
|
||||||
#rm $tmp_path
|
##rm $tmp_path
|
||||||
|
|
||||||
echo $fingers_pane_id
|
echo $fingers_pane_id
|
||||||
}
|
}
|
||||||
|
|
||||||
current_pane_id=`tmux list-panes | grep active | grep -oE ^[[:digit:]]+`
|
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`
|
fingers_pane_id=`prompt_fingers_for_pane $current_pane_id`
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
tmux bind -n C-f run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh"
|
tmux bind-key F run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh"
|
||||||
|
|
Loading…
Reference in New Issue