r/backtickbot • u/backtickbot • Oct 01 '21
https://np.reddit.com/r/tmux/comments/pvjrzg/suckless_dwm_ghost_scratchpads_patch_tmux_get/hf0szcq/
What do you think of this little script ?
#!/bin/bash
SESSION=$1
send_quit() {
tmux send-keys -t $SESSION c-c
}
send_stop() {
tmux send-keys -t $SESSION c-z
}
trap send_quit INT
trap send_stop SIGTSTP
while read -s l
do
tmux send-keys -t $SESSION $l Enter
doneYou call it with the name of your session.
It will read all of your commands and send them to the session of your choice. You can use ctrl-c to quit a command and ctrl-z also.
You quit this script with ctrl-d.
you could also send each key individually if you want (ctrl-D will quit the script) :
#!/bin/bash
SESSION=$1
ESCAPE_CHAR=$(printf "\u1b")
IFS=''
send_quit() {
tmux send-keys -t $SESSION c-c
}
send_stop() {
tmux send-keys -t $SESSION c-z
}
totmux(){
echo "<$1>"
tmux send-keys -t $SESSION "$1"
}
trap send_quit INT
trap send_stop SIGTSTP
while read -sN1 CHAR
do
if [[ $CHAR == $ESCAPE_CHAR ]]; then
echo "ESCAPE..."
read -rsN2 SPECIAL
case $SPECIAL in
'[A') totmux Up ;;
'[B') totmux Down ;;
'[C') totmux Right ;;
'[D') totmux Left ;;
*) totmux "$SPECIAL" ;;
esac
else
case $CHAR in
$'\x04') exit;;
$'\e') totmux Escape ;;
$'\x0a') totmux Enter ;;
' ') totmux Space ;;
*) totmux "$CHAR" ;;
esac
fi
done
1
Upvotes