From 7c544827461b51f2ec44abb662bdc865191f15e7 Mon Sep 17 00:00:00 2001 From: Sarthak Jain Date: Sat, 18 Jul 2026 14:50:14 +0530 Subject: [PATCH] feat(tmux): auto-name sessions with emoji + codename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scripts/tmux-session-name.sh: generates random emoji + adj-noun name 40 emojis x 40 adjectives x 40 nouns = 64,000 combinations Only renames numerically-named sessions (skips explicit names) - tmux.conf.local: session-created hook calls the script automatically - shell/common: added DOTFILES=$HOME/dotfiles env var so hooks and scripts can find the dotfiles root without hardcoded paths Examples: '🐉 sonic-oracle', '🌟 electric-nebula', '🔱 nova-comet' --- scripts/tmux-session-name.sh | 55 ++++++++++++++++++++++++++++++++++++ shell/.config/shell/common | 3 ++ tmux/.tmux.conf.local | 6 ++++ 3 files changed, 64 insertions(+) create mode 100755 scripts/tmux-session-name.sh diff --git a/scripts/tmux-session-name.sh b/scripts/tmux-session-name.sh new file mode 100755 index 0000000..af18432 --- /dev/null +++ b/scripts/tmux-session-name.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# tmux-session-name.sh — Auto-name new tmux sessions with emoji + codename +# +# Called by the session-created hook in .tmux.conf.local +# Usage: tmux-session-name.sh +# +# Only renames if the current name is purely numeric (tmux's default +# auto-numbering: 0, 1, 2 …). Explicitly named sessions are left alone. + +CURRENT_NAME="${1:-}" +SESSION_ID="${2:-}" + +# Skip if name is not a plain number (user explicitly named the session) +if [[ ! "$CURRENT_NAME" =~ ^[0-9]+$ ]]; then + exit 0 +fi + +# ── Name pool ───────────────────────────────────────────────────────────────── + +EMOJIS=( + "⚡" "🔥" "🌙" "🚀" "🎯" "💎" "🌊" "🎸" "🦊" "🐉" + "🌟" "🎭" "🔮" "🦋" "🌸" "🏔️" "🎪" "🦁" "🐺" "🦅" + "🐬" "🌋" "⚗️" "🧠" "🔭" "🎲" "🏹" "🌀" "🦄" "🐙" + "🎮" "🛸" "🌈" "🔱" "⚜️" "🧬" "🦾" "💫" "🎆" "🌌" +) + +ADJECTIVES=( + swift blazing cosmic silent wild golden dark frozen epic neon + cyber ghost storm iron crystal hyper zen rogue nova apex + void shadow turbo lunar sonic electric primal ancient savage brave + mystic toxic ultra prime omega alpha delta sigma raging burning +) + +NOUNS=( + wolf phoenix raven otter falcon dragon viper lynx shark cobra + titan spectre nexus cipher forge matrix pulse blade hawk panther + manta kraken hydra mantis raptor condor jaguar orca wraith banshee + golem oracle anvil tempest quasar nebula comet prism zenith apex +) + +# ── Pick random combination ─────────────────────────────────────────────────── + +EMOJI="${EMOJIS[$RANDOM % ${#EMOJIS[@]}]}" +ADJ="${ADJECTIVES[$RANDOM % ${#ADJECTIVES[@]}]}" +NOUN="${NOUNS[$RANDOM % ${#NOUNS[@]}]}" +NEW_NAME="${EMOJI} ${ADJ}-${NOUN}" + +# ── Rename ──────────────────────────────────────────────────────────────────── + +if [[ -n "$SESSION_ID" ]]; then + tmux rename-session -t "$SESSION_ID" "$NEW_NAME" 2>/dev/null +else + # Called standalone — just print the name + echo "$NEW_NAME" +fi diff --git a/shell/.config/shell/common b/shell/.config/shell/common index 353123c..824a356 100644 --- a/shell/.config/shell/common +++ b/shell/.config/shell/common @@ -5,6 +5,9 @@ export EDITOR='nvim' export VISUAL='nvim' +# Dotfiles root — used by scripts and tmux hooks +export DOTFILES="$HOME/dotfiles" + # Man page rendering export MANROFFOPT="-c" diff --git a/tmux/.tmux.conf.local b/tmux/.tmux.conf.local index 1ea9fd6..17ac268 100644 --- a/tmux/.tmux.conf.local +++ b/tmux/.tmux.conf.local @@ -366,6 +366,12 @@ source-file "/Users/jsarthak/dotfiles/tmux/config/keybindings.conf" setw -g window-status-separator " #[fg=#484848]• " #!important +# ── Auto-name sessions (emoji + codename) ───────────────────────────────────── +# Fires on every new session. Skips sessions the user explicitly named. +# Script lives in ~/dotfiles/scripts/tmux-session-name.sh +set-hook -g session-created \ + 'run-shell "bash $HOME/dotfiles/scripts/tmux-session-name.sh \"#{session_name}\" \"#{session_id}\""' + # ── Mode indicator (always-on, Neovim-style) ────────────────────────────────── # NORMAL = working in tmux (default, always visible) # VISUAL = in copy-mode (prefix + Enter)