Edit ~/.config/ranger/commands.py
to contain something like:
from ranger.api.commands import * class newcmd(Command): def execute(self): if not self.arg(1): self.fm.notify('Wrong number of arguments', bad=True) return # First argument. 0 is the command name. self.fm.notify(self.arg(1)) # Current directory to status line. self.fm.notify(self.fm.thisdir) # Run a shell command. self.fm.run(['touch', 'newfile')
Now you can type:
:newcmd myarg
to run the defined command.
More options can be found at: https://github.com/hut/ranger/blob/9c585e48e14525f11d2405ea0bb9b5eba92e63e9/ranger/config/commands.py
You can then go one step further and define a map for it, e.g.: add to ~/.config/ranger/rc.conf
:
map ,n console newcmd map ,m newcmd default-arg
And now you can just type:
,n
to writenewcmd
on the status line, and get ready for the user to input the first argument,m
and run the command immediately with a default argument
Tested on ranger 1.6.1.