Skip to content

Instantly share code, notes, and snippets.

@rybak
Last active February 22, 2022 04:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rybak/dea01adcd9cc500324f72639df93855d to your computer and use it in GitHub Desktop.
Save rybak/dea01adcd9cc500324f72639df93855d to your computer and use it in GitHub Desktop.
PS1 setup with sad smiley for process failure and dangerous bend symbol for README files
#!/bin/bash
# Cleaned up version of ps1_notifications.sh made on 2018-08-05
#
# See rybak/scriptps github repository for the full version
# link: https://github.com/rybak/scripts/blob/master/config/ps1_notifications.sh
# copy of lib/colors.sh instead of calling source "$HOME/scripts/lib/colors.sh"
BLACK_FG="$(tput setaf 0)"
RED_FG="$(tput setaf 1)"
GREEN_FG="$(tput setaf 2)"
YELLOW_FG="$(tput setaf 3)"
BLUE_FG="$(tput setaf 4)"
MAGENTA_FG="$(tput setaf 5)"
CYAN_FG="$(tput setaf 6)"
WHITE_FG="$(tput setaf 7)"
BLACK="$BLACK_FG"
RED="$RED_FG"
GREEN="$GREEN_FG"
YELLOW="$YELLOW_FG"
BLUE="$BLUE_FG"
MAGENTA="$MAGENTA_FG"
CYAN="$CYAN_FG"
WHITE="$WHITE_FG"
RESET_FONT="\e[0m"
BRIGHT_FG="\e[1m"
DIM_FG="\e[2m"
HIGHLIGHT_FONT="\e[4m"
PS_RESET_FONT='\[\e[0m\]'
function ps1_reset_font() {
PS1="$PS1${PS_RESET_FONT}"
}
# /colors.sh
__TOP_BRACKET="\[\e[2m\]┌─"
__BOTTOM_BRACKET="\\[\\e[2m\\]└─"
# set up simple PS1
PS1=
ps1_reset_font
USERNAME_FONT='\033[0;33;93m'
HOSTNAME_FONT='\033[0;32m'
PS1="$__BRACKET_COLOR${__TOP_BRACKET}$PS1\[$USERNAME_FONT\]"'\u' # user
PS1="$PS1\[$WHITE\]"'@' # @
PS1="$PS1\[$HOSTNAME_FONT\]"'\h' # host
ps1_reset_font
PS1="${PS1}\[\033[01;34m\]" # change to directory color
PS1="$PS1"'\w' # current working directory
ps1_reset_font
__README_COLOR="$DIM_FG$MAGENTA_FG"
case "$TERM" in
xterm*|rxvt* )
__SMILEY='☹ '
__README_SYMBOL='☡'
;;
* )
__SMILEY='('
__README_SYMBOL='z'
;;
esac
function __custom_ps1() {
local EXIT=$?
local PREF="$1"
local POST="$2"
local SADNESS=
local NOTIFY=
local POST_RESET=
if [[ "$EXIT" != '0' ]]
then
SADNESS="$__SMILEY"
fi
if [[ -n $(find -maxdepth 1 -iname '*README*' 2>/dev/null) ]]
then
NOTIFY='\['$__README_COLOR'\]'"$__README_SYMBOL$PS_RESET_FONT"
POST_RESET="$PS_RESET_FONT"
fi
local GIT_POST="${NOTIFY}\n${SADNESS}${POST}${POST_RESET}"
__git_ps1 "$PREF" "$GIT_POST"
}
PROMPT_COMMAND="__custom_ps1 '$PS1' '$__BOTTOM_BRACKET$PS_RESET_FONT\\\$ '"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment