0

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.

Joel Sahlin
  • 51
  • 1
  • 7
  • Environment changes are not propagated to a parent shell, so even if it was such a variable, after exiting the file browser, it would have been gone. – choroba Nov 29 '22 at 09:54
  • Sure that's true, but I was sort of hoping it could have been a global variable, or at least maybe created by the parent shell, but that doesn't seem to be the case here. – Joel Sahlin Nov 29 '22 at 09:58
  • Also note that brace expansion in the shell happens before variable expansion, so using variables in curlies doesn't work. – choroba Nov 29 '22 at 10:04
  • Moreover, if you can `read` the directory name, why can't you `read` the number, too? – choroba Nov 29 '22 at 10:05
  • After reading your answer again I realized I might have misunderstood you. Are you saying that even if it was a variable created by the parent shell, or a global one for that matter, any changes to it would be reverted after closing the child shell? Because in that case it might still be one of the variables listed by the "set" command that is used by Lf. – Joel Sahlin Nov 29 '22 at 10:06
  • The number is an input you type before the actual command. I wouldn't want the function to always make 20 directories every time so I need to find that variable somehow. – Joel Sahlin Nov 29 '22 at 10:10
  • I realized I might have misunderstood you on your second point as well :D I apologize. So the reason why I don't want to `read` the number is because I want consistency on how inputs are made. I guess it's possible to have 2 prompts as a workaround. One to specify the name, and then one for number of repetitions, but this seems redundant when the feature is already built in the core program. – Joel Sahlin Nov 29 '22 at 10:19
  • If I understand you correctly, your question is about writing the configuration file for a file browser called `If`. I then don't see why the question is tagged _bash_. Also, the tags _terminal_ and _scope_ don't look meaningful here and I suggest that you remove them. Configuring software (such as your file browser) should be asked in [su], not in Stackoverflow. Just out of curiousity: Can you provide a link to this browser? I have never heard of it, and google did not bring up anything for "If file browser". – user1934428 Nov 29 '22 at 11:42
  • It's LF not IF. It's a file browser intended for terminals and I use bash, so that's why those flags are relevant. Here is a link: https://github.com/gokcehan/lf – Joel Sahlin Nov 29 '22 at 11:59

1 Answers1

0

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.

Joel Sahlin
  • 51
  • 1
  • 7