Simple, Handy "Edit Output" Script
Sometimes scripts I write to automate my work-flow I’ll use again and again, while others turnout not to be so useful longterm. Recently I wrote a script that I find I’m using repeatedly, so I thought I’d share it.
It’s called edit_output
or eo
for short.
It takes the output of your last command issued on the command line and opens it up in your editor. I find it’s useful when I’d like to copy a part of the output to my clipboard.
“eo
” helps keep my hands on the keyboard and away from the mouse.
How to setup and use
You’ll need iTerm2 (on a Mac) for this to work.
Save the following to the file eo
and put it in a bin
folder that’s in your PATH
.
#!/usr/bin/env osascript
tell application "iTerm2"
tell current session of current window
tell application "System Events" to keystroke "a" using {command down, shift down}
tell application "System Events"
key code 53
end tell
end tell
end tell
tell application "Sublime Text"
activate
end tell
tell application "System Events" to keystroke "n" using {command down}
tell application "System Events" to keystroke "v" using {command down}
return " Last output copied to your editor"
My editor is Sublime Text. If you use a different editor, you’ll need to change the editor specified in the script accordingly.
For me, the path
of the script is:
~/bin/eo
After you save eo
, make it an executable script:
$ chmod +x ~/bin/eo
Test it out
From the command line, type a command that produces output, like the following:
$ ls -al
Then type:
eo
The output of your command should be in your editor.
Enjoy!