summaryrefslogtreecommitdiff
path: root/fish
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-26 10:25:26 +0200
committerPaul Buetow <paul@buetow.org>2026-03-26 10:25:26 +0200
commit54b79b4ff4e607a914f48a42cd7b76037e23667e (patch)
tree8b000be707d7d31d9023b329313553e1854b012a /fish
parent0f09137e4ff442ee78fb8c95c2539c7f1026c824 (diff)
improve tmux session/project attach logic, support directory argument
Diffstat (limited to 'fish')
-rw-r--r--fish/conf.d/tmux.fish33
1 files changed, 26 insertions, 7 deletions
diff --git a/fish/conf.d/tmux.fish b/fish/conf.d/tmux.fish
index 707bd24..84cc6c3 100644
--- a/fish/conf.d/tmux.fish
+++ b/fish/conf.d/tmux.fish
@@ -16,20 +16,30 @@ end
function tmux::new
set -l session $argv[1]
+ set -l dir $argv[2]
_tmux::cleanup_default
if test -z "$session"
tmux::new (string join "" T (date +%s))
else
- tmux new-session -d -s $session
- tmux -2 attach-session -t $session || tmux -2 switch-client -t $session
+ set -l new_session_args -d -s $session
+ if test -n "$dir"
+ set new_session_args $new_session_args -c $dir
+ end
+ tmux new-session $new_session_args
+ if test -n "$TMUX"
+ tmux -2 switch-client -t "=$session"
+ else
+ tmux -2 attach-session -t "=$session"
+ end
end
end
function tmux::project
if test (count $argv) -eq 0
- set -l git_root (basename (git rev-parse --show-toplevel 2>/dev/null))
+ set -l git_root (git rev-parse --show-toplevel 2>/dev/null)
if test -n "$git_root"
- tmux::attach (basename $git_root)
+ set -l session_name (basename $git_root | string replace -a '.' '_')
+ tmux::attach $session_name $git_root
return
end
echo "tp: no argument given and not in a git repo"
@@ -42,16 +52,25 @@ function tmux::project
return 1
end
- cd $dir
- tmux::attach (basename $dir)
+ set -l session_name (basename $dir | string replace -a '.' '_')
+ tmux::attach $session_name $dir
end
function tmux::attach
set -l session $argv[1]
+ set -l dir $argv[2]
if test -z "$session"
+ if test -n "$TMUX"
+ echo "ta: no session name given and already inside tmux"
+ return 1
+ end
tmux attach-session || tmux::new
else
- tmux attach-session -t $session || tmux::new $session
+ if test -n "$TMUX"
+ tmux switch-client -t "=$session" 2>/dev/null; or tmux::new $session $dir
+ else
+ tmux attach-session -t "=$session" 2>/dev/null; or tmux::new $session $dir
+ end
end
end