Created
February 17, 2016 01:04
-
-
Save lholden/e0f0d26ad38cb5c73c8a to your computer and use it in GitHub Desktop.
MSys2 bash prompt
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
declare MAX_PATH_LENGTH=40 | |
declare COLOR_PATH="\[\e[34;1m\]" | |
declare COLOR_EXTRAS="\[\e[35m\]" | |
declare COLOR_MSYSTEM="\[\e[1;31;40m\]" | |
declare COLOR_HOST="" | |
declare COLOR_RESET="\[\e[0m\]" | |
function prompt_path { | |
local path="$1" | |
local prefix | |
[[ "$path" =~ (~) ]] && prefix="~/" | |
if (( ${#path} > $MAX_PATH_LENGTH )); then | |
path=${path: -$(($MAX_PATH_LENGTH - ${#prefix}))} | |
[[ "$path" =~ ^[^/]*/(.*) ]] && path="$prefix(...)${BASH_REMATCH[1]}" | |
fi | |
echo $path | |
} | |
function prompt_jobs { | |
local num_jobs=$1 | |
local jobs_str | |
case $num_jobs in | |
(0) return ;; | |
(1) jobs_str="job";; | |
(*) jobs_str="jobs";; | |
esac | |
echo " [$num_jobs $jobs_str]" | |
} | |
function prompt_msystem { | |
case $MSYSTEM in | |
(MINGW64) return ;; | |
esac | |
echo " [${MSYSTEM}]" | |
} | |
PROMPT_COMMAND='echo -ne "\033]2;${USER}@${HOSTNAME}\007"' | |
PS1="${COLOR_RESET}( \u@${COLOR_HOST}\h${COLOR_RESET}:${COLOR_PATH}\$(prompt_path '\w')${COLOR_RESET}${COLOR_EXTRAS}\$(prompt_jobs \j)\$(prompt_msystem)${COLOR_RESET} )"$'\n\$ ' | |
unset COLOR_PATH COLOR_EXTRAS COLOR_USER COLOR_ROOT COLOR_HOST COLOR_RESET color_by_id | |
# vim: set filetype=sh : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment