Last active
November 10, 2024 20:33
-
-
Save JonnieCache/1e2fdc2f5737f640e150ea40da5b9d1d to your computer and use it in GitHub Desktop.
ZSH script to set the zellij tab title to the running command line, or the current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function current_dir() { | |
local current_dir=$PWD | |
if [[ $current_dir == $HOME ]]; then | |
current_dir="~" | |
else | |
current_dir=${current_dir##*/} | |
fi | |
echo $current_dir | |
} | |
function change_tab_title() { | |
local title=$1 | |
command nohup zellij action rename-tab $title >/dev/null 2>&1 | |
} | |
function set_tab_to_working_dir() { | |
local result=$? | |
local title=$(current_dir) | |
# uncomment the following to show the exit code after a failed command | |
# if [[ $result -gt 0 ]]; then | |
# title="$title [$result]" | |
# fi | |
change_tab_title $title | |
} | |
function set_tab_to_command_line() { | |
local cmdline=$1 | |
change_tab_title $cmdline | |
} | |
if [[ -n $ZELLIJ ]]; then | |
add-zsh-hook precmd set_tab_to_working_dir | |
add-zsh-hook preexec set_tab_to_command_line | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazing!!!