Code challenge: Bash prompt path shortener
问题 I implemented a prompt path shortener for bash to be included in the PS1 environment variable, which shortens the working directory into something more compact but still descriptive. I'm curious what other ideas may exist. Here's the challenge: Create a bash function _dir_chomp which can be included into PS1 like this (line breaks inserted for readability): PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] $( _dir_chomp "$(pwd)" 20 )\[\033[01;37m\]$(parse_git_branch)\[\033[01;34m\] \$\[\033[00m\] '