aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-05-15 09:46:22 -0500
committerToby Vincent <tobyv13@gmail.com>2023-05-15 09:46:22 -0500
commit8cf91b5d97e626b2aa22b4829196a4128d859b69 (patch)
treed5c53434a791c1bc7923e54c4f5e9bf22542c17c
parentbf5d191c09e3544d41dcd46318c070c74ce91a12 (diff)
feat: add tmux script
-rwxr-xr-xbin/tmux-projectr27
1 files changed, 27 insertions, 0 deletions
diff --git a/bin/tmux-projectr b/bin/tmux-projectr
new file mode 100755
index 0000000..5dd89a1
--- /dev/null
+++ b/bin/tmux-projectr
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+if [ "$#" -eq 0 ]; then
+ GIT_PREVIEW='onefetch --include-hidden {}'
+ DIR_PREVIEW='tree -CL 3 --gitignore --noreport --filelimit=50 {}'
+ PREVIEW_CMD="($GIT_PREVIEW || $DIR_PREVIEW) 2>/dev/null"
+
+ # shellcheck disable=2046
+ set -- $(
+ projectr -mgt ~/dkr ~/pkg ~/src -P ~/.dotfiles --exclude-cwd |
+ fzf-tmux "$FZF_TMUX_OPTS" -- --tac --select-1 --exit-0 -d/ --with-nth -1 \
+ --bind 'focus:transform-header(echo {})' \
+ --preview-window='right,75%,<80(up,75%,border-bottom)' --preview="$PREVIEW_CMD"
+ )
+fi
+
+name=$(basename "$1" | tr . _)
+
+if ! tmux has-session -t="$name" 2>/dev/null; then
+ tmux new-session -ds "$name" -c "$1"
+fi
+
+if [ -z "$TMUX" ] && [ -z "$name" ]; then
+ tmux attach-session -t "$name"
+elif tmux has-session -t="$name" 2>/dev/null; then
+ tmux switch-client -t "$name"
+fi