[ale] Bash prompt problem.
Michael B. Trausch
fd0man at gmail.com
Fri Oct 27 16:41:02 EDT 2006
I have a minorly annoying problem with my bash prompt. If anyone would
be able to help with it, I would be really grateful.
The problem: The prompt always causes a "refresh" when anything is
typed, but only when the prompt is a single line, and only when the
locale is set to UTF-8. The prompt is a custom prompt, built with a
bash function:
c_prompt ()
{
local last_err=$?;
local jobs_count=`jobs | wc -l | tr -d " "`;
local red="\[\033[1;31m\]";
local cyan="\[\033[1;36m\]";
local yellow="\[\033[1;33m\]";
local reset="\[\033[0;0m\]";
if [ "$jobs_count" -eq 0 ]; then
local jobs_prompt="";
local jobs_tb="";
else
if [ "$jobs_count" -eq 1 ]; then
local jobs_tb=" - [${jobs_count} bg job]";
local jobs_prompt="${red}You have $jobs_count job on this
tty.${reset}\n";
else
local jobs_tb=" - [${jobs_count} bg jobs]";
local jobs_prompt="${red}You have $jobs_count jobs on this
tty.${reset}\n";
fi;
fi;
if [ x$TERM = xxterm ]; then
local title_bar="\[\033]0;\u@\H - \w${jobs_tb}\007\]";
else
local title_bar="";
fi;
export
PS1="${title_bar}${jobs_prompt}${cyan}\u${yellow}@${cyan}\h${yellow}:${cyan}\W${yellow}[${cyan}${last_err}${yellow}]\\$
${reset}"
}
The result is, when there are background jobs:
You have 1 job on this tty.
fd0man at pepper:~[0]$
And without background jobs:
fd0man at pepper:~[0]$
Along with the xterm title being set, in capable terminals.
Now, the problem is that when I cat something that has no newlines, or
echo something with newlines suppressed, which happens when I want to
look at pid files and the like, I am forced in doing something like this:
fd0man at pepper:~[0]$ cat /var/run/ntpd.pid;echo
13326
fd0man at pepper:~[0]$
If I don't, then the following happens:
fd0man at pepper:~[0]$ cat /var/run/ntpd.pid
fd0man at pepper:~[0]$ [0]$
With the cursor being on the second '[' character. The prompt
"refreshes" itself on the line upon every new character typed, too, in
effect redrawing the command line every single time I press a character
on the keyboard. I have had this problem since I created this custom
prompt, but I can't seem to find the cause behind it, and it is slightly
irritating. Does anyone have any ideas that spring to mind as to what
would be the cause?
Thanks!
Mike
--
Michael B. Trausch <fd0man at gmail.com> - Jabber: fd0man at livejournal.com
Demand freedom: Use open and free protocols, standards, and software.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
More information about the Ale
mailing list