From 3bf00c9f677cf1f362f611e2f7462f074bfef9c4 Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 22 Jul 2025 23:13:38 +0200 Subject: [PATCH] zsh, tmux, ssh --- .zsh/functions.d/s.sh | 25 +++++++++++++++++++++++++ .zshrc | 19 ++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 .zsh/functions.d/s.sh diff --git a/.zsh/functions.d/s.sh b/.zsh/functions.d/s.sh new file mode 100644 index 00000000..14a13030 --- /dev/null +++ b/.zsh/functions.d/s.sh @@ -0,0 +1,25 @@ +# SSH with automatic tmux window renaming +s() { + # Only rename tmux window if inside tmux + if [ -n "$TMUX" ]; then + local original_name + original_name=$(tmux display-message -p '#W') + + # Extract the host from arguments (first arg without user@ or port) + local ssh_host="$1" + ssh_host="${ssh_host#*@}" # remove user@ + ssh_host="${ssh_host%% *}" # trim after space + ssh_host="${ssh_host%%:*}" # remove port if given (e.g. user@host:2222) + + tmux rename-window "${ssh_host%%.*}" # short hostname + + # Run SSH session + command ssh "$@" + + # Restore previous tmux window name + tmux rename-window "$original_name" + else + command ssh "$@" + fi +} + diff --git a/.zshrc b/.zshrc index 60473f79..a20834ab 100644 --- a/.zshrc +++ b/.zshrc @@ -1,7 +1,7 @@ # Source some global/public stuff source ~/.env -# Source some private stuff +# Source some private stuff source ~/.penv # Java Stuff @@ -89,11 +89,6 @@ HISTFILE=~/.zsh_history # Load oh-my-zsh stuff source $ZSH/oh-my-zsh.sh -# Source some functions -for function in ~/.zsh/functions.d/*.sh; do - source $function -done - # Some aliases alias ..='cd ..' alias ...='cd ../..' @@ -134,17 +129,19 @@ case $TERM in ;; esac -if [ -f /usr/bin/shellpic ]; then +if [ -f /usr/bin/shellpic ]; then if [ -f ~/images/tux.png ]; then /usr/bin/shellpic --shell24 --scale-x 50 ~/images/tux.png fi fi -if [ -n "$TMUX" ]; then - printf '\033k%s\033\\' "$(hostname)" -fi - #source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. #[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh + +# Source some functions +for function in ~/.zsh/functions.d/*.sh; do + source $function +done +