Last active
February 20, 2023 13:54
-
-
Save overengineer/ad0a26b7c132c8b68ab530b09d199c99 to your computer and use it in GitHub Desktop.
Emoji Bash Prompt
This file contains hidden or 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
# https://gist.github.com/overengineer/ad0a26b7c132c8b68ab530b09d199c99 | |
# Bash unofficial strict mode | |
set -euo pipefail | |
IFS=$'\n\t' | |
LANG='' | |
# Pacify Bash strict mode | |
export GIT_PS1_COMPRESSSPARSESTATE='' | |
export GIT_PS1_OMITSPARSESTATE='' | |
# waste some cpu cycles | |
function emojis () { | |
local f=$(find -maxdepth 3 -nowarn -not -path "*.git*" -not -path "*build/*" -depth | head -n 400) | |
function emojis.match () { | |
echo "$f" | grep -Eq "$1" && echo -n "$2" | |
} | |
emojis.match "(\.[ch](pp)?|\.cmake|/CMakeLists\.txt)$" 'π ' # C/C++ | |
emojis.match "\.r(s|lib)$" 'π¦' # Rust | |
emojis.match "\.go$" 'πΉ' # Go | |
emojis.match "\.ja(va|r)$" 'β' # Java | |
# emojis.match "\.(cs|csproj(\.user)?)$" '#οΈβ£' # C# | |
emojis.match "\.(vb[glprwzi]?|vbproj(\.user)?)$" 'βΎοΈ' # VB | |
emojis.match "\.jsx?$" 'π¨' # JS | |
emojis.match "\.e?rb$" 'π»' # Ruby | |
emojis.match "\.(pyc?|ipynb)$|/__pycache__$" 'π' # Python | |
emojis.match "\.ph(p[345s]|tml)$" 'π' # PHP | |
emojis.match "\.pl$" 'πͺ' # Perl | |
emojis.match "\.ml$" 'π«' # OCaml | |
emojis.match "\.nim$" 'π' # Nim | |
emojis.match "\.zi[gr]$" 'π¦' # Zig | |
emojis.match "\.(swift|mm|scptd?|applescript)$" 'π' # Apple Languages | |
emojis.match "/Dockerfile$" 'π³' # Docker | |
emojis.match "\.z?sh$" 'π§' # Shell | |
} | |
function last_commit_brief () { | |
echo -n "$(git log -1 --oneline --pretty="%<(9,trunc)%cN(%<(6,trunc)%cr): %<($(( $(tput cols) - 60 )),trunc)%B" 2> /dev/null | head -n 1)" | |
} | |
function __git_dirty () { | |
git diff --quiet --no-ext-diff HEAD | |
[ $? == 1 ] && echo "!" | |
} | |
function __is_repo () { | |
echo $(git rev-parse --is-inside-work-tree 2>/dev/null) | |
} | |
export PS1='${debian_chroot:+($debian_chroot)}\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;32m\]@\[\033[0;32m\]\h:\[\033[0;33m\]$(__git_ps1)\[\033[0;31m\]$(__git_dirty) \[\033[0;0m\]$(last_commit_brief)$([[ $(__is_repo) ]] && echo -e "\n\[\033[0;32m\]$(emojis) ")\[\033[0;36m\]\w\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] \[\033[37m\]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment