Skip to content

Instantly share code, notes, and snippets.

@walteh
Last active September 20, 2025 14:46
Show Gist options
  • Select an option

  • Save walteh/663b6b396151e0ab9f7e8daf43a8f9bf to your computer and use it in GitHub Desktop.

Select an option

Save walteh/663b6b396151e0ab9f7e8daf43a8f9bf to your computer and use it in GitHub Desktop.
bash_prompt_simple
__bash_prompt_simple() {
local e=$? p a o i ee faint=$'\e[2m' err=$'\e[31m' esc=$'\e[0m' bold=$'\e[1m' op='\[' cl='\]'
[[ $PWD == "$HOME"* ]] && p="~${PWD#$HOME}" || p=$PWD
IFS=/ read -ra a<<<"$p"; o=${a[0]}
for((i=1;i<${#a[@]}-1;i++)); do [[ ${a[i]} ]] && o+="$op$faint$cl/$op$esc$cl${a[i]:0:1}"; done
[[ ${#a[@]} -gt 1 ]] && o+="$op$faint$cl/$op$esc$cl$op$bold$cl${a[-1]}$op$esc$cl"
[[ $e != 0 ]] && ee=" $op$err$cl$e$op$esc$cl" || ee=""
PS1="$o$ee $op$faint$cl\$$op$esc$cl "
};
PROMPT_COMMAND=__bash_prompt_simple
@walteh
Copy link
Author

walteh commented Sep 19, 2025

basically only does two things:

  1. truncates the path by letter
  2. shows previous non-zero exit codes
Screenshot 2025-09-19 at 9 17 44 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment