PTC MKS Toolkit Knowledge Base

Section:IO
Product:MKS Toolkit (All)
Version:
OS:All
Keywords:PS1, path length
Category:General/Knowledge Base


How can I make it so that my PS1 prompt is not so long?


Put this in your $HOME/environ.ksh and very long paths will no longer sweep your cursor off your screen...

# Annoyed by long paths pushing your cursor off the screen?

PS1_MAX_LEN=20
PS1_PREFIX_LEN=5
PS1_POSTFIX_LEN=12

PS1='[$( if [ "${#PWD}" -le ${PS1_MAX_LEN:-15} ] ; then ; echo $PWD; else ; echo ${PWD:0:${PS1_PREFIX_LEN:-5}}...${PWD:$(( ${#PWD} - ${PS1_POSTFIX_LEN:-7} )):${PS1_POSTFIX_LEN:-7} }; fi)] '

Given a path like C:/temp your prompt will look like:

    [C:/temp]
However, when you are deep in your code tree, C:/src/rd/nt/shell/library/built-in, this construct will display your prompt as:
    [C:/sr...ary/built-in]