1
0
mirror of https://github.com/Morantron/tmux-fingers.git synced 2024-07-01 08:10:57 +02:00
tmux-fingers/scripts/tmux-fingers.sh

51 lines
1.6 KiB
Bash
Raw Normal View History

2016-05-02 21:15:29 +02:00
#!/usr/bin/env bash
2016-04-24 01:36:09 +02:00
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2016-04-30 02:42:56 +02:00
source $CURRENT_DIR/utils.sh
2016-04-24 01:36:09 +02:00
function init_fingers_pane() {
2017-02-14 08:29:42 +01:00
local pane_id=$(tmux new-window -F "#{pane_id}" -P -d -n "[fingers]" "$(init_pane_cmd)")
2016-04-24 01:36:09 +02:00
echo $pane_id
}
2016-04-28 22:27:40 +02:00
function capture_pane() {
local pane_id=$1
local out_path=$2
2016-05-02 21:15:29 +02:00
local pane_info=$(tmux list-panes -s -F "#{pane_id}:#{pane_height}:#{scroll_position}:#{?pane_in_mode,1,0}" | grep "^$pane_id")
2016-04-28 22:27:40 +02:00
2016-05-02 21:15:29 +02:00
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)
2016-04-28 22:27:40 +02:00
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
2016-07-14 22:47:16 +02:00
tmux capture-pane -J -p -t $pane_id -E $end_capture -S $start_capture > $out_path
2016-04-28 22:27:40 +02:00
}
2016-04-24 01:36:09 +02:00
function prompt_fingers_for_pane() {
local current_pane_id=$1
2016-05-02 21:15:29 +02:00
local fingers_pane_id=$(init_fingers_pane)
local tmp_path=$(fingers_tmp)
2016-04-26 21:44:18 +02:00
wait
2016-04-24 01:36:09 +02:00
2016-04-28 22:27:40 +02:00
capture_pane "$current_pane_id" "$tmp_path"
local original_rename_setting=$(tmux show-window-option -gv automatic-rename)
tmux set-window-option automatic-rename off
pane_exec "$fingers_pane_id" "cat $tmp_path | $CURRENT_DIR/fingers.sh \"$current_pane_id\" \"$fingers_pane_id\" $tmp_path $original_rename_setting"
2016-04-24 01:36:09 +02:00
2016-04-26 21:44:18 +02:00
echo $fingers_pane_id
2016-04-24 01:36:09 +02:00
}
2016-05-02 21:15:29 +02:00
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)