You are not logged in.

#1 2015-09-28 16:31:50

briareos
Member
Registered: 2015-09-28
Posts: 9

VIM-like multi-select CLI interactive filter with range-support

Hi,

I am looking for a simple filter that allows me to select *several* ranges of input lines and print the resulting selection to STDOUT.

Let's say I have 26 lines, contents "a" through "z".

1. I fire up the tool (echo $lines | the_tool).
2. I select line "c" and I select line "e" (effectively marking c, d and e).
3. I select line "m" to "p" (effectively marking m, n, o and p).
4. I hit <ENTER>
5. The tool should now write this to STDOUT:

c
d
e
m
n
o
p

So far, I've looked at tools like fuzzy finders (hf, fzf, ff), pmenu and pencol. Pencol at least offers a multi-select, but navigation is quite cumbersome as each and every item has to be selected separately.

Also, I would like the tool to use VIM-like key binds (hjkl at least). Obviously, the fuzzy-finders occupy these keys for use with  the actual characters.

Main, but not sole use case for this would be to select images. I am using sxiv, but it seems to only allow marking images one-by-one (?)

Any suggestions / ideas welcome!

Last edited by briareos (2015-09-28 16:39:13)

Offline

#2 2015-10-15 12:48:26

balta2ar
Member
From: Russia, Moscow
Registered: 2010-03-23
Posts: 25
Website

Re: VIM-like multi-select CLI interactive filter with range-support

fzf does support multiple selection. Use -m flag.

Offline

#3 2015-10-15 21:01:24

briareos
Member
Registered: 2015-09-28
Posts: 9

Re: VIM-like multi-select CLI interactive filter with range-support

Thanks for the hint. Until I find something with VIM-like key bindings this is a valid solution for my use cases.

Last edited by briareos (2015-10-15 21:05:03)

Offline

#4 2015-10-15 21:11:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,521
Website

Re: VIM-like multi-select CLI interactive filter with range-support

A binding or two in vim would do it.

Just add a binding or function that works like 'd' but instead of deleting it sends the contents to a temp file - for the following examples, say you rebound 'd' to this new action.  So you could go to line 'c', then type 3d, those three lines are added to a tmp file.  Then you go to line m, and maybe use a visual block to select three lines, then hit 'd' and those lines are appened to the tmp file.  When you exit vim, you'd just cat the tmp file.

To make this into a tool like you are asking for, just make a short script that reads it's stdin into one tmp file, runs vim with a custom vimrc (to set this new 'd' binding for example), then cats the new tmp file on exit (and optionally removes the now-uneeded tmp files).

If you include the custom vimrc as a heredocument you can have this all in a single script file.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB