Open mohkale opened 4 years ago
Here's what i use:
cmd SelRecurs %{{
IFS=$'\n'
[[ ! -d $f ]] && exit 0
for d in $(find $f -type d); do
lf -remote "send $id select '$d'"$'\n'\
\ \ \ "send $id open"$'\n'\
\ \ \ "send $id invert"
done
lf -remote "send $id select '$f'"
}}
This selectes every subdirectory of the selected directory, enters it selects (actually toggles selection on) everything inside that (and then repeat to a next one, if there is any).
(The IFS=$'\n'
is used because I use the default ifs
value "\n"
)
It have worked for me very well for what I use it and it seems to be effective even for directories with too many subdirectories.
You can modify it to fit your needs.
@mohkale Easiest way to fix this would be to add recursive capabilities to our current glob-select
command as you mention much like globstar in bash.
It'd be nice if we could simply use :glob-select */*
. That way, at least for simple cases, we could specify how many directories deep it should be able to go.
:glob-select */*
selects all directories at depth 2:glob-select */*/*
selects all directories at depth 3:glob-select */*/*/*
selects all directories at depth 4
...I'm not sure how useful :glob-select **/*
would be in practice.
@mohkale I'm hesitant to add a custom syntax for this purpose. Is it used somewhere?
I've never seen something like this explicitly demonstrated, but I believe its the expected behavior with globs. It seems to work in:
Dir.glob('*/*')
from pathlib import Path as p; list(p('.').glob('*/*'))
var glob = require("glob"); g.glob('*/*', {}, function(err, files) { console.log(files) })
I presume if you allow recursive globs than globs like this will also be enabled, but I'm not at all familiar with golang so I can't say for sure.
@mohkale So then it is used somewhere. I also realized this already works in Go as well. But we're using the base name of a file in glob-select
implementation and we only check the files in the current directory. We need to walk the directory to implement this though we should somehow do this efficiently in a smart way. It may be a little tricky to implement.
The flat
command in ranger
is very useful, not only for selecting files but also to open them or just to have a glimpse of them. If you have a flat
command, you can do many things.
If you only modify `glob-select`, you can only... select files ;-)
Today I had a simple problem. I wanted to select all files at depth 2.
eg.
but lf doesn't seem to support recursive globs I.E.
:glob-select **/*
. In ranger I'd normally do:flat 0
and then filter out directories so I can select the files, butlf
doesn't have that feature yet so is there another recommended way?I tried the subprocess approach:
but that spawns a tonne of lf processes and seems to hang indefinitely if you try to do too many files at once.