Last active
March 18, 2018 10:07
-
-
Save bitdivine/46e754abd05d0ba089d3bd20817c9a59 to your computer and use it in GitHub Desktop.
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
| # Prompt: Exit code red/green && runtime | |
| PROMPT_COMMAND=__prompt_command # Func to gen PS1 after CMDs | |
| __prompt_command() { | |
| local EXIT="$?" # This needs to be first | |
| timer_stop | |
| PS1="" | |
| local RCol='\[\e[0m\]' | |
| local Red='\[\e[0;31m\]' | |
| local Gre='\[\e[0;32m\]' | |
| local BYel='\[\e[1;33m\]' | |
| local BBlu='\[\e[1;34m\]' | |
| local Pur='\[\e[0;35m\]' | |
| if [ $EXIT != 0 ]; then | |
| PS1+="${Red}\u${RCol}" # Add red if exit code non 0 | |
| else | |
| PS1+="${Gre}\u${RCol}" | |
| fi | |
| local runtime="$(printf "%s:%02s:%02s\n" $((timer_show/3600)) $((timer_show/60%60)) $((timer_show%60)))" | |
| PS1+="${RCol}@${BBlu}\h ${Pur}\W${BYel} ${runtime}$ ${RCol}" | |
| } | |
| function timer_start { | |
| timer=${timer:-$SECONDS} | |
| } | |
| function timer_stop { | |
| timer_show=$(($SECONDS - $timer)) | |
| unset timer | |
| } | |
| trap 'timer_start' DEBUG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment