tmux: gnome-style app-shortcuts for switching panes

This commit is contained in:
Daniel Lundin 2024-04-05 20:30:39 +02:00
parent 0afb5698dd
commit 7ad9868c20
No known key found for this signature in database
3 changed files with 54 additions and 41 deletions

20
bin/tmux-shortcut Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eo pipefail
nr="@app-${1}"
shift
pane="$(tmux show -vg ${nr} || true)"
if [[ -n "${pane}" ]] && tmux has-session -t "${pane}" ; then
if tmux list-panes -F "#{pane_id}" | grep "^${pane}\$" >>/dev/null ; then
# Pane is on this window. Focus it and exit.
exec tmux select-pane -t "${pane}"
fi
else
# App pane does not exist, so create a new window.
pane=$(tmux new-window -d -P -F '#{pane_id}' "$@")
tmux set -g "${nr}" "${pane}"
fi
# Swap active pane for app
tmux swap-pane -s "${pane}"