[HN Gopher] Show HN: LineSelect, shell utility to interactively ...
       ___________________________________________________________________
        
       Show HN: LineSelect, shell utility to interactively select lines in
       a pipeline
        
       Allows you to "pause" a shell pipeline to interactively select a
       subset of lines to proceed with. I've always wanted a tool like
       this, as it effectively combines the best of shell pipes (easy to
       automate) and visual file managers (easy to make selections). Now
       that I have it I can't believe a tool like this is not already part
       of the standard set of shell utilities. There are so many
       situations where it is useful.  Tested on Linux but should also
       work on MacOS.  Also: please help me come up with a better name!
        
       Author : chfritz
       Score  : 41 points
       Date   : 2023-07-05 16:16 UTC (6 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | LiveTheDream wrote:
       | Some other options:
       | 
       | 1. Piping into `fzf -m` (use tab to toggle selections and built-
       | in search to filter options).
       | 
       | 2. Percol https://github.com/mooz/percol (also has filtering, use
       | ctrl-space to toggle selection).
        
         | st0le wrote:
         | `gum choose --no-limit`
         | 
         | https://github.com/charmbracelet/gum
        
       | beembeem wrote:
       | I'm definitely going to try this, but oy javascript. It's
       | probably the reason this can be written with so little code but I
       | would prefer a native binary that doesn't have the npm
       | dependency.
        
         | chfritz wrote:
         | Agreed. Less than 100 lines of code definitely has it's
         | advantages, esp. for people who want to fork and extend it.
        
       | ElevenLathe wrote:
       | See also: 'vipe' from the excellent 'moreutils' package:
       | https://joeyh.name/code/moreutils/
       | 
       | There are some other gems in this package. The ones I find myself
       | using regularly are 'ts' and 'sponge' but I'm sure the useful
       | subset depends a lot on the kind of work you are doing
        
       | netmare wrote:
       | Windows/PowerShell users should know there's a builtin cmdlet for
       | this, Out-GridView. I mention this because I've used it for
       | viewing objects in tabular form long before I realized it allows
       | interactive selection. For example, selecting desktop files to
       | delete:                   Get-ChildItem -File ~\desktop | Out-
       | GridView -PassThru | Remove-Item
       | 
       | or using aliases:                   ls -file ~\desktop | ogv
       | -pass | ri
        
       | MobiusHorizons wrote:
       | I typically use fzf for this purpose, and even on some rare
       | occasions vim
        
         | chfritz wrote:
         | fzf looks awesome, thanks for sharing. Didn't know about it. Do
         | you have an example on how you can do this with vim?
        
           | MobiusHorizons wrote:
           | I used it in a shell script with a temp file. You could
           | pretty easily write a shell script for this behavior though
           | to be used in a pipeline                 #!/bin/sh
           | TEMP="$(mktmp)"       cat > "$TEMP"       $EDITOR "$TEMP"
           | cat "$TEMP"
        
           | k3vinw wrote:
           | Vim command has a '-' argument which instructs it to read
           | from standard input. Here's an example of interactively
           | selecting files to delete in the current directory: find .
           | -type f -name *.txt | vim - | xargs rm
        
             | k3vinw wrote:
             | Oof. Should have tried this one first before posting. The
             | tricky part of this is that reading from standard input
             | implies non-interactive mode.
             | 
             | Not as succinct but you can still pipe your output to vim,
             | make your edits, run :w vimpipe to save your edits, and
             | pipe the output of your vimpipe file to another command.
             | 
             | find . -type f -name \\.txt | vim -; cat vimpipe | xargs rm
        
               | k3vinw wrote:
               | There's also an existing command line utility for this
               | called vipe which I've always wanted to try, but never
               | got around too. It's part of moreutils:
               | https://joeyh.name/code/moreutils/
        
             | Hello71 wrote:
             | with seq 1 10 | vim - | cat > x, I get "Vim: Warning:
             | Output is not to a terminal" and the pipeline appears to
             | hang, but actually the output is going to "x". In other
             | words, your command deletes some unknown files depending on
             | your terminal setup.
        
       | renewiltord wrote:
       | That's a really cool use of a tool. I like it very much. I'll
       | probably use `fzf -m` for it, but thank you for the idea of
       | putting it in the middle of a pipeline which I don't use fzf for
       | enough in my interactive shell use.
        
       | jph wrote:
       | Similar Rust tools are checkline (checkbox line picker for stdin)
       | and markline (markable line picker for stdin). I'm the dev.
       | 
       | https://github.com/SixArm/checkline
       | 
       | https://github.com/SixArm/markline
       | 
       | You may also want to know about similar tools such as vipe, peco,
       | percol, canything, zaw, and fzf.
        
         | chfritz wrote:
         | Thanks! I've just looked at each of them and tested some. I
         | think peco is the best one (and better than mine). Way bigger
         | code base, but probably worth it.
        
       | fuzztester wrote:
       | >Also: please help me come up with a better name!
       | 
       | How about isel or iselect, for interactively select?
        
         | dymk wrote:
         | "insel", interactive select
        
         | eichin wrote:
         | http://www.ossp.org/pkg/tool/iselect/ (already packaged in
         | debian and ubuntu)
        
       | eichin wrote:
       | To get retro, "whiptail" has been around forever (newt, or
       | dialog) but that ends up with more horrible incantations like
       | "whiptail --menu $(seq 1 10 | while read x; do echo $x $x; done)"
       | - though whiptail does get you more options, like
       | radiobox/checkbox instead of just menu, if you want multiple
       | select - the focus is on text-ui for a user to select things that
       | _happens_ to produce an output, so it has lots of options for
       | customization of screen layout rather than just being the kind of
       | basic line-picker that you 'd actually want day-to-day...
        
       ___________________________________________________________________
       (page generated 2023-07-05 23:02 UTC)