summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-01 09:53:44 +0200
committerPaul Buetow <paul@buetow.org>2026-03-01 09:53:44 +0200
commitc77463597e835bc1230c7e5103023a3624892505 (patch)
tree31571e674ad371e630450a6e65ce821217dfefc5
parentf8b513b3887fc4d594f06b76c1f10342d05edba1 (diff)
new
-rw-r--r--fish/conf.d/tmux.fish43
1 files changed, 43 insertions, 0 deletions
diff --git a/fish/conf.d/tmux.fish b/fish/conf.d/tmux.fish
index e65960e..87dc325 100644
--- a/fish/conf.d/tmux.fish
+++ b/fish/conf.d/tmux.fish
@@ -1,3 +1,5 @@
+set -gx TMUX_FZF_GIT_INDEX ~/git/.index
+
function _tmux::cleanup_default
tmux list-sessions | string match -r '^T.*: ' | string match -v -r attached | string split ':' | while read -l s
echo "Killing $s"
@@ -25,6 +27,46 @@ function tmux::new
end
end
+function tmux::git_project
+ set -l filter (test -n "$argv[1]"; and echo $argv[1]; or echo .)
+ set -l git_dir ~/git
+
+ set -l index_age 0
+ if test -f $TMUX_FZF_GIT_INDEX
+ if test (uname) = Darwin
+ set $TMUX_FZF_GIT_INDEX_age (math (date +%s) - (stat -f %m $TMUX_FZF_GIT_INDEX))
+ else
+ set $TMUX_FZF_GIT_INDEX_age (math (date +%s) - (stat -c %Y $TMUX_FZF_GIT_INDEX))
+ end
+ end
+ if test $index_age -gt 86400
+ rm $TMUX_FZF_GIT_INDEX
+ end
+
+ if not test -f $TMUX_FZF_GIT_INDEX
+ find $git_dir -maxdepth 4 -type d -name .git \
+ | sed 's|/.git$||' | sed "s|$git_dir/||" \
+ | grep -F -v . >$TMUX_FZF_GIT_INDEX
+ end
+
+ set -l matches (grep "$filter" $TMUX_FZF_GIT_INDEX)
+ set -l session
+ if test (count $matches) -eq 1
+ set session $matches[1]
+ else
+ set session (printf "%s\n" $matches | fzf)
+ end
+ echo cd $git_dir/$session
+ echo tmux::attach $session
+end
+
+function tmux::git_project::reindex
+ if test -f $TMUX_FZF_GIT_INDEX
+ rm $TMUX_FZF_GIT_INDEX
+ end
+ tmux::git_project $argv
+end
+
function tmux::attach
set -l session $argv[1]
if test -z "$session"
@@ -89,6 +131,7 @@ alias ts 'tmux::search'
alias tssh 'tmux::cluster_ssh'
alias tm tmux
alias tl 'tmux list-sessions'
+alias tp 'tmux::git_project'
alias foo 'tmux::new foo'
alias bar 'tmux::new bar'
alias baz 'tmux::new baz'