Scrawls from Preston...

Powered by Pelican.

Tue 18 August 2009

Editing long commands

Sometimes you get in a situation where you are editing a long command on the command line and you'd kill to be able to use your mouse to select a word or option in the middle. This tip makes it a pleasure

First for me their was the discovery of cntl-a which jumps one back to the beginning of a line, but just as often I wanted to delete a long path as an opt to a long command.

The first thing is to set your default Editor in your environment variables. I use TextMate - but you could use textwrangler, VI, Emacs.

add a line like this to your ~/.bash_profile

export EDITOR="mate -w"

then close your terminal session or "source ~/.bash_profile"

Now when you are in the middle of typing a long command, or after hitting the up arrow, press cntl-x and hold it, then hit "e"

boom - your current command opens up in your editor, you can use all the features of that editor, and when you save and close that file - the command will be executed back in your shell.

Since I've integrated this tip into my workflow - I find I use it all the time.

Only downside is GUI editors won't work for SSH since you are in the remote hosts env - there is probably a tricky way to reverse-ssh the editor command back to you, but I haven't explored that.


http://ptone.com/dablog