diff --git a/Basic-use-cases.md b/Basic-use-cases.md index cbbdc6e..726efdf 100644 --- a/Basic-use-cases.md +++ b/Basic-use-cases.md @@ -225,6 +225,28 @@ if [[ -n $DISPLAY ]]; then fi ``` +#### Executing a command for each file in selection + +While in the prompt you are able to execute a command with each item from the selection as its arguments. Etiher one by one or all at once. + +To execute a command on a per file basis place `%j` where the file path should be placed. The following example searches for a string in each file. + +```sh +printf "Searching for string in %s\n" "%j"; grep "string" "%j" +``` + +To execute a command with the entire selection as arguments place `%J` where the file paths should be placed. The following example updates a tar archive with the entire selection. + +```sh +tar uvf archive.tar %J +``` + +There are some limitations when using `%j` and `%J`: +* You can use multiple `%j` inside a single command. +* You can only use one `%J` inside a single command. If multiple `%J` are used only the last one will be replaced with the selection. +* You can only use either `%j` or `%J` inside a single command. If both are encountered the prompt will close. No command will be executed. +* When using `%J` `nnn` won't quote the file paths from selection. Quoting `%J` will just place quotes around the entire selection, it won't quote each item individually. + #### Shell depth indicator If you use `!` to spawn a shell in the current directory and your shell is bash or zsh, it could be nice to add: