Last active
July 18, 2018 23:18
-
-
Save possatti/dc18149d7a6f7892516f83b19586d78d to your computer and use it in GitHub Desktop.
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
# Palette: http://colorpalettes.net/color-palette-3697/ | |
# Brown: #4f231c rgb(79,35,28) | |
# Dark red: #88011d rgb(136,1,29) | |
# Light red: #da002b rgb(218,0,43) | |
# Blueish: #8ed2df rgb(142,210,223) | |
# Kinda white: #f2efdf rgb(242,239,223) | |
# Alternative pallete: http://colorpalettes.net/tag/the-color-of-cherry/ | |
# Green 1: #7e9b0d rgb(126,155,13) | |
# Green 2: #baaf07 rgb(186,175,7) | |
rgb() { | |
# $1: BG=0, FG=1 | |
if [ "$1" -eq "0" ]; then | |
echo "\033[48;2;${2};${3};${4}m" | |
else | |
echo "\033[38;2;${2};${3};${4}m" | |
fi | |
} | |
frgb() { | |
# FG then BG. | |
echo "\033[38;2;${1};${2};${3};48;2;${4};${5};${6}m" | |
} | |
FALLBACK_PS1="$PS1" | |
cherry_prompt() { | |
# Run `man strftime` to see how to specify the date-time format. | |
local EXIT_CODE="$?" | |
local BOLD="\033[1m" | |
local RESET="\033[0m" | |
## One line. | |
# CHERRY_PS1="" | |
# CHERRY_PS1+="\[$(frgb 242 239 223 136 1 29)\]$(date '+%-m月%-d日')" | |
# CHERRY_PS1+="\[$(frgb 242 239 223 218 0 43)\]$(date '+%-H時%-M分')" | |
# CHERRY_PS1+="\[$(rgb 0 242 239 223)$(rgb 1 79 35 28)\] \u \[$(rgb 1 218 0 43)\]at \[$(rgb 1 79 35 28)\]\H \[$(rgb 1 218 0 43)\]in \[$(rgb 1 79 35 28)\]\W \[$(rgb 1 218 0 43)$BOLD\]\$\[$RESET\] " | |
# # CHERRY_PS1+="\[$(rgb 0 242 239 223)$(rgb 1 79 35 28)\] \u\[$(rgb 1 218 0 43)\]@\[$(rgb 1 79 35 28)\]\H\[$(rgb 1 218 0 43)\]:\[$(rgb 1 79 35 28)\]\W \[$(rgb 1 218 0 43)$BOLD\]\$\[$RESET\] " | |
## Multiline. | |
# CHERRY_PS1="\n" | |
# CHERRY_PS1+="\[$(frgb 242 239 223 136 1 29)\]$(date '+%Y年%-m月%-d日')" | |
# CHERRY_PS1+="\[$(frgb 242 239 223 218 0 43)\]$(date '+%-H時%-M分')\[$RESET\]\n" | |
# CHERRY_PS1+="\[$(rgb 0 242 239 223)$(rgb 1 79 35 28)\]\u \[$(rgb 1 218 0 43)\]at \[$(rgb 1 79 35 28)\]\H \[$(rgb 1 218 0 43)\]in \[$(rgb 1 79 35 28)\]\W " | |
# if [ -n "$VIRTUAL_ENV" ]; then | |
# ENV_NAME=$(basename $VIRTUAL_ENV) | |
# CHERRY_PS1+="\[$(rgb 1 126 155 13)\]($ENV_NAME) " | |
# fi | |
# if [ "$EXIT_CODE" != 0 ]; then | |
# CHERRY_PS1+="\[$(rgb 1 126 155 13)\](error $EXIT_CODE) " | |
# fi | |
# CHERRY_PS1+="\[$(rgb 1 218 0 43)$BOLD\]\$\[$RESET\] " | |
## Full width. | |
DARK_RED="\[$(frgb 242 239 223 136 1 29)\]" | |
LIGHT_RED="\[$(frgb 242 239 223 218 0 43)\]" | |
JTIME=$(date '+%Y_%-m_%-d_%-H_%-M' | perl -Mutf8 -CS -pe 'tr/0123456789/0123456789/') | |
YEAR=$(echo $JTIME | cut -d_ -f1) | |
MONTH=$(echo $JTIME | cut -d_ -f2) | |
DAY=$(echo $JTIME | cut -d_ -f3) | |
HOUR=$(echo $JTIME | cut -d_ -f4) | |
MINUTE=$(echo $JTIME | cut -d_ -f5) | |
CHERRY_PS1="\n" | |
CHERRY_PS1+="$DARK_RED${YEAR}年${MONTH}月${DAY}日" | |
CHERRY_PS1+="$LIGHT_RED${HOUR}時${MINUTE}分\[$RESET\]\n" | |
CHERRY_PS1+="\[$(rgb 0 242 239 223)$(rgb 1 79 35 28)\]\u \[$(rgb 1 218 0 43)\]at \[$(rgb 1 79 35 28)\]\H \[$(rgb 1 218 0 43)\]in \[$(rgb 1 79 35 28)\]\W " | |
if [ -n "$VIRTUAL_ENV" ]; then | |
ENV_NAME=$(basename $VIRTUAL_ENV) | |
CHERRY_PS1+="\[$(rgb 1 126 155 13)\]($ENV_NAME) " | |
fi | |
if [ "$EXIT_CODE" != 0 ]; then | |
CHERRY_PS1+="\[$(rgb 1 126 155 13)\](error $EXIT_CODE) " | |
fi | |
CHERRY_PS1+="\[$(rgb 1 218 0 43)$BOLD\]\$\[$RESET\] " | |
# Some terminals don't support true colors, e.g. if you enter `screen` the prompt | |
# will look all weird. And I still don't know how to check for support for true | |
# color, so meanwhile I did this. | |
if [ "$TERM" == "xterm-256color" ]; then | |
PS1="$CHERRY_PS1" | |
else | |
## Fallback prompt | |
PS1="$FALLBACK_PS1" | |
fi | |
} | |
export PROMPT_COMMAND=cherry_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preview:
New preview: