Hi, one last thing I'm missing in my lf configuration is the possibility to set the text of the command line. The most obvious usage would be setting it to :rename (filename) to just quickly change something in a file's name without retyping it as a whole.
Please let me know if this can be done in a simple way or if it's just missing. I didn't manage to do it, sorry.
You probalby looking for push command. It works like this (binding is just example):
map mr push :rename<space>
or If you want to have current file name pushed as well: (see #119 for more details)
map mr ${{lf -remote "send $id push :rename<space>$(basename $f)"}}
@TeddyDD Thanks for the examples. It never occurred to me that this could be possible with remote commands :)
@aidam38 It has been mentioned to me a few times before that ranger's rename function is easier to work with since it automatically adds the current file name to the command line. While @TeddyDD 's solution may work more or less, I think we should make this easier.
I had thought about adding environmental variable completion to solve this issue but I haven't got the chance to work on it yet. Currently it is not possible to use environmental variables as command parameters since $ char interferes with the configuration syntax. Therefore the following does not work unfortunately:
:rename $f.backup
Even if this would work, its use would still be limited. I was thinking, if we could expand the variable before we pass it to the command, we could make it work. So maybe we can check the initial letter of the current word in autocompletion and if the word starts with $ we can trigger an environmental variable expansion. I think this way we should be able to define mappings like the following:
map r push :rename<space>$f<tab>
And then in the command line it should simply show something like:
:rename foo.txt
While @TeddyDD 's solution may work more or less
My solution does not work for files with spaces in names unfortunately :( (at least I can't figure it out).
Variable expansion in commands would be nice but I wonder if it won't be confusing with shell scope. Maybe $ should be changed to other character for shell scopes?
My solution does not work for files with spaces in names unfortunately :( (at least I can't figure it out).
Well you can manually substitute spaces with <space> and add quotes around the filename as the following monstrosity:
map r $lf -remote "send $id push :rename<space>'$(basename $f | sed 's/ /<space>/g')'<left>"
Can you clarify what you mean by shell scopes? An example would be nice if you have.
Cool trick with the remote command, that's exactly what I was looking for.
As for the improvement, I think it would be better if you implemented a function like expand in vim, which, when processing the command would, as it says, would expand anything inside it, it may by lf variables or even enviromental variables. I think that people still may want to use $ in their commands, even though it may be more logical to put them in a separate cmd line.
Thanks @gokcehan it works perfectly!
Can you clarify what you mean by shell scopes?
Everything after $ or inside ${{ }} :) They are called 'prefixes' in docs, I forgot about that. I meant that env variables in commands can be confused with $ prefix commands. For example:
map r push :rename $f.backup
map R $backup $f
$ have two meanings here. It's not problem for the parser I guess, but might be confusing for users.
@gokcehan This is a great tip, - I was looking for such a solution!
map r $lf -remote "send $id push :rename<space>'$(basename $f | sed 's/ /<space>/g')'<left>"
I would suggest we add this tip to default lfrc bindings, good job @gokcehan @TeddyDD
@ipstone It sounds like a good idea to put this to tips wiki so people won't have to hunt issues for such a trick. However, I'm not sure about putting it to the example config. For some reason, I feel like this command is still brittle in some ways. Also we may probably add a builtin rename command soon which would make this example redundant. I agree this trick can always be useful for something else though.
With the new builtin rename command, current file name is already added by default. Closing this issue now.
Most helpful comment
Well you can manually substitute spaces with
<space>and add quotes around the filename as the following monstrosity:Can you clarify what you mean by shell scopes? An example would be nice if you have.