6 ms·
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!
- MobiusHorizons 3y agoI typically use fzf for this purpose, and even on some rare occasions vim
- chfritz 3y agofzf looks awesome, thanks for sharing. Didn't know about it. Do you have an example on how you can do this with vim?
- MobiusHorizons 3y agoI 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 3y agoVim 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
- Hello71 3y agowith 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.
- k3vinw 3y agoOof. 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 3y agoThere’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/ https://joeyh.name/code/moreutils/
- LiveTheDream 3y agoSome 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 https://github.com/mooz/percol (also has filtering, use ctrl-space to toggle selection).
- st0le 3y ago`gum choose --no-limit` https://github.com/charmbracelet/gum https://github.com/charmbracelet/gum
- lathiat 3y agoI always find myself needing a tool to interactively let me select which columns of an output to print. Basically I'm interactively writing something like 'awk {print $5, $10}' or whatever but I'm not sure which columns I need. Anyone know anything like that? Ideally after running it'd somehow output which columns they were to use later.
- st0le 3y agoUltimate plumber can do this. https://github.com/akavel/up https://github.com/akavel/up
- renewiltord 3y agoThat'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.
- beembeem 3y agoI'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 3y agoAgreed. Less than 100 lines of code definitely has it's advantages, esp. for people who want to fork and extend it.
- fuzztester 3y ago>Also: please help me come up with a better name! How about isel or iselect, for interactively select?
- eichin 3y agoTo 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...
- ElevenLathe 3y agoSee also: 'vipe' from the excellent 'moreutils' package: https://joeyh.name/code/moreutils/ 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 3y agoWindows/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
- operator-name 3y agoWow! It's a shame that it's GUI only, but really cool to see powershell including all of these nifty functions.
- netmare 3y agoYeah, a text-mode equivalent inside the console would have been much better. Something like the TBrowse system of dBase/Clipper I was using back in the 90s. Ah, the memories...
- jph 3y agoSimilar 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/checkline https://github.com/SixArm/markline https://github.com/SixArm/markline You may also want to know about similar tools such as vipe, peco, percol, canything, zaw, and fzf.
- chfritz 3y agoThanks! 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.