diff --git a/.env b/.env index 9b689fc8..887dc4b7 100644 --- a/.env +++ b/.env @@ -3,10 +3,15 @@ # Example: can be shell compatible stuff like export, alias etc. or just # define variables like FOO=BAR # -# You should put private stuff to .penv. It is handled the same way as this +# You should put private stuff to .penv. It is handled the same way as this # file but will be ignored by .gitignore. # +# History settings +HISTSIZE=100000 +SAVEHIST=100000 +HISTFILE=~/.zsh_history + # Extend the $PATH to $HOME/bin and more. #export PATH=$HOME/bin:$HOME/.local/bin/:$HOME/.gem/ruby/3.4.0/bin:$HOME/.android/sdk/platform-tools:$HOME/.cargo/bin:$PATH diff --git a/.tmux.conf b/.tmux.conf index 8576a136..0cc6f503 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -1,11 +1,11 @@ -# Original Source: https://github.com/jonasjacek/ - # Set prefix key unbind-key C-b bind y send-prefix set -g prefix ^y # CONFIGURATION +set -g automatic-rename on +set -g set-titles on set-option -g history-limit 10000 # DESIGN: 256 COLOR SUPPORT diff --git a/.zsh/functions.d/us.sh b/.zsh/functions.d/us.sh new file mode 100644 index 00000000..a64709c9 --- /dev/null +++ b/.zsh/functions.d/us.sh @@ -0,0 +1,25 @@ +us() { + if [ -n "$TMUX" ]; then + local original_name + original_name=$(tmux display-message -p '#W') + + # Determine the target username + local target_user="root" + local arg1="$1" + if [[ "$arg1" != "-" && -n "$arg1" ]]; then + target_user="$arg1" + fi + + # Rename the window before running su + tmux rename-window "su-${target_user}" + + # Use "command su" to bypass the function if it exists + command su "$@" + + # Restore original window name after exit + tmux rename-window "$original_name" + else + command su "$@" + fi +} + diff --git a/.zshrc b/.zshrc index 65f956ca..537ab8e7 100644 --- a/.zshrc +++ b/.zshrc @@ -1,8 +1,3 @@ -# History settings -HISTSIZE=100000 -SAVEHIST=100000 -HISTFILE=~/.zsh_history - # Source some global/public stuff source ~/.env @@ -17,7 +12,7 @@ source ~/.zsh/oh-my-zsh.sh # I use xterm and this sets a nice title with hostname and cwd in it. case $TERM in - linux) + linux*) export TERM=linux precmd () {print -Pn "\e]0;%n@%m: %~\a"} ;; @@ -25,7 +20,7 @@ case $TERM in export TERM=xterm-256color precmd () {print -Pn "\e]0;%n@%m: %~\a"} ;; - screen) + screen*) export TERM=screen-256color precmd () {print -Pn "\e]0;%n@%m: %~\a"} ;; @@ -48,3 +43,15 @@ for function in ~/.zsh/functions.d/*.sh; do source $function done +# Update tmux window title to the current running command +# In root's .zshrc (or any su-target user) +if [ -n "$TMUX" ]; then + function preexec() { + local cmd=${1[(wr)^(*=*|sudo|su|command)]} + print -Pn "\e]2;${cmd%% *}\a" + } + function precmd() { + print -Pn "\e]2;zsh\a" + } +fi +