bashterminalscopefile-browser

How to access the repeat variable in lf file browser?


In lf file browser, if I for example press "4" and "j", the file browser jumps 4 steps down from the selected file to select another file 4 steps below, just like moving the cursor in vi.

Now if I want to create a directory I can map the following to a key in my lfrc:

cmd mkdir %{{
    printf "Name New Directory: "
    read latestdir
    mkdir -p $latestdir
}}

map o mkdir

So far so good.

Now however I want to be able to create multiple directories at once, lets say 20 directories. If I press "20" and "o" I assume one of two things happens. Either the 20 part of the input gets ignored completely and only one directory is created, or the directory gets created once and then overwritten 19 times. Neither is what I want.

I can create multiple directories in the shell like so:

mkdir DirName{1..20}

To do so in my lfrc I need to be able to access the "20" part of the input through some sort of variable so I can type any number I want whenever I need to make multiple dirs or files etc. I guess it would look something like this:

cmd mkdir %{{
    printf "Name New Directory: "
    read latestdir
    mkdir -p "$latestdir{1..$somevariable}"
}}

What is this variable called in lf and how do I access it?

I Read through the documentation and expected to find the variable mentioned somewhere. Couldn't find any mentioning of the feature of "inputting a number before doing a command" at all.

I have watched multiple youtube videos of people explaining features in the lf file browser, how to make scripts for lf etc. and nobody mentioned how to access this variable.

I don't think it's an environment variable, since after doing "15" "j" and exiting lf,

set | grep 15

gives no output. I assume it is a local variable for lf only, or if it is an environment variable it must be a temporary one that overwrites after using.


Solution

  • After asking the same question on the projects github page, it turned out that the source code didn't export the variable to make it accessible for usage in custom shell functions. However a suggestion on how to modify the source was provided, and as of V29 of lf, it will be available straight out of the box. The variable is named $lf_count.

    The current version of lf as of providing this answer is still V28, so you will have to build from source to make it work.