aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/common
diff options
context:
space:
mode:
Diffstat (limited to 'dotfiles/common')
-rwxr-xr-xdotfiles/common/.local/bin/tmux-util36
1 files changed, 35 insertions, 1 deletions
diff --git a/dotfiles/common/.local/bin/tmux-util b/dotfiles/common/.local/bin/tmux-util
index 2fa861d..4a7b596 100755
--- a/dotfiles/common/.local/bin/tmux-util
+++ b/dotfiles/common/.local/bin/tmux-util
@@ -36,6 +36,37 @@ EOF
}
# -----------------------------------------------------------------------------
+# go
+# -----------------------------------------------------------------------------
+
+cmd_go() {
+ local name="${1:-}"
+ if [ -z "$name" ]; then
+ echo "tmux-util go: missing session name" >&2
+ echo "Usage: tmux-util go <name>" >&2
+ return 2
+ fi
+
+ # `=name` forces exact match in `tmux has-session` (otherwise tmux does
+ # prefix matching, which would let `go foo` attach to a session named
+ # `foobar`).
+ if tmux has-session -t "=$name" 2>/dev/null; then
+ if [ -n "${TMUX:-}" ]; then
+ tmux switch-client -t "$name"
+ else
+ tmux attach-session -t "$name"
+ fi
+ else
+ if [ -n "${TMUX:-}" ]; then
+ tmux new-session -d -s "$name" -c "$PWD"
+ tmux switch-client -t "$name"
+ else
+ tmux new-session -s "$name" -c "$PWD"
+ fi
+ fi
+}
+
+# -----------------------------------------------------------------------------
# ls
# -----------------------------------------------------------------------------
@@ -144,7 +175,10 @@ main() {
ls)
cmd_ls "$@"
;;
- go|pick|find|rename)
+ go)
+ cmd_go "$@"
+ ;;
+ pick|find|rename)
echo "tmux-util: subcommand '$sub' is not implemented yet" >&2
return 2
;;