summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/extra/tmux-sessionizer53
1 files changed, 33 insertions, 20 deletions
diff --git a/bin/extra/tmux-sessionizer b/bin/extra/tmux-sessionizer
index 34958e5..0404b6a 100755
--- a/bin/extra/tmux-sessionizer
+++ b/bin/extra/tmux-sessionizer
@@ -1,33 +1,46 @@
#!/bin/sh
+# Path to your projects directory
+Prefix="$HOME/proj"
+# Paths in which to search for projects
+Paths="$Prefix $Prefix/handmade"
+
if [ $# -eq 1 ]; then
- selected="$1"
+ Selected="$1"
else
- pfx="$HOME/proj"
-
- selected="$(find "$pfx" $pfx/handmade \
- -mindepth 1 -maxdepth 1 \( -path "$pfx/handmade/*" -o -path "$pfx/*" \) -a -type d -a \( -not -path "$pfx/handmade" \) |
- sed "s@$pfx/@@" | fzf)"
- { [ "$selected" ] && [ -d "$pfx/$selected" ]; } || exit 1
-fi
+ # Exclude the search paths themselves
+ Args="$(
+ for Path in $Paths
+ do
+ printf -- "%s\n" "-a ( -not -path "$Path" ) "
+ done
+ )"
-if [ -z "$selected" ]; then
- exit 0
-fi
+ Selected="$(find $Paths -mindepth 1 -maxdepth 1 -type d $Args | sed "s@$Prefix/@@" | fzf)"
-tmux_running="$(pgrep "tmux" | head -n1)"
+ { [ "$Selected" ] && [ -d "$Prefix/$Selected" ]; } || exit 1
+fi
-if [ -z $TMUX ] && [ -z "$tmux_running" ]; then
- tmux new-session -s "$selected" -c "$pfx"/"$selected"
+if [ -z "$Selected" ]; then
exit 0
fi
-if ! tmux has-session -t="$selected" 2> /dev/null; then
- tmux new-session -ds "$selected" -c "$pfx"/"$selected"
-fi
+TmuxRunning="$(pgrep "tmux" | head -n1)"
+Session="${Selected##*/}"
-if [ -z $TMUX ]; then
- tmux attach -t "$selected"
+if [ -z $TMUX ] && [ -z "$TmuxRunning" ]; then
+ tmux new-session -s "$Session" -c "$Prefix"/"$Selected"
+ herbe 1
else
- tmux switch-client -t "$selected"
+
+ if ! tmux has-session -t="$Session" 2> /dev/null; then
+ tmux new-session -ds "$Session" -c "$Prefix"/"$Selected"
+ fi
+
+ if [ -z $TMUX ]; then
+ tmux attach -t "$Session"
+ else
+ tmux switch-client -t "$Session"
+ fi
+
fi