You are not logged in.

#1 2010-08-20 07:53:18

EvanPurkhiser
Member
From: San Francisco
Registered: 2010-08-17
Posts: 225
Website

Cursor getting stuck in bash terminal

For some reason sometimes my cursor (little blinking text thing, not mouse) will get stuck like so:

I run a command such as

$ rm some/ folders/ -rf

Then end up wanting to go back in history to a previous command, so I hit up till I get to that command in the history, lets say I want to get back too this

$ echo 'hello world'

So I hit up till i get too it and what will sometimes happen is this

$rm someecho 'hello world'

the 'rm some' text will get stuck there and the cursor will always be after it even if I try and delete it. I have to clear the console to fix it.

Its not specific just to the rm command, in fact I'm not entirely sure what is unique about the commands that cause this too happen, its difficult to reproduce as well.

Any Idea why this may be happening?

here's my .bashrc

PS1='[\e[0;34m${PWD##*/}/\e[0m]> '

# add my bin to the path
PATH=$PATH:~/bin

# bash options
shopt -s cdspell          # autocorrects cd misspellings
shopt -s checkwinsize     # update the value of LINES and COLUMNS after each command if altered
shopt -s cmdhist          # save multi-line commands in history as single line
shopt -s dotglob          # include dotfiles in pathname expansion
shopt -s expand_aliases   # expand aliases
shopt -s extglob          # enable extended pattern-matching features
shopt -s nocaseglob       # pathname expansion will be treated as case-insensitive

# define 1st and 2nd choice editors and pagers
export EDITOR=vim
export PAGER=/bin/more

# bash sudo completion
complete -cf sudo
if [ -f /etc/bash_completion ]; then
  . /etc/bash_completion
fi

# aliases
alias hist='history | grep $1'            # search cmd history
alias cp="cp -i"                          # confirm before overwriting something
alias df='df -h'                          # human-readable sizes
alias du='du -h'                          # human-readable sizes
alias free='free -m'                      # show sizes in MB
alias ls='ls --color=auto -F'             # colourized list
alias ll='ls -lh'                         # list detailed with human-readable sizes
alias la='ls -a'                          # list all files
alias f='find | grep'                     # quick search
alias c='clear'                           # clear screen
alias vi='vim'                            # always use vim
alias svim='sudo vim'                     # lazy
alias sps='ps aux | grep -v grep | grep'  # search process
alias grep='grep --color=auto'            # colourized grep
alias top='htop'                          # replace top
alias shutdown='sudo shutdown -h now'     # shutdown
alias reboot='sudo reboot'                # reboot

# For the lulz
alias backtrace='traceroute'

# pacman aliases
alias pacup='sudo pacman -Syu'            # sync and update
alias pacin='sudo pacman -S'              # install pkg
alias pacout='sudo pacman -Rns'           # remove pkg and the deps it installed
alias pacs="pacman -Sl | cut -d' ' -f2 | grep " #
alias pac="pacsearch"                     # colorize pacman (pacs)
pacsearch () 
{
  echo -e "$(pacman -Ss $@ | sed \
  -e 's#core/.*#\\033[1;31m&\\033[0;37m#g' \
  -e 's#extra/.*#\\033[0;32m&\\033[0;37m#g' \
  -e 's#community/.*#\\033[1;35m&\\033[0;37m#g' \
  -e 's#^.*/.* [0-9].*#\\033[0;36m&\\033[0;37m#g' )"
}


# nohup - run command detached from terminal and without output
# usage: nh <command>
nh()
{
  nohup "$@" &>/dev/null &
}

# ex - archive extractor
# usage: ex <file>
ex ()
{
  if [ -f $1 ] ; then
    case $1 in
      *.tar.bz2)   tar xjf $1   ;;
      *.tar.gz)    tar xzf $1   ;;
      *.bz2)       bunzip2 $1   ;;
      *.gz)        gunzip $1    ;;
      *.tar)       tar xf $1    ;;
      *.tbz2)      tar xjf $1   ;;
      *.tgz)       tar xzf $1   ;;
      *.zip)       unzip $1     ;;
      *.Z)         uncompress $1;;
      *)           echo "'$1' cannot be extracted via ex()" ;;
    esac
  else
    echo "'$1' is not a valid file"
  fi
}

