-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmux-annotator.sh
executable file
·34 lines (30 loc) · 1.04 KB
/
tmux-annotator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# tmux-annotator
# This script runs a tmux session and binds the F4 key to
# annotate the current screen using "annotator" (in PATH)
# and pipes the result through "termlayout" (in PATH).
# Silas S. Brown 2014, 2015, 2019, 2022 - public domain - no warranty
if [ "$TMUX" ]; then
# tmux is not already running
exec tmux new-session '"'"$0"'"'" shell $*"
elif [ "$1" = annot ]; then
tmux last-window
tmux capture-pane
tmux last-window
clear ; echo Please wait... # hopefully not long
if [ -e /dev/shm ]; then TmpFile=$(mktemp /dev/shm/annotXXX)
else TmpFile=$(mktemp /tmp/annotXXX); fi
tmux save-buffer $TmpFile # can't put /dev/stdout here
tmux delete-buffer
sed -e 's/&/\&/g' -e 's/</\</g' -e 's/$/<br>/' < $TmpFile | annotator --ruby | termlayout | less -r
rm -f $TmpFile
else
tmux bind-key -n F4 new-window '"'"$0"'"'" annot"
echo "F4 = run annotator"
if [ "$1" = shell ]; then
shift
if [ ! "$1" ]; then
exec "$SHELL" || exec /bin/bash
else "$@"; fi
elif ! [ ! "$1" ]; then "$@"; fi
fi