Skip to content

Instantly share code, notes, and snippets.

@Bradshaw
Last active September 2, 2021 10:05
Show Gist options
  • Save Bradshaw/4d5572cf94242f4dd5c8d643a6f8aea3 to your computer and use it in GitHub Desktop.
Save Bradshaw/4d5572cf94242f4dd5c8d643a6f8aea3 to your computer and use it in GitHub Desktop.
A cute iTerm2 config 🌸

It looks like this

My terminal prompt in all its glory

  1. Includes Git branch name
  2. Distance (ahead & behind) the origin/HEAD
  3. Symbols indicating the kind of changes
# Requires a font that supports Nerd Fonts symbols: https://www.nerdfonts.com/
# Also some aliases are context-specific
#
# Manage history
export HISTCONTROL=ignoreboth
export HISTSIZE=8000
export HISTFILESIZE=8000
# Extra paths
export PATH="/usr/local/bin:$PATH:$HOME/bin:."
export PATH="/Applications/Unity/Hub/Editor/2020.1.7f1/PlaybackEngines/AndroidPlayer/SDK/platform-tools:$PATH"
# Command line completions (Needs to be run before Git display stuff?)
if [ -r /usr/local/etc/profile.d/bash_completion.sh ]; then
. /usr/local/etc/profile.d/bash_completion.sh;
fi
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash;
fi
# LOCALE
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# Emoji sets
flowers=(🌸 🌺 🌼)
plants=(🌱 πŸƒ 🌿)
function pick_flower {
echo ${flowers[$RANDOM % ${#flowers[@]}]};
}
function pick_plant {
echo ${plants[$RANDOM % ${#plants[@]}]};
}
# Git display
function git_distance {
local main_branch="$(git symbolic-ref refs/remotes/origin/HEAD 2> /dev/null | sed 's@^refs/remotes/origin/@@')"
if [ -z "$main_branch" ]; then
echo
else
local distance="$(git rev-list --left-right --count origin/$main_branch...HEAD 2> /dev/null)"
echo ↓$(echo $distance | sed 's/ / ↑/')
fi
}
function git_dirty_bits {
git status --porcelain 2> /dev/null | (
linecount=0
unset dirty deleted untracked newfile copied renamed
while read line ; do
((linecount=linecount+1))
case "${line//[[:space:]]/}" in
@('M'|'UU')*) dirty='ο•© ' ; ;; # This line breaks it bash_completion.sh isn't loaded ???
'D'*) deleted='ο€” ' ; ;;
'??'*) untracked='? ' ; ;;
'A'*) newfile=' ' ; ;;
'C'*) copied='ο€… ' ; ;;
'R'*) renamed=' ' ; ;;
esac
done
bits="$dirty$deleted$untracked$newfile$copied$renamed"
[ -n "$bits" ] && echo " ξ‚» $bits" || echo " ξ‚» Β· "
)
}
function git_branch {
export LAST_GIT_BRANCH=$(git branch 2>/dev/null | grep '^*' | colrm 1 2 | tr -d '\n');
if ([ -n "$LAST_GIT_BRANCH" ]);
then
echo "$LAST_GIT_BRANCH"
else
echo ""
fi
}
function git_symbol {
local current_branch="$(git_branch)"
if [ -z "$current_branch" ]; then
echo
else
echo " $(pick_plant) "
fi
}
function git_mods {
local current_branch="$(git_branch)"
if [ -z "$current_branch" ]; then
echo
else
echo "$(git_distance)$(git_dirty_bits)"
fi
}
function git_maybe_branch {
local current_branch="$(git_branch)"
if [ -z "$current_branch" ]; then
echo
else
local bits="$(git_dirty_bits)"
local dir=${PWD##*/}
local offset="$((${#dir}))"
local mods="$(git_mods)"
local full="$current_branch $mods"
if [ "$((${#full} + ${#dir} + ${#bits} + 10))" -gt "$(tput cols)" ]; then
echo
else
echo "$current_branch "
fi
fi
}
# Color and font management
function sep {
printf "\[$(tput setaf $1)\]ξ‚Ί\[$(tput setaf 15)$(tput setab $1)\]"
}
function out {
printf "\[$(tput sgr0)$(tput setaf $1)$(tput rev)\]ξ‚Ί\[$(tput sgr0)\]"
}
# Custom prompt
export PS1="\[$(tput sgr0)\]\n \$(pick_flower)\[$(tput setab 6)\] \W $(sep 4)\$(git_symbol)\[$(tput sitm)\]\$(git_maybe_branch)\[$(tput ritm)\]\$(git_mods)\$(pick_flower)\[$(tput sgr0)\]\n$(sep 9)  $(sep 5)$(out 5) "
# Set window title to working directory
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# Extra programs
# Enable "fuck" command
eval "$(thefuck --alias)"
# Get the weather forecast
function wttr {
if [ "$(tput cols)" -lt 63 ]; then
curl http://wttr.in/${1:-Lille}?0;
elif [ "$(tput cols)" -lt 125 ]; then
curl http://wttr.in/${1:-Lille}?n;
else
curl http://wttr.in/${1:-Lille};
fi
}
# Text editors
alias vi=/usr/bin/nano # who the fuck uses vi?
alias rider="open -na Rider.app"
alias subl="open -a /Applications/Sublime\ Text.app"
# Node version manager
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Pretty ls
alias ls="colorls --sd --gs"
# Main Colors
unrecognized_file: orange
recognized_file: green
executable_file: red
dir: magenta
# Link
dead_link: red
link: cyan
# special files
socket: green
blockdev: green
chardev: green
# Access Modes
write: darkkhaki
read: limegreen
exec: red
no_access: indianred
# Age
day_old: mediumspringgreen
hour_old: lime
no_modifier: seagreen
# File Size
file_large: red
file_medium: orange
file_small: green
# Random
report: white
user: teal
tree: cyan
empty: yellow
error: red
normal: darkkhaki
# Git
addition: chartreuse
modification: darkkhaki
deletion: darkred
untracked: darkorange
unchanged: forestgreen
ai: ""
android: ""
apple: "ο…Ή"
audio: ""
avro: "ξ˜‹"
c: ""
clj: ""
coffee: ""
conf: "ξ˜•"
cpp: ""
css: ""
d: ""
dart: ""
db: ""
diff: "ο‘€"
doc: ""
docker: ""
ebook: "ξŠ‹"
env: "ο‘’"
epub: ""
erl: ""
file: " "
font: "ο€±"
gform: ""
git: ""
go: ""
gruntfile.js: ""
hs: ""
html: "ο„»"
image: "ο‡…"
iml: ""
java: "ξˆ„"
js: ""
json: "ξ˜‹"
jsx: ""
less: ""
log: ""
lua: ""
md: "ο’Š"
mustache: ""
npmignore: ""
pdf: ""
php: ""
pl: ""
ppt: ""
psd: ""
py: "ξ˜†"
r: ""
rb: ""
rdb: ""
rss: "ο‚ž"
rubydoc: ""
sass: "ξ˜ƒ"
scala: ""
shell: "ο’‰"
sqlite3: "ξŸ„"
styl: "ξ˜€"
tex: "ξ˜€"
ts: ""
twig: ""
txt: "ο…œ"
video: "ο€½"
vim: ""
windows: "ο…Ί"
xls: ""
xml: "ξ˜™"
yarn.lock: ""
yml: ""
zip: ""
# Custom
unity: ""
cs: ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment