From: Arun Prakash Jana Date: Sun, 6 Jun 2021 13:07:49 +0000 (+0530) Subject: NNN_PLUG: use ! as run-cmd-as-plugin symbol (earlier _) X-Git-Tag: v4.2~111 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=9de941306c77dd61b28d71280314cd16ee894d8c;p=nnn.git NNN_PLUG: use ! as run-cmd-as-plugin symbol (earlier _) --- diff --git a/nnn.1 b/nnn.1 index a0a4b52e..236d16a2 100644 --- a/nnn.1 +++ b/nnn.1 @@ -382,14 +382,14 @@ separated by \fI;\fR: 2. Alternatively, combine with \fIAlt\fR (i.e. \fIAlt+key\fR). 3. To skip directory refresh after running a plugin, prefix with \fB-\fR. - export NNN_PLUG='m:-mediainf' + export NNN_PLUG='p:-plugin' .Ed .Pp To assign keys to arbitrary non-background non-shell-interpreted cli - commands and invoke like plugins, add \fI_\fR (underscore) before the + commands and invoke like plugins, add \fI!\fR (underscore) before the command. .Bd -literal - export NNN_PLUG='x:_chmod +x $nnn;g:_git log;s:_smplayer $nnn' + export NNN_PLUG='x:!chmod +x $nnn;g:!git log;s:!smplayer $nnn' To pick and run an unassigned plugin, press \fBEnter\fR at the plugin prompt. To run a plugin at startup, use the option `-P` followed by the plugin key. @@ -397,31 +397,31 @@ separated by \fI;\fR: NOTES: 1. Use single quotes for $NNN_PLUG so $nnn is not interpreted 2. $nnn should be the last argument (IF used) - 3. (Again) add \fB_\fR before the command + 3. (Again) add \fB!\fR before the command 4. To disable directory refresh after running a \fIcommand as plugin\fR, - prefix with \fB-_\fR + prefix with \fB-!\fR 5. To skip user confirmation after command execution, suffix with \fB*\fR Note: Do not use \fB*\fR with programs those run and exit e.g. cat - export NNN_PLUG='y:-_sync*' + export NNN_PLUG='y:-!sync*' - 6. To run a \fIGUI app as plugin\fR, add a \fB|\fR after \fB_\fR + 6. To run a \fIGUI app as plugin\fR, add a \fB|\fR after \fB!\fR - export NNN_PLUG='m:-_|mousepad $nnn' + export NNN_PLUG='m:-!|mousepad $nnn' EXAMPLES: ----------------------------------- + ------------------------------------------------- Key:Command | Description ----------------------------------- + ------------------------------------------------- - g:-_git diff | Show git diff - h:-_hx $nnn* | Open hovered file in hx hex editor - k:-_fuser -kiv $nnn* | Interactively kill process(es) using hovered file - l:-_git log | Show git log - n:-_vi /home/user/Dropbox/dir/note* | Take quick notes in a synced file/dir of notes - p:-_less -iR $nnn* | Page through hovered file in less - s:-_|smplayer -minigui $nnn | Play hovered media file, even unfinished download - x:_chmod +x $nnn | Make the hovered file executable - y:-_sync* | Flush cached writes + g:-!git diff | Show git diff + h:-!hx $nnn* | Open hovered file in hx hex editor + k:-!fuser -kiv $nnn* | Interactively kill process(es) using hovered file + l:-!git log | Show git log + n:-!vi /home/user/Dropbox/dir/note* | Take quick notes in a synced file/dir of notes + p:-!less -iR $nnn* | Page through hovered file in less + s:-!|smplayer -minigui $nnn | Play hovered media file, even unfinished download + x:!chmod +x $nnn | Make the hovered file executable + y:-!sync* | Flush cached writes ----------------------------------- + ------------------------------------------------- Online docs: https://github.com/jarun/nnn/tree/master/plugins diff --git a/plugins/README.md b/plugins/README.md index b3414d90..4cb39ba2 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -100,7 +100,7 @@ If the plugins list gets too long, try breaking them up into sections: ``` NNN_PLUG_PERSONAL='g:personal/convert2zoom;p:personal/echo' NNN_PLUG_WORK='j:work/prettyjson;d:work/foobar' -NNN_PLUG_INLINE='e:_go run $nnn*' +NNN_PLUG_INLINE='e:!go run $nnn*' NNN_PLUG_DEFAULT='1:bookmarks;2:ipinfo;p:preview-tui;o:fzz;b:nbak' NNN_PLUG="$NNN_PLUG_PERSONAL;$NNN_PLUG_WORK;$NNN_PLUG_DEFAULT;$NNN_PLUG_INLINE" export NNN_PLUG @@ -114,22 +114,20 @@ Note: #### Skip directory refresh after running a plugin -`nnn` refreshes the directory after running a plugin to reflect any changes by the plugin. To disable this (say while running the `mediainf` plugin on some filtered files), add a `-` before the plugin name: +`nnn` refreshes the directory after running a plugin to reflect any changes by the plugin. To disable this add a `-` before the plugin name: ```sh -export NNN_PLUG='m:-mediainf' +export NNN_PLUG='p:-plugin' ``` -Now `nnn` will not refresh the directory after running the `mediainf` plugin. - ## Running commands as plugin -To assign keys to arbitrary non-background, non-shell-interpreted cli commands and invoke like plugins, add `_` (underscore) before the command. +To assign keys to arbitrary non-background, non-shell-interpreted cli commands and invoke like plugins, add `!` (underscore) before the command. For example: ```sh -export NNN_PLUG='x:_chmod +x $nnn;g:_git log;s:_smplayer $nnn' +export NNN_PLUG='x:!chmod +x $nnn;g:!git log;s:!smplayer $nnn' ``` Now ;x can be used to make a file executable, ;g can be used to the git log of a git project directory, ;s can be used to preview a partially downloaded media file. @@ -139,7 +137,7 @@ Now ;x can be used to make a file executable, ;g can be us `nnn` waits for user confirmation (the prompt `Press Enter to continue`) after it executes a command as plugin (unlike plugins which can add a `read` to wait). To skip this, add a `*` after the command. For example: ```sh -export NNN_PLUG='s:_smplayer $nnn*;n:-_vim /home/vaio/Dropbox/Public/synced_note*' +export NNN_PLUG='s:!smplayer $nnn*;n:-!vim /home/vaio/Dropbox/Public/synced_note*' ``` Now there will be no prompt after ;s and ;n. @@ -148,32 +146,32 @@ Note: Do not use `*` with programs those run and exit e.g. cat. #### Run GUI app as plugin -To run a GUI app as plugin, add a `|` after `_`. For example: +To run a GUI app as plugin, add a `|` after `!`. For example: ```sh -export NNN_PLUG='m:-_|mousepad $nnn' +export NNN_PLUG='m:-!|mousepad $nnn' ``` Notes: 1. Use single quotes for `$NNN_PLUG` so `$nnn` is not interpreted 2. `$nnn` should be the last argument (IF used) -3. (_Again_) add `_` before the command -4. To disable directory refresh after running a _command as plugin_, prefix with `-_` +3. (_Again_) add `!` before the command +4. To disable directory refresh after running a _command as plugin_, prefix with `-!` #### Some useful key-command examples | Key:Command | Description | |---|---| -| `g:-_git diff` | Show git diff | -| `h:-_hx $nnn*` | Open hovered file in [hx](https://github.com/krpors/hx) hex editor | -| `k:-_fuser -kiv $nnn*` | Interactively kill process(es) using hovered file | -| `l:-_git log` | Show git log | -| `n:-_vi /home/user/Dropbox/dir/note*` | Take quick notes in a synced file/dir of notes | -| `p:-_less -iR $nnn*` | Page through hovered file in less | -| `s:-_\|smplayer -minigui $nnn` | Play hovered media file, even unfinished download | -| `x:_chmod +x $nnn` | Make the hovered file executable | -| `y:-_sync*` | Flush cached writes | +| `g:-!git diff` | Show git diff | +| `h:-!hx $nnn*` | Open hovered file in [hx](https://github.com/krpors/hx) hex editor | +| `k:-!fuser -kiv $nnn*` | Interactively kill process(es) using hovered file | +| `l:-!git log` | Show git log | +| `n:-!vi /home/user/Dropbox/dir/note*` | Take quick notes in a synced file/dir of notes | +| `p:-!less -iR $nnn*` | Page through hovered file in less | +| `s:-!\|smplayer -minigui $nnn` | Play hovered media file, even unfinished download | +| `x:!chmod +x $nnn` | Make the hovered file executable | +| `y:-!sync*` | Flush cached writes | ## Access level of plugins @@ -314,7 +312,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are # Show media information for hovered file # Save as file mediainf - # m:-_mediainf + # m:-!mediainf mediainfo "$1" | eval "$PAGER" # exiftool "$1" | $PAGER @@ -323,7 +321,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are # Show tree output with permissions and file size # Save as file treeplug - # t:-_treeplug + # t:-!treeplug tree -ps | $EDITOR - ------------------------------------------------- @@ -331,7 +329,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are # List files with UID/GID # Save as file uidgid - # u:-_uidgid + # u:-!uidgid ls -lah --group-directories-first | less ------------------------------------------------- @@ -339,7 +337,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are # Show hovered file data in hex # Save as file hexview - # x:-_hexview + # x:-!hexview if [ -f "$1" ]; then xxd "$1" | $PAGER @@ -349,7 +347,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are # Show hovered PDF text # Save as file pdftxt - # p:-_pdftxt + # p:-!pdftxt if [ -f "$1" ] && [ "$(head -c 4 "$1")" = "%PDF" ]; then pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' | $PAGER diff --git a/plugins/fzcd b/plugins/fzcd index 64c9a541..fb0c1668 100755 --- a/plugins/fzcd +++ b/plugins/fzcd @@ -30,7 +30,7 @@ LIST="$LIST" if ! type fzf >/dev/null 2>&1; then printf "fzf missing" read -r _ - exit 1 + exit 1 fi if [ -n "$1" ] && [ "$(file -b --mime-type "$1")" = 'text/plain' ] && [ -e "$(head -1 "$1")" ]; then diff --git a/src/nnn.c b/src/nnn.c index 402d905f..5db9e378 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -4812,10 +4812,10 @@ static bool run_selected_plugin(char **path, const char *file, char *runfile, ch g_state.pluginit = 1; } - if (*file == '_') { + if (*file == '!') { flags = F_MULTI | F_CONFIRM; - /* Get rid of preceding _ */ + /* Get rid of preceding ! */ ++file; if (!*file) return FALSE;