tag:blogger.com,1999:blog-7977789709139913287.post4204936594289039698..comments2023-08-27T15:03:26.783+02:00Comments on Technicals writings from JLH: Bash prompt trick: cheap emulation of tcsh's pwd trailing componentjlehenhttp://www.blogger.com/profile/07863111280211011857noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7977789709139913287.post-4176793929182785312009-06-25T23:44:42.727+02:002009-06-25T23:44:42.727+02:00Thanks for the code!
FWIW, here's a version t...Thanks for the code!<br /><br />FWIW, here's a version that keeps the prefix (~ or /) similar to how it works in tcsh:<br /><br />function traildir()<br />{<br /> local n=$1 dir=$2<br /> local sl tildedir homelen shifted traildir<br /> local oldifs=$IFS<br /><br /> tildedir=${dir#$HOME}<br /> if ! [[ "$tildedir" == "$dir" ]]; then<br /> # Special break out case<br /> [[ -z "$tildedir" ]] && { echo "~"; return 0; }<br /><br /> sl="~/"<br /> else<br /> sl="/"<br /> fi<br /><br /> set -- ${HOME//\// }<br /> homelen=$#<br /><br /> shifted=0<br /> IFS="/"<br /> set -- ${tildedir/\//}<br /> if [[ $# -gt $n ]]; then<br /> shifted=$(($# - $n))<br /> shift $shifted<br /> IFS="/"<br /> traildir="$sl<$shifted>/$*"<br /> else<br /> IFS="/"<br /> traildir="$sl$*"<br /> fi<br /><br /> IFS=$oldifs<br /> echo $traildir<br />}Mike Heffnerhttps://www.blogger.com/profile/11080441908731326948noreply@blogger.comtag:blogger.com,1999:blog-7977789709139913287.post-21330313917973929352009-02-24T18:44:00.000+01:002009-02-24T18:44:00.000+01:00Dear tataz,There's a new feature in the freshly re...Dear tataz,<BR/><BR/>There's a new feature in the freshly released bash4 which you may find interesting:<BR/><BR/>$ export PS1="\u@xxx:\w\$ "<BR/>bana@xxx:~$ cd lala/lili/lolo/lulu/<BR/>bana@xxx:~/lala/lili/lolo/lulu$ export PROMPT_DIRTRIM=2<BR/>bana@xxx:~/.../lolo/lulu$ export PROMPT_DIRTRIM=1<BR/>bana@xxx:~/.../lulu$ unset PROMPT_DIRTRIM<BR/>bana@xxx:~/lala/lili/lolo/lulu$<BR/><BR/>:*Anonymoushttps://www.blogger.com/profile/02809054491599987814noreply@blogger.com