Xterm + Bash + Long command lines

Xterm + Bash + Long command lines

Post by Bit Twiste » Fri, 12 Nov 2004 18:48:32




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 :

I have heard if you set VISUAL to say emacs you can use the emacs
commands for navigation.

export VISUAL=emacs

Things like
       Control r  to search for a command in history
       Control a to get to start of line
       Alt f move forward a word

 
 
 

Xterm + Bash + Long command lines

Post by John » Fri, 12 Nov 2004 20:24:43



> 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.

You can use emacs or vi commands to navigate and edit command lines
(and shell histories).

By default, bash uses emacs commands but you can select vi mode by
    set -o vi
or by invoking it as
    bash -o vi
and change back by set -o emacs (and so on). See the bash manual page,
particularly the READLINE section.

--
John.

 
 
 

Xterm + Bash + Long command lines

Post by Stephane CHAZELA » Fri, 12 Nov 2004 20:46:33


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

 
 
 

Xterm + Bash + Long command lines

Post by Carl Holtje ;021;vcsg6 » Fri, 12 Nov 2004 21:40:35



> 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.

$> paste -d" " aa bb |grep "N5" ...
$> ^16^15

Will replace the instance of '16' with '15' and re-execute the command.

Hope it helps!

Carl

- --

"There are 10 types of people in the world: Those who understand binary
and those that don't."

 
 
 

Xterm + Bash + Long command lines

Post by William Par » Sat, 13 Nov 2004 00:24:56



> 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.

set -o vi
<Esc>f,cw15<Enter>
 
 
 

Xterm + Bash + Long command lines

Post by Stephane CHAZELA » Sat, 13 Nov 2004 18:28:04


2004-11-11, 12:56(-08), Shankar B:
[...]
Quote:> Thanks for your zsh suggestion. I will try it out sometime.

[...]

Note it is being discussed in the zsh-users mailing list, with
the zsh developpers helping to improve it. I shall post a
solution once we've reach a stable one.

So far, support for multi-line and copy/pasting of zsh killring
have been added.

See:

http://www.zsh.org/mla/users/2004/index.html

--
Stephane

 
 
 

Xterm + Bash + Long command lines

Post by Stephane CHAZELA » Fri, 19 Nov 2004 21:50:56


2004-11-12, 09:28(+00), Stephane CHAZELAS:
Quote:> 2004-11-11, 12:56(-08), Shankar B:
> [...]
>> Thanks for your zsh suggestion. I will try it out sometime.
> [...]

> Note it is being discussed in the zsh-users mailing list, with
> the zsh developpers helping to improve it. I shall post a
> solution once we've reach a stable one.

[...]

It may not be much stable, but it has had a lot of improvements.
http://stchaz.free.fr/mouse.zsh provides mouse support for the
Z-shell.

Supported:

- VT200/xterm/gnome-terminal/rxvt like mouse tracking (need to
  toggle mouse support).
- Wheel-mouse in xterm by adding a X resource
- having the mouse support only shile holding a modifier key
  (such as Alt or Windows) for xterm
- NEW: GPM mouse support on Linux consoles

How to use:

- see the comments at the beginning of the file

Hope this helps
Stephane