From fce012bb93ce4ee7fb691a46e5b3bda355a6b9c0 Mon Sep 17 00:00:00 2001 From: Jorge Morante Date: Thu, 28 Apr 2016 22:27:40 +0200 Subject: [PATCH] working in copy mode --- scripts/fingers.sh | 17 +++++++++++------ scripts/tmux-fingers.sh | 32 ++++++++++++++++++++++++++------ tmux-fingers.tmux | 2 +- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/scripts/fingers.sh b/scripts/fingers.sh index 1d72379..b8bce00 100755 --- a/scripts/fingers.sh +++ b/scripts/fingers.sh @@ -1,5 +1,4 @@ #!/bin/bash -clear #TODO move this out of here! current_pane_id=$1 @@ -9,6 +8,11 @@ ALPHABET=asdfqwertjkluiop 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) +function clear_screen() { + clear + tmux clearhist +} + function get_hint() { echo ${HINTS[$1]} } @@ -17,6 +21,8 @@ function fancy() { printf "\033[1;33m$1\033[0m" } +clear_screen + PATTERNS= lines='' @@ -35,17 +41,16 @@ match_lookup='' OLDIFS=$IFS IFS=$(echo -en "\n\b") # wtf bash? for match in $matches ; do - echo "for match [$match]" hint=`get_hint $i` linenumber=`echo $match | cut -f1 -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" i=$(($i+1)) done IFS=$OLDIFS -echo -e "$output" +echo -ne "$output" function handle_exit() { tmux swap-pane -s $current_pane_id -t $fingers_pane_id @@ -55,7 +60,7 @@ function handle_exit() { trap "handle_exit" EXIT input='' -while read -n 1 char +while read -r -s -n1 char do input="$input$char" result=`echo -e $match_lookup | grep "^$input:" | cut -f2 -d:` @@ -64,7 +69,7 @@ do if [[ ! -z $result ]]; then clear - echo "$result" + echo -n "$result" tmux copy-mode tmux send-key "H" # top of buffer diff --git a/scripts/tmux-fingers.sh b/scripts/tmux-fingers.sh index f2902d5..049b603 100755 --- a/scripts/tmux-fingers.sh +++ b/scripts/tmux-fingers.sh @@ -11,27 +11,47 @@ function pane_exec() { } 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 } +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() { local current_pane_id=$1 local fingers_pane_id=`init_fingers_pane` local tmp_path=`mktemp --suffix "tmux-fingers"` 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" tmux swap-pane -s $current_pane_id -t $fingers_pane_id - #rm $tmp_path + ##rm $tmp_path 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` - diff --git a/tmux-fingers.tmux b/tmux-fingers.tmux index 9483463..d9212a7 100755 --- a/tmux-fingers.tmux +++ b/tmux-fingers.tmux @@ -1,4 +1,4 @@ #!/usr/bin/env bash 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"