Skip to content

Instantly share code, notes, and snippets.

@overengineer
Last active February 20, 2023 13:54
Show Gist options
  • Save overengineer/ad0a26b7c132c8b68ab530b09d199c99 to your computer and use it in GitHub Desktop.
Save overengineer/ad0a26b7c132c8b68ab530b09d199c99 to your computer and use it in GitHub Desktop.
Emoji Bash Prompt
# 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