Unix/Linux

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • bash prompt stuff

    5 answers - 666 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit


    hey, I'd like to customize my bash prompt a bit
    currently I have:
    PS1="-\h:\w- \u$ "
    the problem I have is sometimes I get pretty deep into my directory
    structure, and some of my directory names are pretty long. Is there
    some way to change the \w in my prompt to:
    1) if the directory structure is less than 30 characters, just display
    it
    2) if the directory structure is more than 30 characters, change it to
    display three dots (like an ellipsis) and the last 27 characters of the
    path
    for instance:
    / gets changed to
    so the prompt would look like:
    username$
    thanks in advance
  • No.1 | | 821 bytes | |

    2005-07-12, juicymixx@mailinator.com wrote:

    hey, I'd like to customize my bash prompt a bit

    currently I have:
    PS1="-\h:\w- \u$ "

    the problem I have is sometimes I get pretty deep into my directory
    structure, and some of my directory names are pretty long. Is there
    some way to change the \w in my prompt to:
    1) if the directory structure is less than 30 characters, just display
    it
    2) if the directory structure is more than 30 characters, change it to
    display three dots (like an ellipsis) and the last 27 characters of the
    path
    for instance:
    / gets changed to
    ng_path/going/to/some_place

    so the prompt would look like:
    username$

    PRMPT_CMMAND='if [ ${#PWD} -gt 30 ]
    then PS1="-\h:${PWD: -27}\u$ "
    else PS1="-\h:\w- \u$ "
    fi'
  • No.2 | | 1091 bytes | |

    Tue, 12 Jul 2005 15:04:42 -0700, juicymixx@mailinator.com wrote:

    hey, I'd like to customize my bash prompt a bit

    currently I have:
    PS1="-\h:\w- \u$ "

    the problem I have is sometimes I get pretty deep into my directory
    structure, and some of my directory names are pretty long. Is there
    some way to change the \w in my prompt to:
    1) if the directory structure is less than 30 characters, just display
    it
    2) if the directory structure is more than 30 characters, change it to
    display three dots (like an ellipsis) and the last 27 characters of the
    path
    for instance:
    / gets changed to
    ng_path/going/to/some_place

    so the prompt would look like:
    username$

    If you have bash3, then the following will do what you want, after you put
    in a few more question-marks.

    PS1='-\h:${PWD/#???*/${PWD#${PWD%???}}}- \u\$ '

    The first set of question-marks determine the length where the prompt is
    changed, and the second set determine how many characters of the name are
    displayed.

  • No.3 | | 1079 bytes | |

    Tue, 12 Jul 2005 15:04:42 -0700, juicymixx@mailinator.com wrote:

    hey, I'd like to customize my bash prompt a bit

    currently I have:
    PS1="-\h:\w- \u$ "

    the problem I have is sometimes I get pretty deep into my directory
    structure, and some of my directory names are pretty long. Is there
    some way to change the \w in my prompt to: 1) if the directory structure
    is less than 30 characters, just display it
    2) if the directory structure is more than 30 characters, change it to
    display three dots (like an ellipsis) and the last 27 characters of the
    path
    for instance:
    / gets changed to
    ng_path/going/to/some_place

    so the prompt would look like:
    username$

    If you have bash3, then the following will do what you want, after you put
    in a few more question-marks, and change the number

    PS1='-\h:${PWD/#???*/${PWD: -9}}- \u\$ '

    The question-marks determine the length where the prompt is changed, and
    the -9 determine how many characters of the name are displayed.

  • No.4 | | 222 bytes | |


    Thanks for all the responses guys
    I ended up going with Chris F.A. Johnson's solution. I like the idea
    of having the PRMPT_CMMAND do all the checking 'work'. Thanks
    Chris!
  • No.5 | | 337 bytes | |

    juicymixx@mailinator.com wrote:
    hey, I'd like to customize my bash prompt a bit

    Let another script do the work for you

    http://bashish.sourceforge.net # "bashish.bash"
    # "Dotfile
    Generator.tcl"
    # "ibpconf.bash"

    For bash profiles in general, a fine place to look is:

    =Brian

Re: bash prompt stuff


max 4000 letters.
Your nickname that display:
In order to stop the spam: 0 + 9 =
QUESTION ON "Unix/Linux"

EMSDN.COM