From 4fdf299abb1bec18d75119b894a2a57574fae337 Mon Sep 17 00:00:00 2001 From: KlzXS Date: Fri, 22 Oct 2021 21:09:29 +0200 Subject: [PATCH] Added info about using selection inside prompt. --- Basic-use-cases.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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: