Last active
November 27, 2022 20:35
-
-
Save simbo/89983bb71774d5325429b13ed1724694 to your computer and use it in GitHub Desktop.
Bashrc commons
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
# set prompt with git info, last exit code and colors | |
promptCommand() { | |
# values | |
lastExitCode=$? | |
gitRev="$(git branch 2>/dev/null | grep '^*' | colrm 1 1)" | |
# colors | |
# (all 8bit color codes: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) | |
user=$(tput setaf 214) | |
at=$(tput setaf 240) | |
host=$(tput setaf 90) | |
dir=$(tput setaf 33) | |
git=$(tput setaf 135) | |
lastExit=$(tput setaf $([ $lastExitCode -eq 0 ] && echo 34 || echo 124)) | |
clock=$(tput setaf 240) | |
reset=$(tput sgr0) | |
# prompt | |
export PS1="\[$user\]\u\[$at\]@\[$host\]\h \[$dir\]\w\[$git\]$gitRev \[$clock\]\t\n\[$lastExit\]❯ \[$reset\]" | |
} | |
PROMPT_COMMAND="promptCommand" | |
# smart bash history | |
bind '"\e[A": history-search-backward' | |
bind '"\e[B": history-search-forward' | |
# enable keychain for ssh keys | |
/usr/bin/keychain --quiet $HOME/.ssh/id_rsa | |
source $HOME/.keychain/$HOSTNAME-sh | |
# add homedir scripts to path | |
export PATH="$HOME/bin:$PATH" | |
# display motd | |
sudo run-parts /etc/update-motd.d/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment