.zshrc
goes in $HOME
, everything else goes in $HOME/share
, and you want to brew install zsh-git-prompt
. I'm using Gruvbox here with macOS Terminal.
Last active
September 16, 2020 20:55
-
-
Save e0da/05d467f2cb31411d8d9bce6dcba11833 to your computer and use it in GitHub Desktop.
Prompts
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
# shellcheck shell=bash | |
STDOUT=1 | |
STDERR=2 | |
if test -t $STDOUT; then | |
INTERACTIVE=1 | |
else | |
INTERACTIVE=0 | |
fi | |
interactive_shell() { | |
test "$INTERACTIVE" = 1 | |
} | |
color() { | |
if interactive_shell; then | |
echo -en "\033[$1;5;$2m" | |
fi | |
} | |
B() { | |
echo -en "\033[1m" | |
} | |
b() { | |
echo -en "\033[22m" | |
} | |
F() { | |
color 38 "$1" | |
} | |
f() { | |
echo -en "\033[39m" | |
} | |
K() { | |
color 48 "$1" | |
} | |
k() { | |
echo -en "\033[49m" | |
} | |
log() { | |
echo -e "$@" >&$STDOUT | |
f >&$STDOUT | |
k >&$STDOUT | |
} | |
warn() { | |
echo -e "$@" >&$STDERR | |
f >&$STDERR | |
k >&$STDOUT | |
} | |
error() { | |
echo -e "$@" >&$STDERR | |
f >&$STDERR | |
k >&$STDOUT | |
} |
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
# shellcheck shell=bash | |
# Unix | |
export BLACK=0 | |
export RED=1 | |
export GREEN=2 | |
export YELLOW=3 | |
export BLUE=4 | |
export MAGENTA=5 | |
export CYAN=6 | |
export WHITE=7 | |
export bBLACK=8 | |
export bRED=9 | |
export bGREEN=10 | |
export bYELLOW=11 | |
export bBLUE=12 | |
export bMAGENTA=13 | |
export bCYAN=14 | |
export bWHITE=15 | |
# Rainbow | |
export RED="$RED" | |
export ORANGE=208 | |
export YELLOW="$YELLOW" | |
export GREN="$GREEN" | |
export BLUE="$BLUE" | |
export VIOLET="$MAGENTA" | |
# Other | |
export PINK=175 | |
# Aliaases | |
export GRAY="$WHITE" | |
export dGRAY="$bBLACK" | |
export lGRAY="$bWHITE" | |
export INDIGO="$MAGENTA" | |
export PURPLE="$MAGENTA" |
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
# vim: set ft=bash: | |
# shellcheck shell=bash | |
source "/usr/local/opt/zsh-git-prompt/zshrc.sh" | |
# shellcheck source=cli.sh | |
source "$HOME/share/cli.sh" | |
# shellcheck source=colors.sh | |
source "$HOME/share/colors.sh" | |
BOLD='%B' # bold mode | |
NORMAL='%b' # normal mode | |
# In lieu of descriptive names, use mostly consistent naming convention. | |
# Descriptive name, plus context as a character. The exception is actual | |
# characters, which have the type first. Because short names are nicer when all | |
# you're doing is string concatenation. | |
cL='»' # Left prompt character | |
cR='«' # Right prompt character | |
cLT='❮' # "Less Than" parenthesis character | |
cGT='❯' # "Greater Than" parenthesis character | |
spbC='31' # super pretty blue Color | |
branchC="$ORANGE" # branch Color | |
branchM="$BOLD" # branch Mode | |
cmdC="$spbC" # comand Color | |
cmdM="$NORMAL" # comand Mode | |
dirC="$BLUE" # directory Color | |
dirC="$spbC" # directory Color | |
dirM="$BOLD" # directory Mode | |
promptC="$bWHITE" # prompt Color | |
promptM="$BOLD" # prompt Mode | |
prL="$promptM%F{$bWHITE}$cL " # Left prompt | |
prR=" $promptM%F{$bWHITE}$cR" # Right prompt | |
prF="%F{$YELLOW}$cLT%F{$RED}%?%F{$YELLOW}$cGT " # prompt, prev cmd Failed | |
ZSH_THEME_GIT_PROMPT_PREFIX='' | |
ZSH_THEME_GIT_PROMPT_SUFFIX='' | |
ZSH_THEME_GIT_PROMPT_SEPARATOR=' ' | |
ZSH_THEME_GIT_PROMPT_BRANCH="%{$branchM%F{$branchC}%}" | |
function e0da_prompt() { | |
if git rev-parse --is-inside-work-tree &>/dev/null; then | |
git_status=$(git_super_status | tr -d "\n") | |
git_ref=$(echo "$git_status" | awk '{ print $1 }') | |
git_status=$(echo "$git_status" | awk '{ print $2 }') | |
echo -en "$git_status$git_ref" | |
fi | |
echo -en "$prR%F{$dirC}%~" | |
} | |
# Print the index-th digit of digits, e.g. $(d 245 2) => 4 | |
d() { | |
local digits; digits="$1"; shift | |
local index; index="$1"; shift | |
echo "$digits" | awk "{print \$$index}" | tr -d "\n" | |
} | |
rainbow_timestamp() { | |
local out | |
local t; t=$(date +'%H%M%S' | sed -E 's/(.)/\1 /g') | |
out="%F{ $RED }$(d "$t" 1)" | |
out="$out%F{$ORANGE}$(d "$t" 2)" | |
out="$out%F{$YELLOW}$(d "$t" 3)" | |
out="$out%F{$GREEN }$(d "$t" 4)" | |
out="$out%F{$BLUE }$(d "$t" 5)" | |
out="$out%F{$VIOLET}$(d "$t" 6)" | |
echo -en "$out" | tr -d "\n" | |
} | |
export PROMPT="%B\$(rainbow_timestamp)%(?.$prL.$prF)$cmdM%F{$cmdC}" | |
export RPROMPT="\$(e0da_prompt)%b%f" | |
# Restore text color before output begins | |
# https://stackoverflow.com/questions/9268836/zsh-change-prompt-input-color | |
preexec () { echo -ne "\e[0m" } |
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
# vim: set ft=bash nowrap: | |
# shellcheck shell=bash | |
# shellcheck source=prompts.zsh | |
source "$HOME/share/prompts.zsh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment