Code challenge: Bash prompt path shortener

前端 未结 5 1390
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 09:27

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 descrip

5条回答
  •  迷失自我
    2021-01-30 10:15

    This is how I shorten my bash prompt w/ full path in titlebar (works since 3.0):

    _PS1P=('' '..')
    PROMPT_COMMAND='_PS1L=${#DIRSTACK[0]} _PS1D=${DIRSTACK[0]}'
    PS1='\[\e]2;\h:\w\a\]\h ${_PS1P[$_PS1L>36]}${_PS1D:$_PS1L>36?-34:0} \$ '
    

    This method requires very low CPU overhead.

提交回复
热议问题