mtekman, to Bash

I've wasted literal years dabbling in beautiful looking shells (#fish / #zsh), or trying to enhance my #bash with needlessly bloated decoration frameworks (oh-my-bash/starship), I've decided to roll my own bash prompt in 20 lines.

It shows everything I need: user and host only over ssh, active environments (#conda, venv, or #guix), and the #git branch if I'm in a project.

That's it. Runs quick and easy.

Just add the code (see the alt/hover text in the code image) to your #bashrc, and voila!

[function prompt_command { ## styles and symbols local RESET='[\033[0m]' ; local BLD_GRN='[\033[1;32m]'; local BLD_YLW='[\033[1;33m]'; local BLD_PPL='[\033[1;35m]'; local BLD_WHT='[\033[1;37m]'; local ITL_YLW='[\0333;33m]'; local LSEP='{'; local RSEP='}'; local MSEP='|' ## export PS1="" ## Prepend contexts local GIT_BRANCH=$(git branch --show-current 2>/dev/null) [ -n "$SSH_CONNECTION" ] && PS1=${PS1}${BLD_WHT}'\u'${ITL_YLW}'@'${BLD_PPL}'\h'${RESET} [ -n "$CONDA_DEFAULT_ENV" ] && PS1=${PS1}${LSEP}${ITL_YLW}${CONDA_DEFAULT_ENV}${RESET}${RSEP} [ -n "$VIRTUAL_ENV" ] && PS1=${PS1}${LSEP}${BLD_WHT}${VIRTUAL_ENV##*/}${RESET}${RSEP} [ -n "$GUIX_ENVIRONMENT" ] && PS1=${PS1}${LSEP}${BLD_GRN}'GUIX'${RESET}${RSEP} [ -n "$GIT_BRANCH" ] && PS1=${PS1}${LSEP}${BLD_PPL}${GIT_BRANCH}${RESET}${RSEP} ## Truncate the path local trunc_len=25 ## shorten dirs if less than this local short_dir=$(pwd | sed -r "s|^${HOME}|~|") [[ ${#short_dir} > $trunc_len ]] && short_dir=$(sed -r 's|([^/]{2})[^/]+/|\1/|g' <<< "${short_dir}") ## Merge separators, and add the truncated path PS1=${PS1//${RSEP}${LSEP}/${MSEP}} PS1=${PS1}${BLD_GRN}${short_dir}${BLD_YLW}'▶ '${RESET} } export PROMPT_COMMAND=prompt_command

tivasyk,
@tivasyk@mastodon.social avatar

@mtekman it's beautiful in more ways than one. love it.

having run into problems with python-based prompt (powerline) because of incompatibilities between different venvs / global setup and being too lazy / minimalist to fix them, i'll just use your solution (only slightly modified colors).

thanks for sharing!

mtekman,

@tivasyk thanks! I had my problems with powerline too, despite it being a nice aesthetic - I think minimalism really is the answer here. I'm still not settled on the colours, so I would be greatly interested in what you choose

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • mdbf
  • ngwrru68w68
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • tacticalgear
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • DreamBathrooms
  • JUstTest
  • ethstaker
  • GTA5RPClips
  • modclub
  • tester
  • anitta
  • osvaldo12
  • cisconetworking
  • everett
  • cubers
  • Leos
  • provamag3
  • normalnudes
  • lostlight
  • All magazines