Friday, November 11, 2016

Word.

I hate the mouse, so it makes sense that I would especially hate copying and pasting from the command line. I usually just need one word of screen output to go about my business and do what I need to do, but this requires activating the control box (Alt+Space), activating the Edit menu, activating the Mark command and then dragging the cursor over the text of interest. Woe be to me if I screw up the text selection, because then I get to start all over again. And then there's when Windows doesn't respond consistently to the Alt+Space keystrokes I'm sending in order to activate the control box (yes, this happens; no, it's not human error).

I hate this so much that I wrote a pair of programs (line and word) to resolve it. Here are three examples of using them: getting all IP addresses, copying one of several paths to the clipboard, and isolating a filename in a paragraph of output.


If you invoke line or word without an argument, it will print the output with line numbers. An argument will isolate the lines or words you specify. Word accepts negative indices like Python. Line does not, because I didn't want to hog memory reading all of stdin into a buffer, though it wouldn't be hard to add, and it's not unreasonable since this is mostly for use with small buffers. Neither program accepts ranges, because I didn't have lots of time to spend.

You can get the code here: https://github.com/strictlymike/pipe-slice

3 comments:

  1. This is why I run shells out of emacs.

    ReplyDelete
    Replies
    1. That's interesting. I always wanted to learn Emacs, but after I invested the time in Vim, I had less reward waiting for me for learning to use Emacs (I already know one programmer's editor) and some of the chords requiring multiple keys were a bit arduous. But I still look on with wonder and curiosity when I see an experienced colleague bust out Emacs.

      Delete
    2. I use evil-mode. All that vim knowledge isn't wasted then! And you can avoid the awkward key bindings with something like Spacemacs.

      Delete