Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently using bash on OSX (via iTerm2). Sometimes I have to run programs with a very lengthy set of command line arguments. If I find that I've mistyped, it takes way too long to arrow back to the mistake and fix it. I know some programs, such as nano, support mouse reporting for cursor positioning. Is this supported by any shells, or (even better) as an option to bash?

share|improve this question

put on hold as off-topic by random 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking product, service, or learning material recommendations are off-topic because they become outdated quickly and attract opinion-based answers. Instead, describe your situation and the specific problem you're trying to solve. Share your research. Here are a few suggestions on how to properly ask this type of question." – random
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
I know that there are zsh scripts that add mouse support, but haven't tried any. – Joe Internet Aug 12 '11 at 14:41
up vote 3 down vote accepted

Sounds like you would benefit from investing a short amount of time in learning some default readline keyboard shortcuts. Note that user606723's answer above gives some basic ones but the Home and Alt+arrow keys do not work on all terminals. Here are a few of the ones I find the following most useful and which also work in more terminals.

(Unless otherwise noted, "word" means an alphanumeric string.)

  • Alt-f: go one word forward.
  • Alt-b: go one word back.
  • Ctrl-a: go to beginning of line
  • Ctrl-e: go to end of line
  • Alt-d: delete to end of word
  • Alt-Backspace: delete to beginning of word
  • Ctrl-w: delete backwards to whitespace
  • Ctrl-y: paste most recently deleted text
  • Ctrl-b, Ctrl-f: move backward/forward one character, equivalent to left and right
  • Ctrl-h, Ctrl-d: equivalent to Backspace and Delete, respectively.

I list the last few because I find them more convenient than reaching for the arrow keys or delete/backspace. You can see how with these basic shortcuts you can do quite a bit of editing rather easily. But there are more:

  • Alt-.: rotate through the last word (white-space delimited) of the previous lines in history. Using it one gets you the last argument of the most recent command you typed.
  • Ctrl-_: undo (incremental)
  • Ctrl-]: search forward for character (like f in vim, but less convenient)
  • Ctrl-r: reverse history search
  • Alt-0...Alt-9: numeric argument to next command. For example if you wanted to delete 4 words: Alt-4Alt-d. Or if you need 1024 A's on the command line for some reason: Alt-1024A.
  • Ctrl-u: delete from cursor position to beginning of line
  • Ctrl-k: delete from cursor position to end of line

And these are just a few of the ones I use - there are many more in the manpage.

share|improve this answer
    
I selected this answer because it's the one I think I will use, but these are all great solutions. Thanks! – John Didion Aug 14 '11 at 12:34

I don't know but ...


History Expansion

to repeat the last command after correcting teh to the

^teh^the^

to repeat the last command that contained the word foo after changing the first occurrence of bar to qax

!?foo?:s/bar/qax/

Line editing

you can use emacs-style editing commands to move quickly through the line.

I prefer vi mode set -o vi which means I can use b and w to move back and forwards a word at a time and use fx to move the cursor to the next occurrence of a specific character x.

share|improve this answer
    
+1 for the regex – Yitzchak Aug 12 '11 at 15:43

GPM (General Purpose Mouse) is a mouse server for the console and xterm

EDIT: Apparently there's also a version 2.

share|improve this answer

This isn't an 'answer', but it is a solution. I am submitting it as an answer because I require the extra room.

Have you tried using a combination of Home and Alt + Left

  • Home - Will take to the front of the command.
  • End - Will take to the end of the command.
  • Alt + Left - Will take you a "word" to the left.
  • Alt + Right - Will take you a "word" to the right.

With these key combos, it should be alot easier to traverse back to your mistake =)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.