The page: http://tldp.org/HOWTO/Bash-Prompt-HOWTO/setps.html shows the best place to change the shell prompt (which is .bashrc).
However, the previous page of that document has a lot of escape sequences offered by the Bash shell for insertion in the prompt (From the Bash 2.04 man page)
I found that \w (the current working directory) and \W (the basename of the current working directory=cwd) work perfectly.
However, what I was hoping i could do would be to get not just the last basename of the cwd but rather the last 3 or so. In short, I wanted to be able to see something between the \w and the \W settings
would anyone have any idea for how to do this?
proposal for script:
1) create a variable and put the \W into it
2) "somehow" truncate this, with string manipulation searching on the "\" and so I could specify 2 or 3 backslashes to "capture"
3) put the truncated string into a new variable
4) return this new variable
5) name the script which does this in such a way that bash will now recognize not just \w and \W but also \Wn where n is the number of slashes to keep
6) how do I modify bash to recognize an option, in this case, my \Wn where n is a number, so I can do
$ PS1=" \W3 $ "
and have it be recognized?
while some of the logic i think is clear to me, some of the syntax for doing each of those steps eludes me.
I could do the truncation in Perl but can truncation be done in bash scripting directly?