diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-29 21:27:46 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-29 21:27:46 +0300 |
| commit | 32f4db67e999a831d59a0a193eba142e81fea999 (patch) | |
| tree | 5703a5e4d5252178220e65282002528bbc7d0abc /scripts | |
| parent | 36316dfd196111594a2a0c6c336bb771c9429a9a (diff) | |
tmux: avoid fish wrappers for popups
Task: z9
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/tmux-popup-attach | 57 | ||||
| -rwxr-xr-x | scripts/tmux-popup-new | 16 |
2 files changed, 73 insertions, 0 deletions
diff --git a/scripts/tmux-popup-attach b/scripts/tmux-popup-attach new file mode 100755 index 0000000..d295d52 --- /dev/null +++ b/scripts/tmux-popup-attach @@ -0,0 +1,57 @@ +#!/bin/sh + +set -eu + +if [ "$#" -lt 1 ] || [ "$#" -gt 3 ]; then + echo "usage: tmux-popup-attach SESSION [DIRECTORY]" >&2 + echo " tmux-popup-attach --basename DIRECTORY SESSION_SUFFIX" >&2 + exit 2 +fi + +if [ "$1" = "--basename" ]; then + if [ "$#" -ne 3 ]; then + echo "usage: tmux-popup-attach --basename DIRECTORY SESSION_SUFFIX" >&2 + exit 2 + fi + + directory=$2 + session=$(basename "$directory")$3 +else + if [ "$#" -gt 2 ]; then + echo "usage: tmux-popup-attach SESSION [DIRECTORY]" >&2 + exit 2 + fi + + session=$1 + directory=${2:-} +fi + +if [ -n "${TMUX:-}" ]; then + tmux switch-client -t "=$session" 2>/dev/null && exit 0 +else + tmux attach-session -t "=$session" 2>/dev/null && exit 0 +fi + +tmux list-sessions -F '#{session_name}:#{session_attached}' 2>/dev/null | + while IFS=: read -r name attached; do + case $name in + T*) + if [ "$attached" = 0 ]; then + echo "Killing $name" + tmux kill-session -t "=$name" || true + fi + ;; + esac + done + +if [ -n "$directory" ]; then + tmux new-session -d -s "$session" -c "$directory" 2>/dev/null || true +else + tmux new-session -d -s "$session" 2>/dev/null || true +fi + +if [ -n "${TMUX:-}" ]; then + exec tmux -2 switch-client -t "=$session" +fi + +exec tmux -2 attach-session -t "=$session" diff --git a/scripts/tmux-popup-new b/scripts/tmux-popup-new new file mode 100755 index 0000000..ebb1800 --- /dev/null +++ b/scripts/tmux-popup-new @@ -0,0 +1,16 @@ +#!/bin/sh + +set -eu + +if [ "$#" -lt 3 ]; then + echo "usage: tmux-popup-new DIRECTORY SESSION_SUFFIX COMMAND [ARG ...]" >&2 + exit 2 +fi + +directory=$1 +suffix=$2 +shift 2 + +session=$(basename "$directory")$suffix + +exec tmux new-session -A -s "$session" -c "$directory" "$@" |
