CLI tool to graphically select lines during piped commands

0

Is there a tool similar to choose that I can plug into chain of commands that will let me select (multiple) lines for the next step?

choose unfortunately doesn't "pass on" the line you select, instead if you do a command, select a line and try to do something with it, what you get is:

% echo "a\tb\ncde\tf" | choose | wc
cde      f
       0       0       0

Orangenhain

Posted 2014-04-16T21:31:53.577

Reputation: 653

There's also a completely shell based solution to this problem (currently only single line select as well): Sentaku

– Orangenhain – 2014-04-30T16:11:08.273

Answers

1

It's open source, and the basic logic isn't very complicated, so you could always just modify it.

Put the following lines into a file (say, choose.diff) in the same directory as choose, then run patch -p1 < choose.diff:

--- a/choose
+++ b/choose
@@ -164,8 +164,8 @@ def do_it(auswahl):
     index = select_entry(auswahl,
                          header_text=u'Navigate by pressing ↑ and ↓, select by pressing Enter')

-    # print chosen string
-    print(orig_auswahl[index])
+    # return chosen string
+    return orig_auswahl[index]


 if __name__=="__main__":
@@ -179,7 +179,7 @@ if __name__=="__main__":
     sys.__stdin__ = sys.stdin = open('/dev/tty')
     os.dup2(sys.stdin.fileno(), 0)

-    do_it(auswahl)
+    choice = do_it(auswahl)

     #restore old stdout
     sys.stdout.flush()
@@ -190,3 +190,5 @@ if __name__=="__main__":
     sys.__stdout__ = sys.stdout = old_out
     sys.__stdin__ = sys.stdin = old_in
     sys.__stderr__ = sys.stderr = old_err
+
+    print choice

jjlin

Posted 2014-04-16T21:31:53.577

Reputation: 12 964

Thanks! And by combining this with the browse.py example code in the urwid repository, I was also able to get multi-select.

– Orangenhain – 2014-04-17T22:39:38.983

0

Not sure this suits you, but if it's about selecting lines from a stream of text, sed should always sort you out. Check the examples below:

I want to output only those lines not matching a certain regular expression (regex) - in this example, omit all lines containing the word "pipe".

$> echo -e "this is a line\nthat is a line\nthis is a piped line\nthat is a line in a pipe" | sed '/pipe/d'
this is a line
that is a line

In the next one, output only those lines containing the word "pipe"

$> echo -e "this is a line\nthat is a line\nthis is a piped line\nthat is a line in a pipe" | sed '/pipe/!d'
this is a piped line
that is a line in a pipe

Alternatively, ouput only the 2nd and 3rd lines:

$> echo -e "this is a line\nthat is a line\nthis is a piped line\nthat is a line in a pipe" | sed -n '2,3p'
that is a line
this is a piped line

And many more examples and possibilites... Check out sed1line

Definitely, there are many more capable alternatives too, awk, perl, etc

nemesisfixx

Posted 2014-04-16T21:31:53.577

Reputation: 2 811