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 | |
| parent | 36316dfd196111594a2a0c6c336bb771c9429a9a (diff) | |
tmux: avoid fish wrappers for popups
Task: z9
| -rwxr-xr-x | scripts/tmux-popup-attach | 57 | ||||
| -rwxr-xr-x | scripts/tmux-popup-new | 16 | ||||
| -rw-r--r-- | tmux/tmux.conf | 16 |
3 files changed, 81 insertions, 8 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" "$@" diff --git a/tmux/tmux.conf b/tmux/tmux.conf index 91fe998..6dd48af 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -17,15 +17,15 @@ bind-key J resize-pane -D 5 bind-key K resize-pane -U 5 bind-key L resize-pane -R 5 -bind-key g popup -E -w 99% -h 99% -d '#{pane_current_path}' "fish -c 'tmux new-session -A -s (basename (pwd))-tmp-lazygit lazygit'" -bind-key f popup -E -w 99% -h 99% -d '#{pane_current_path}' "fish -c 'tmux new-session -A -s (basename (pwd))-tmp-ranger ranger'" -bind-key e run-shell -b "cd '#{pane_current_path}' && hexai-tmux-edit --pane '#{pane_id}'" -bind-key N popup -E -w 99% -h 99% -d ~/Notes "fish -c 'tmux::attach notes'" -bind-key t popup -E -w 99% -h 99% -d '#{pane_current_path}' "fish -c 'tmux::attach (basename (pwd))-tmp-scratch'" -bind-key a popup -E -w 99% -h 99% -d '#{pane_current_path}' "fish -c 'tmux::attach adhoc'" +bind-key g popup -E -w 99% -h 99% -d '#{pane_current_path}' "tmux-popup-new #{q:pane_current_path} -tmp-lazygit lazygit" +bind-key f popup -E -w 99% -h 99% -d '#{pane_current_path}' "tmux-popup-new #{q:pane_current_path} -tmp-ranger ranger" +bind-key e run-shell -b "cd #{q:pane_current_path} && hexai-tmux-edit --pane '#{pane_id}'" +bind-key N popup -E -w 99% -h 99% -d ~/Notes "tmux-popup-attach notes ~/Notes" +bind-key t popup -E -w 99% -h 99% -d '#{pane_current_path}' "tmux-popup-attach --basename #{q:pane_current_path} -tmp-scratch" +bind-key a popup -E -w 99% -h 99% -d '#{pane_current_path}' "tmux-popup-attach adhoc #{q:pane_current_path}" bind-key H popup -E -w 99% -h 99% -d '#{pane_current_path}' "htop" -bind-key Q popup -E -w 99% -h 99% "fish -c 'tmux new-session -A -s quickedit quickedit'" -bind-key V popup -E -w 99% -h 99% "fish -c 'tmux new-session -A -s quickview quickview'" +bind-key Q popup -E -w 99% -h 99% "tmux new-session -A -s quickedit quickedit" +bind-key V popup -E -w 99% -h 99% "tmux new-session -A -s quickview quickview" # bind-key b break-pane -d bind-key c new-window -c '#{pane_current_path}' |
