Running commands on files
Like any decent file manager, fzfm can run any commands you like. It’s easier to describe using examples.
IMPORTANT NOTE: fzfm is written in the fish shell language. It doesn’t have to be your default shell, so alt-s will invoke your shell, not fish. But the commands you run within fzfm (i.e., almost everything described below) will have to be in fish syntax. For simple commands and sequences there is not much difference; only complex commands (if-then-else, tests, etc.), will need care. Or you could just wrap your bash commands in a bash -c '...' :-)
Simple ad hoc commands.
-
:!ncdu -eThis is a command that does not require any file/dir arguments, and so it just runs in the current directory.
-
:!vim %fYou need to select at least one file (using the fzf-standard TAB key) before you type this. Vim will run once, with all your selected files as arguments.
-
:!vim %cAgain, you have to select at least one file using TAB. But this time, vim will run once per file; i.e., if you selected 3 files, vim will run 3 times.
While vim may not be a great example for this, some commands require
%cand can’t be used with%f. For example,tar -tvf %c | lesswould never work if you used%fand you selected multiple files. -
:!mv -v %f %d2; pauseApart from
%cand%f, there are 2 other macros.%d1is replaced by theSTART_DIR, and%d2byALT_DIR. This command moves selected files/dirs to the ALT_DIR, pausing after it is done so you can visually see what it did. (The defaultF6hotkey does exactly this, by the way).Note:
pauseis a fish function provided byfzfmfor convenience. See the Tips, tricks, and traps section for more on this.
You can’t have both %c and %f in the same command, so there’s no
ambiguity.
Command history
But you don’t have to keep re-typing these commands. fzfm has a command
history file ~/.config/fzfm/cmd_hist, which already contains many
commands, and you can add more yourself.
-
ctrl-r, pick command, hit Enter
When you hit ctrl-r, your current file/dir selections are saved, and you see a new fzf window with the contents of the command history file.
Pick one and hit enter. Done
-
ctrl-r, type new command, hit alt-n
This is what you do if the command you want doesn’t exist, and you would like to run it, but also add it to the command history file for later reuse.
If there is already a command that is almost what you want, but not quite, you don’t have to type the whole thing out. Filter or arrow down to the “almost there” command, and hit ctrl-g to “get” that line up to the query area, then edit it as needed before hitting alt-n.
Notes on the command history file:
- Commands are shown in decreasing order of frequency of use (no AI here;
just plain unix commands
sortanduniq). %c,%f,%d1, and%d2work the same as before.- On startup, if the history file does not exist, it is created and populated with a default set of commands. You are free to edit the file to add/change/remove commands, as well as edit the hotkeys and “colon-commands”; see later for more on this.