This commit is contained in:
Johannes Findeisen 2025-07-23 01:25:04 +02:00
commit 712367eb98
4 changed files with 47 additions and 10 deletions

25
.zsh/functions.d/us.sh Normal file
View file

@ -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
}