screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: truncated PWD on the hardstatus line?


From: Malte Skoruppa
Subject: Re: truncated PWD on the hardstatus line?
Date: Wed, 04 Mar 2009 22:04:54 +0100
User-agent: Thunderbird 2.0.0.19 (X11/20090302)

Hi,

I have a similar setup in which I rename screen windows according to the
current directory. If the path gets too long (more than 20 chars), I
truncate it, more precisely, I truncate a prefix exactly long enough
such that the resulting string is 18 chars long, then I prepend ".." to
the string so I know it has been truncated (hence in the end the string
contains exactly 20 chars). This is usually largely sufficient for me to
know where I am at all times.

I use the following PROMPT_COMMAND in my .bashrc

PROMPT_COMMAND='
if [ $TERM = "screen" ]; then
 MYPWD="${PWD/#$HOME/~}"
 [ ${#MYPWD} -gt 20 ] && MYPWD=..${MYPWD:${#MYPWD}-18}
 echo -n -e "\033k$MYPWD\033\\"
fi
'

(note: I also replace $HOME by ~, as this is much shorter).

This sends an escape sequence to screen (only when I'm in screen of
course) to set the current window name to $PWD, truncated and
everything, and it works perfectly. It's all pure bash, so it's
lightning fast, which is important since PROMPT_COMMAND is executed each
time you issue any command (I wouldn't like to use a perl one-liner or
something similar in this situation).

Hope that helps...

Cheers,

Malte

P Kapat schrieb:
> Hi,
>
> I am trying to setup my .screenrc. I am able to display the $PWD on
> the hardstatus line using:
>
> PS1="\[\e]0;\w\a\]$PS1"
>
> in my .bashrc, and
>
> hardstatus string '%{= Ck}%H:%L>%{= dd} %h'
>
> in my .screenrc. But for long directory names, I wanted to truncate
> the first part of the directory string to "...". I was trying to use
> the PROMPT_COMMAND in .bashrc to do the actual truncation and use that
> variable (say, newPWD)  instead of '\w' in the PS1 string above:
> "\[\e]0;$newPWD\a\]$PS1"
>
> Of course this doesn't work. Also, I couldn't quite understand the %L
> or %> or %< string sequences for screen. So, is it possible?
>
> Kindly CC me when replying, I am not subscribed to the list.
>   





reply via email to

[Prev in Thread] Current Thread [Next in Thread]