Last active
March 31, 2024 00:54
-
-
Save satmandu/0723e80ffcc79f60a3529df0da2d279a to your computer and use it in GitHub Desktop.
bash prompt with color, xterm title setting, and ssh host in title
This file contains hidden or 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
# Goes in .bashrc | |
# Heavily cribbed from | |
# https://stackoverflow.com/a/16715681 | |
# and inspired by | |
# https://unix.stackexchange.com/a/420090 | |
__prompt_command() { | |
local EXIT="$?" # This needs to be first | |
PS1="" | |
local RCol='\[\e[0m\]' | |
local Red='\[\e[0;31m\]' | |
local Gre='\[\e[0;32m\]' | |
local BYel='\[\e[1;33m\]' | |
local BBlu='\[\e[1;34m\]' | |
local Pur='\[\e[0;35m\]' | |
local termtitle='\e]2;\u@\h\a' | |
if [ $EXIT != 0 ]; then | |
PS1+="${Red}\u${RCol}" # Add red if exit code non 0 | |
else | |
PS1+="${Gre}\u${RCol}" | |
fi | |
PS1+="${RCol}@${BBlu}\h ${Pur}\w${BYel}$ ${RCol}" | |
PS1+="${termtitle}" | |
} | |
PROMPT_COMMAND=__prompt_command # Func to gen PS1 after CMDs | |
ssh() { | |
printf "\e]2;$*\a" | |
command ssh "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment