aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/common
diff options
context:
space:
mode:
Diffstat (limited to 'dotfiles/common')
-rwxr-xr-xdotfiles/common/.local/bin/tmux-util50
1 files changed, 48 insertions, 2 deletions
diff --git a/dotfiles/common/.local/bin/tmux-util b/dotfiles/common/.local/bin/tmux-util
index 4669b03..dca01fd 100755
--- a/dotfiles/common/.local/bin/tmux-util
+++ b/dotfiles/common/.local/bin/tmux-util
@@ -36,6 +36,53 @@ EOF
}
# -----------------------------------------------------------------------------
+# rename
+# -----------------------------------------------------------------------------
+
+cmd_rename() {
+ local sessions
+ sessions=$(tmux list-sessions \
+ -F '#{session_attached} #{session_name}' 2>/dev/null || true)
+ if [ -z "$sessions" ]; then
+ echo "No tmux sessions to rename."
+ return 0
+ fi
+
+ local choice
+ choice=$(echo "$sessions" | awk '{
+ state = ($1 == "1") ? "attached" : "detached"
+ printf "%-9s %s\n", state, $2
+ }' | fzf --header="Pick a session to rename" | awk '{print $2}')
+
+ if [ -z "$choice" ]; then
+ # User cancelled.
+ return 0
+ fi
+
+ local new_name
+ printf 'New name for "%s": ' "$choice"
+ read -r new_name
+
+ if [ -z "$new_name" ]; then
+ echo "tmux-util rename: empty new name, cancelled." >&2
+ return 1
+ fi
+
+ if [ "$new_name" = "$choice" ]; then
+ echo "tmux-util rename: new name same as old, no change."
+ return 0
+ fi
+
+ if tmux has-session -t "=$new_name" 2>/dev/null; then
+ echo "tmux-util rename: a session named '$new_name' already exists." >&2
+ return 1
+ fi
+
+ tmux rename-session -t "$choice" "$new_name"
+ echo "Renamed: $choice -> $new_name"
+}
+
+# -----------------------------------------------------------------------------
# pick
# -----------------------------------------------------------------------------
@@ -242,8 +289,7 @@ main() {
cmd_pick "$@"
;;
rename)
- echo "tmux-util: subcommand '$sub' is not implemented yet" >&2
- return 2
+ cmd_rename "$@"
;;
*)
echo "tmux-util: unknown subcommand: $sub" >&2