|
-
- _show_last_exit_smilie() {
- # If the exit status of the last run command was a 0 (success), show a smile, otherwise a frown
- exit_status=$?
- if [[ "$exit_status" -ne 0 ]]; then
- echo "${NORMAL}[${RED}:(${NORMAL}]"
- else
- echo "${NORMAL}[${GREEN}:)${NORMAL}]"
- fi
- }
-
-
- # This function was modified from one found @ https://www.reddit.com/r/linux/comments/2uf5uu/this_is_my_bash_prompt_which_is_your_favorite/?st=jikgswh4&sh=371ba8bf
- _git_status() {
- local unknown untracked stash clean ahead behind staged dirty diverged
- unknown=$BLUE
- untracked=$GREEN
- stash=$GREEN
- clean=$GREEN
- ahead=$YELLOW
- behind=$YELLOW
- staged=$CYAN
- dirty=$RED
- diverged=$RED
-
-
- branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
- if [[ -n "$branch" ]]; then
- git_status=$(git status 2> /dev/null)
- # If nothing changes the color, we can spot unhandled cases.
- color=$unknown
- if [[ $git_status =~ 'Untracked files' ]]; then
- color=$untracked
- branch="${branch}?"
- fi
- if git stash show &>/dev/null; then
- color=$stash
- branch="${branch}+"
- fi
- if [[ $git_status =~ 'working directory clean' ]]; then
- color=$clean
- fi
- if [[ $git_status =~ 'Your branch is ahead' ]]; then
- color=$ahead
- branch="${branch}>"
- fi
- if [[ $git_status =~ 'Your branch is behind' ]]; then
- color=$behind
- branch="${branch}<"
- fi
- if [[ $git_status =~ 'Changes to be committed' ]]; then
- color=$staged
- fi
- if [[ $git_status =~ 'Changed but not updated' ||
- $git_status =~ 'Changes not staged' ||
- $git_status =~ 'Unmerged paths' ]]; then
- color=$dirty
- fi
- if [[ $git_status =~ 'Your branch'.+diverged ]]; then
- color=$diverged
- branch="${branch}!"
- fi
- echo -n "${NORMAL}|${color}${branch}${NORMAL}|"
- fi
- }
-
-
- set_prompt() {
- if [ $1 = yes ]; then
- echo -n "${debian_chroot:+($debian_chroot)}${GREEN}\u${NORMAL}[${BLUE}\w${NORMAL}]$(_show_last_exit_smilie)$(_git_status)\$ "
- else
- echo -n "${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
- fi
- }
|