You are not logged in.

#1 2009-02-26 16:45:44

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

[SOLVED] History acting wierd in bash

So i noticed last night that my bash prompt was acting funny regarding my history.  i've been messing with .bashrc a bit but i'm not sure if that's got to do with it.  i'll outline the issue then post my .bash* files at the end.

as an example: if my last few entries in history look like this (timestamps removed):

> history | tail
 6701 sudo tail /var/log/vsftpd.log
 6702 sudo cat /var/log/vsftpd.log | grep JimmyPage
 6703 tail /var/log/errors.log
 6704 cat /var/log/everything.log | grep fcron
 6705 ls .bin/
 6706 cat /var/log/pacman.log
 6707 cat /var/log/pacman.log | grep upgraded
 6708 tail history
 6709 history
 6710 history | tail

as i cycle through history with the UP/DOWN arrows after about three entries the first 6 or 7 characters would remain as artifacts on the prompt.  this is hard to explain so here's a sequence of events that would match the above history entries:

  <UP> makes prompt> history | tial
  <UP> makes prompt> history
  <UP> makes prompt> tail history
  <UP> makes prompt> tail hicat /var/log/pacman.log | grep upgraded
  <UP> makes prompt> tail hicat /var/log/pacman.log
<DOWN> makes prompt> tail hicat /var/log/pacman.log | grep upgraded
<DOWN> makes prompt> tail hitail history
<DOWN> makes prompt> tail hihistory

pressing enter executes the commands as if the artifacts weren't there, but it's super annoying to not know what you're looking at.

as you can see was going through pacman to look for upgrades to bash or ncurses or something, but no such upgrade recently.

here's my .bashrc:

> cat .bashrc
# .bashrc

[ -z "$PS1" ] && return

[ -f ~/.bash_functions ] && source ${HOME}/.bash_functions
[ -f ~/.bash_exports ] && source ${HOME}/.bash_exports
[ -f ~/.bash_alias ] && source ${HOME}/.bash_alias

complete -cf sudo

shopt -s cdspell
shopt -s checkwinsize
shopt -s dotglob

# console colors
if [ "$TERM" = "linux" ]; then
    echo -en "\e]P0222222" #black
    echo -en "\e]P8222222" #darkgrey
    echo -en "\e]P1803232" #darkred
    echo -en "\e]P9982b2b" #red
    echo -en "\e]P25b762f" #darkgreen
    echo -en "\e]PA89b83f" #green
    echo -en "\e]P3aa9943" #brown
    echo -en "\e]PBefef60" #yellow
    echo -en "\e]P4324c80" #darkblue
    echo -en "\e]PC2b4f98" #blue
    echo -en "\e]P5706c9a" #darkmagenta
    echo -en "\e]PD826ab1" #magenta
    echo -en "\e]P692b19e" #darkcyan
    echo -en "\e]PEa1cdcd" #cyan
    echo -en "\e]P7ffffff" #lightgrey
    echo -en "\e]PFdedede" #white
    clear #for background artifacting
fi

# update title bars
case "$TERM" in
  xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\0033]0;${USER}  ${PWD/$HOME/~}\007"'
    ;;
  putty)
    PROMPT_COMMAND='echo -ne "\0033]0;${HOSTNAME}  ${PWD/$HOME/~}\007"'
    ;;
  *)
    ;;
esac

# helping putty with line drawing
if [ "$TERM" = "putty" ]; then
  export LC_ALL=C
  export TERM=rxvt-256color
else
  export LC_ALL=en_US.utf8
fi

# prompt
G="\e[0;32m"
Y="\e[0;33m"
W="\e[0m"

#if [ "$TERM" = "linux" ]; then
#  PS1='[ \u @ \h \W]\$ '
#else
#  PS1="[ ${Y}\A ${W}][ ${G}\w ${W}]\n${Y}> ${W}"
#fi

PS1="[ ${Y}\A ${W}][ ${G}\w ${W}]\n${Y}> ${W}"

.bash_profile just sources .bashrc.  the history related lines in .bash_exports are:

> cat .bash_exports | grep HIST
export HISTIGNORE="&:ls:ll:la:cd:exit:clear"
export HISTSIZE=20000
export HISTFILESIZE=20000
export HISTTIMEFORMAT="[%Y-%m-%d - %H:%M:%S] "

i can post the full .bash_{alias,exports,functions} files as well if you think there might be something in there that would affect this.  there are very few options in there i don't fully understand, but i'd be happy to find some stupid mistake that could easily fix this.

this occurs in xterm and rxvt-unicode.  it does NOT happen when ssh'd in through putty.  and i haven't tested it in a linux console or screen session (but i will soon).  very annoying.

i appreciate any thoughts on this matter.

Last edited by brisbin33 (2009-02-27 15:44:40)

Offline

#2 2009-02-27 14:23:01

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] History acting wierd in bash

OK... so it just started happening to me in putty with TERM=rxvt-256color.  it was not happening yesterday in putty with TERM=xterm.  so i think i've narrowed it down to an rxvt-256color (AUR package) problem.  anyone else experiencing this?

also, once i log in through putty (where TERM=rxvt-256color by default) even if i export a new TERM variable (xterm) it still occurs.  yet, if i log in through putty with TERM=xterm by default... it does not occur.  the _only_ other difference in the two putty sessions would be the translation (ISO for xterm/working and UTF-8 for rxvt/non-working) but i don't see how that could affect the history/prompt situation.

more testing is required...

Offline

#3 2009-02-27 15:06:33

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] History acting wierd in bash

OK.... update 2.  i love when all my guesses/assumptions gradually get more and more wrong.

so, seems it's a prompt issue... go figure

with a fallback prompt, i get no odd behavior:

PS1='[ \u @ \h \w ] \$ '

but with my usual prompt i get the weird history display:

G="\e[0;32m"
Y="\e[0;33m"
W="\e[0m"

PS1="[ ${Y}\A ${W}][ ${G}\w ${W}]\n${Y}> ${W}"

have i typed something wrong there?

Offline

#4 2009-02-27 15:38:58

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] History acting wierd in bash

These threads may apply: (just searching for PS1 in topic titles)
http://bbs.archlinux.org/viewtopic.php?id=56825
http://bbs.archlinux.org/viewtopic.php?id=56917

Offline

#5 2009-02-27 15:44:26

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] History acting wierd in bash

*facepalm*

thank you, apologies for the noob lack-of-searching.

putting \[ \] around any color codes solved it.

Offline

Board footer

Powered by FluxBB