|
# 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" |