Skip to content

Instantly share code, notes, and snippets.

@AlvaroBrey
Last active April 13, 2018 16:09
Show Gist options
  • Save AlvaroBrey/68f4b912b96e68f54e6e4144cce6a289 to your computer and use it in GitHub Desktop.
Save AlvaroBrey/68f4b912b96e68f54e6e4144cce6a289 to your computer and use it in GitHub Desktop.
Guake tab auto renaming for Bash. Source in your .bashrc.
#!/usr/bin/env bash
function simpleDirName(){
# Echoes only the last folder of the current path, or ~ if we are at $HOME
if [ "$(pwd)" == "$HOME" ]
then
DN="~"
else
DN="${PWD##*/}";
fi
echo $DN;
}
function renameTab() {
NAMELEN=8
NAME=$(whoami)
TABNAME="${NAME:0:$NAMELEN}: $(simpleDirName)";
guake -r "$TABNAME";
}
function isGuake(){
CURRENT_EMU=$(basename "/"$(ps -f -p $(cat /proc/$(echo $$)/stat | cut -d \ -f 4) | tail -1 | sed 's/^.* //'))
if [ "$CURRENT_EMU" == "guake.main" ]
then
return 0;
else
return 1;
fi
}
if isGuake
then
export PROMPT_COMMAND="$PROMPT_COMMAND;renameTab"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment