Skip to content

Instantly share code, notes, and snippets.

@eliminmax
Last active March 4, 2025 19:19
Show Gist options
  • Select an option

  • Save eliminmax/197c5f8e9fb41168b16df34ff604c5b6 to your computer and use it in GitHub Desktop.

Select an option

Save eliminmax/197c5f8e9fb41168b16df34ff604c5b6 to your computer and use it in GitHub Desktop.
# System-wide aliases
alias clear-hist='history -c > ~/.bash_history;'
alias dir='dir --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias h='history'
alias l='ls -F'
alias la='ls -A'
alias ll='ls -AlF'
alias ls='ls --color=auto'
alias t='tree'
alias v='vim'
alias vdir='vdir --color=auto'
alias vi='vim'
# Setup for prompt
case "$(tput colors)" in
256|16777216)
__prompt_user_host_color_code='38;5;{}'
__prompt_directory_color_code='38;5;{}'
# __prompt_gitbranch_color_code='38;5;{}'
__prompt_prev_okay_color_code='38;5;46'
__prompt_prev_fail_color_code='38;5;124'
__prompt_priv_user_color_code='38;5;{}'
;;
8)
__prompt_user_host_color_code='{}'
__prompt_directory_color_code='{}'
# __prompt_gitbranch_color_code='{}'
__prompt_prev_okay_color_code='32'
__prompt_prev_fail_color_code='31'
__prompt_priv_user_color_code='{}'
;;
*)
# must not be empty or else it's treated as an implicit 0, and __prompt_user_host_color_code must end the inverted color set by __prompt_priv_user_color_code
__prompt_user_host_color_code='27'
__prompt_directory_color_code='27'
# __prompt_gitbranch_color_code='27'
__prompt_prev_okay_color_code='27'
__prompt_prev_fail_color_code='27'
__prompt_priv_user_color_code='7'
;;
esac
__prompt_prev_exit_color_code() {
local prev_exit=$?
case $prev_exit in
0) printf '%s' "$__prompt_prev_okay_color_code" ;;
*) printf '%s' "$__prompt_prev_fail_color_code" ;;
esac
return $prev_exit
}
if [ $EUID -eq 0 ]; then
PS1='\[\e[0;1m\][\[\e[$(__prompt_prev_exit_color_code)m\]$?\[\e[39m\]] \[\e[${__prompt_priv_user_color_code}m\]{\u}\[\e[${__prompt_user_host_color_code}m\]@\h\[\e[39m\]:\[\e[${__prompt_directory_color_code}m\]\w\[\e[39m\]\$ \[\e[m\]'
else
PS1='\[\e[0;1m\][\[\e[$(__prompt_prev_exit_color_code)m\]$?\[\e[39m\]] \[\e[${__prompt_user_host_color_code}m\]\u@\h\[\e[39m\]:\[\e[${__prompt_directory_color_code}m\]\w\[\e[39m\]\$ \[\e[m\]'
# PS1='\[\e[0;1m\][\[\e[$(__prompt_prev_exit_color_code)m\]$?\[\e[39m\]]\[\e[${__prompt_gitbranch_color_code}m\]$(__git_ps1) \[\e[${__prompt_user_host_color_code}m\]\u@\h\[\e[39m\]:\[\e[${__prompt_directory_color_code}m\]\w\[\e[39m\]\$ \[\e[0m\]'
fi
# assorted shell options
shopt -s lithist # save multi-line history with embedded newlines
shopt -s autocd # if given a directory name as a command, treat it as an implicit `cd`
# vi:ft=bash:noet:ai:ts=4:sts=4:sw=4
@eliminmax
Copy link
Author

When setting up a new Debian system, I take that replace instances of {} with ANSI color codes (different for each host, and chosen with the help of sharkdp/pastel, and append it to the system-wide /etc/bash.bashrc file. On desktop systems where I work with git a lot, I replace the non-root PS1 template with the commented-out alternative, and uncomment and set the __prompt_gitbranch_color_code variables.

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