# roll - archive wrapper
# usage: roll <foo.tar.gz> ./foo ./bar
roll ()
{
  FILE=$1
  case $FILE in
    *.tar.bz2) shift && tar cjf $FILE $* ;;
    *.tar.gz) shift && tar czf $FILE $* ;;
    *.tgz) shift && tar czf $FILE $* ;;
    *.zip) shift && zip $FILE $* ;;
  esac
}

# mktar - tarball wrapper
# usage: mktar <filename | dirname>
function mktar() { tar czf "${1%%/}.tar.gz" "${1%%/}/"; }

# calc - simple calculator
# usage: calc <equation>
function calc() { echo "$*" | bc; }

# define - fetch word defnition from google
# usage: define <word>
define ()
{
  lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}&btnG=Google+Search" | grep -m 5 -w "*"  | sed 's/;/ -/g' | cut -d- -f5 > /tmp/templookup.txt
  if [[ -s  /tmp/templookup.txt ]] ;then    
    until ! read response
      do
      echo "${response}"
      done < /tmp/templookup.txt
    else
      echo "Sorry $USER, I can't find the term \"${1} \""                
  fi    
  rm -f /tmp/templookup.txt
}

# start, stop, restart, reload - simple daemon management
# usage: start <daemon-name>
start()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg start
  done
}
stop()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg stop
  done
}
restart()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg restart
  done
}
reload()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg reload
  done
}

Last edited by EvanPurkhiser (2010-08-20 08:02:42)

Offline

#2 2010-08-20 08:21:28

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Cursor getting stuck in bash terminal

This is likely to be a terminal specific issue. What is your terminal application (xterm, urxvt, etc.)?

Also, it's quite likely that the spurious text will be seen by the shell - you can test this by running a command when it's there. You may not want to test it with a rm command though wink
I sometimes get it (urxvtc) when exiting out of stuff like most or other apps that take over the whole terminal display, or when the terminal resizes. It's normally just the terminal not clearing the display properly - hence why clearing the terminal fixes it. That said I can see why it an be annoying and you want to fix it.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#3 2010-08-20 08:39:11

EvanPurkhiser
Member
From: San Francisco
Registered: 2010-08-17
Posts: 225
Website

Re: Cursor getting stuck in bash terminal

Sorry should have mentioned what terminal I am using in my first post. I am using urxvt

However the surprise text is NOT seen my the shell. If I run a command with the extra text there it will run fine, after I run it the prompt is fixed, but if I go up in history and pass the command that causes the cursor to get stuck it will happen again.

Offline

#4 2010-08-20 09:03:14

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Cursor getting stuck in bash terminal

Okay, I've only seen this with urxvt in the cases I mention above so:

1) What's your window manager?
2) Does the terminal move, resize, etc. at all?
3) Do you get it if you search the history (CTRL+r the type part of the command)?
4) What's the commandline you use to start urxvt?
5) Can you post your .Xdefaults?
6) Is there any consistency in the spurious text (eg no. of characters, always up to a certain character, etc.)?


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#5 2010-08-20 09:09:00

pseup
Member
Registered: 2008-06-06
Posts: 103

Re: Cursor getting stuck in bash terminal

The escapes in your PS1 are incomplete.

PS1='[\e[0;34m${PWD##*/}/\e[0m]> '
Should be:
PS1='[\[\e[0;34m\]${PWD##*/}/\[\e[0m\]]> '

Offline

#6 2010-08-20 09:15:49

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Cursor getting stuck in bash terminal

pseup wrote:

The escapes in your PS1 are incomplete.

PS1='[\e[0;34m${PWD##*/}/\e[0m]> '
Should be:
PS1='[\[\e[0;34m\]${PWD##*/}/\[\e[0m\]]> '

Ha yeah, good catch.
The prompt was why I asked Q5, but then forgot to go and look at it, sorry. roll
Need another coffee. neutral


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#7 2010-08-20 09:27:40

EvanPurkhiser
Member
From: San Francisco
Registered: 2010-08-17
Posts: 225
Website

Re: Cursor getting stuck in bash terminal

Thanks guys!

I changed my PS1 to escape all non printing characters, this was most likely the problem.

I'll report back if it occurs again.

Offline

Board footer

Powered by FluxBB