forked from Neo-Oli/tmux-text-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux-command-runner.sh
104 lines (89 loc) · 3.09 KB
/
tmux-command-runner.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /bin/bash
# this script write by @manesec.
tmux_macros_run_command(){
local read_funs=$1;
local read_value=$(echo $2 |base64 -d);
case $read_funs in
debug )
echo "[debug] $read_value"
;;
sleep )
echo "[sleep] $read_value"
for i in $(seq 1 $read_value); do
echo `expr $read_value - $i`
tmux rename-window -t $PANE "[$remain-`expr $read_value - $i + 1`s]"
sleep 1
done
;;
send-key )
echo "[send-key] $read_value"
tmux send-keys -t "$PANE" $read_value
;;
send-string )
echo "[send-string] $read_value"
tmux send-keys -t "$PANE" -l "" "$read_value"
;;
send-string-b64 )
echo "[send-string-b64] $read_value"
cmd_value=$(echo "$read_value" | base64 -d)
tmux send-keys -t "$PANE" -l "" "$cmd_value"
;;
run-command )
echo "[run-command] $read_value"
cmd_value=$(eval $read_value)
;;
run-command-b64 )
echo "[run-command-b64] $read_value"
cmd_value=$(echo "$read_value" | base64 -d)
cmd_value=$(eval $cmd_value)
;;
send-from-cmd )
echo "[send-from-cmd] $read_value"
cmd_value=$(eval $read_value)
tmux send-keys -t "$PANE" -l "" "$cmd_value"
;;
send-from-cmd-b64 )
echo "[send-from-cmd-b64] $read_value"
cmd_value=$(echo "$read_value" | base64 -d)
cmd_value=$(eval $cmd_value)
tmux send-keys -t "$PANE" -l "" "$cmd_value"
;;
esac
}
sh_loader(){
echo " ## Tmux Command Macros V0.1 ##"
echo " https://github.com/manesec/tmux-command-macros"
echo "-----------------------------------------------------------"
PANE=$1
selected=$(echo $2 | base64 -d)
env_file=$3
# load require into env if exist
echo "[env] Reading from env $env_file ..."
if [ -f $env_file ]; then
while read -r LINE; do
# Remove leading and trailing whitespaces, and carriage return
CLEANED_LINE=$(echo "$LINE" | awk '{$1=$1};1' | tr -d '\r')
if [[ $CLEANED_LINE != '#'* ]] && [[ $CLEANED_LINE == *'='* ]]; then
export "$CLEANED_LINE"
fi
done < $env_file
rm -f $env_file
fi
total=$(jq -c '.[]|.[]|=@base64' "$selected" | wc -l)
current=0
# send to run command
echo "[main] Time to start ..."
for line in $(jq -c '.[]| .[]|=@base64' "$selected") ; do
local read_funs=$(echo $line | jq -r 'keys[]')
local read_value=$(echo $line | jq -r '.[]')
# Calc process remain
current=$((current+1))
remain=`expr $total - $current`
tmux rename-window -t $PANE "$remain"
# Reading command
tmux_macros_run_command $read_funs $read_value;
done;
# back to auto rename
tmux set-option -t $PANE -w automatic-rename on
}
sh_loader $@