Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way to force my PS1 variable to a certain number of chars.
It currently looks like:

$PS1="\W $"

and I'm trying to keep the same number of characters regardless of the length of current folder name.

For example, both Documents and bin would be displayed as 10 character strings, keeping the left side of my terminal the same width all of the time.

share|improve this question
    
How are you going to format this? Something like "LongFileName" -> "LongFileNa"? By the way, awk can do this: echo 12345 | awk '{substr($0, 1, 10)}'. How to stuff it into $PS1, I have no idea. –  new123456 Jun 22 '11 at 21:03
    
@new123456 this is exactly my issue. I can do what you're saying, but if you use $pwd you'll only get your initial login directory, it won't update as you change directories –  cmwright Jun 23 '11 at 14:20
    
bash has the PROMPT_COMMAND variable, but it doesn't have the same semantics as PS1 (notably the escape characters). zsh can do this with PROMPT (it evaluates at every run). –  new123456 Jun 23 '11 at 15:11

1 Answer 1

If you are using an xterm or similar then you can put the current directory in the Title Bar and then have a fixed prompt

PS1='\[\e]0;\h \w\007\] \u$ '

will put the current hostname and directory in the title bar and make the prompt username$ e.g. iain$

There is more information here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.