2004-11-11, 01:32(-08), Shankar B:
Quote:> Hi all
> I wonder if there is an easy way to change the position of keyboard
> cursor on the Bash command line by clicking that location with the
> mouse. I use Bash 2.05b and Xterm 4.2.99. The reason I need is that I
> have long command lines like :
> paste -d" " aa bb |grep "N5" | cut -d" " -f8,16 | awk '{print $1-$2}'
>| sort -n | uniq -c | ~/bin/addup
> and I would like to change the cut option 16 to say 15 without using
> the left/right arrows to go to that location. I use such command lines
> as part of some quick and dirty work once in a while and I don't want
> to write shell scripts or anything of that sort.
[...]
In emacs mode
<Ctrl-R>16
will get you to the 16. Also note <Meta-B> to move backward one
word.
In vi mode
<Esc>?16<Cr>
<Esc>b (or B)
are the equivalents
5B to get 5 Words back.
Now, about your mouse question. You could do it with zsh
if [[ $TERM = *xterm* ]]; then
zle-xterm-mouse() {
emulate -L zsh
setopt extendedglob # for (#b)
local bt mx my cx cy i match mbegin mend
read -k bt # mouse button, x, y reported after \e[M
read -k mx
read -k my
[[ $bt = "#" ]] || return 0 # only for btn1 release
print -n '\e[6n' # query cursor position
while read -k i && [[ $i != R ]]; do cx+=$i; done
[[ $cx = (#b)??(*)\;(*) ]] || return
cy=$match[1]
cx=$match[2]
(( CURSOR += #mx - 32 - cx + (#my - 32 - cy) * COLUMNS ))
Quote:}
precmd() {
# enable mouse tracking
print -n '\e[?1000h'
Quote:}
preexec() {
# disable mouse tracking
print -n '\e[?1000l'
Quote:}
zle -N zle-xterm-mouse zle-xterm-mouse
bindkey '\e[M' zle-xterm-mouse
fi
--
Stephane