My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 8.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <h1 align="center">nnn plugins</h1>
  2. <p align="center"><img src="https://i.imgur.com/14iPDIq.png" /></p>
  3. <p align="center"><i>image preview with plugin thumb</i></p>
  4. Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or binaries) which `nnn` can communicate with and trigger. This mechanism fits perfectly with the fundamental design to keep the core file manager lean and fast, by delegating repetitive (but not necessarily file manager-specific) tasks to the plugins.
  5. The currently available plugins are listed below.
  6. | Plugin (a-z) | Lang | Deps | Description |
  7. | --- | --- | --- | --- |
  8. | boom | sh | [moc](http://moc.daper.net/) | Play random music from dir |
  9. | dups | sh | find, md5sum,<br>sort uniq xargs | List non-empty duplicate files in current dir |
  10. | checksum | sh | md5sum,<br>sha256sum | Create and verify checksums |
  11. | dragdrop | sh | [dragon](https://github.com/mwh/dragon) | Drag/drop files from/into nnn |
  12. | exetoggle | sh | chmod | Toggle executable status of hovered file |
  13. | fzcd | sh | fzy/fzf<br>(optional fd) | Change to the directory of a fuzzy-selected file/dir |
  14. | fzopen | sh | fzy, xdg-open | Fuzzy find a file in dir subtree and edit or xdg-open |
  15. | getplugs | sh | curl | Update plugins |
  16. | gutenread | sh | curl, unzip, w3m<br>[epr](https://github.com/wustho/epr) (optional)| Browse, download, read from Project Gutenberg |
  17. | hexview | sh | xxd | View a file in hex in `$PAGER` |
  18. | imgresize | sh | [imgp](https://github.com/jarun/imgp) | Resize images in dir to screen resolution |
  19. | imgur | bash | - | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) |
  20. | ipinfo | sh | curl, whois | Fetch external IP address and whois information |
  21. | kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device |
  22. | mediainf | sh | mediainfo | Show media information |
  23. | moclyrics | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) | Show lyrics of the track playing in moc |
  24. | mocplay | sh | [moc](http://moc.daper.net/) | Append (and/or play) selection/dir/file in moc|
  25. | ndiff | sh | vimdiff | Diff for selection (limited to 2 for directories) |
  26. | nmount | sh | pmount, udisks2 | Toggle mount status of a device as normal user |
  27. | notes | sh | - | Open a quick notes file/dir in `$EDITOR` |
  28. | nwal | sh | nitrogen | Set image as wallpaper using nitrogen |
  29. | oldbigfile | sh | find, sort | List large files by access time |
  30. | organize | sh | file | Auto-organize files in directories by file type |
  31. | pastebin | sh | - | Paste contents of a text a file ix.io |
  32. | pdfview | sh | pdftotext/<br>mupdf-tools | View PDF file in `$PAGER` |
  33. | picker | sh | nnn | Pick files and list one per line (to pipe) |
  34. | pskill | sh | fzy, sudo/doas | Fuzzy list by name and kill process or zombie |
  35. | pywal | sh | pywal | Set image as wallpaper, change terminal colorscheme |
  36. | readit | sh | pdftotext, mpv,<br>pico2wave | Read a PDF or text file aloud |
  37. | ringtone | sh | date, ffmpeg | Create a variable bitrate mp3 ringtone from file |
  38. | splitjoin | sh | split, cat | Split file or join selection |
  39. | suedit | sh | sudoedit/sudo/doas | Edit file using superuser permissions |
  40. | sxiv | sh | sxiv | View images in dir, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))|
  41. | thumb | sh | [lsix](https://github.com/hackerb9/lsix) | View thumbnail of an image or dir of images |
  42. | transfer | sh | curl | Upload file to transfer.sh |
  43. | treeview | sh | tree | Informative tree output in `$EDITOR` |
  44. | uidgid | sh | ls, less | List user and group of all files in dir |
  45. | upgrade | sh | curl | Upgrade nnn manually on Debian 9 Stretch |
  46. | vidthumb | sh | [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer),<br>[lsix](https://github.com/hackerb9/lsix) | Show video thumbnails in terminal |
  47. | viuimg | sh | [viu](https://github.com/atanunq/viu), less | View an image or images in dir in `$PAGER` |
  48. <p align="center"><img src="https://i.imgur.com/SpT0L2W.png" /></p>
  49. <p align="center"><i>read ebooks with plugin gutenread (Android)</i></p>
  50. ## Installing plugins
  51. The following command installs all plugins:
  52. curl -Ls https://raw.githubusercontent.com/jarun/nnn/master/plugins/getplugs | sh
  53. Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`. You can run the `getplugs` plugin later to update the plugins. It backs up earlier plugins.
  54. **NOTE:** `getplugs` also downloads the launcher `nlaunch` and tries to place it at `/usr/local/bin/` using `sudo`. If it fails you have to place `nlauch` manually somewhere in your `$PATH`.
  55. ## Executing plugins
  56. **Method 1:** Directly with <kbd>:key</kbd>:
  57. export NNN_PLUG='o:fzopen;p:mocplay;d:ndiff;m:nmount;n:notes;v:viuimg;t:thumb'
  58. Now plugin `fzopen` can be run with the keybind <kbd>:o</kbd>, `mocplay` can be run with <kbd>:p</kbd> and so on... The key vs. plugin pairs are shown in the help and config screen.
  59. **Method 2:** Use the _pick plugin_ shortcut to visit the plugin directory and execute a plugin. Repeating the same shortcut cancels the operation and puts you back in the original directory.
  60. ## Running commands as plugin
  61. To assign keys to arbitrary non-background cli commands (non-shell-interpreted) and invoke like plugins, add `_` (underscore) before the command. For example:
  62. export NNN_PLUG='x:_chmod +x $NNN;g:_git log;s:_smplayer $NNN;o:fzopen'
  63. Now <kbd>:x</kbd> can be used to make a file executable, <kbd>:g</kbd> can be used to the git log of a git project directory, <kbd>:s</kbd> can be used to preview a partially downloaded media file.
  64. Notes:
  65. 1. Use single quotes for `$NNN_PLUG` so `$NNN` is not interpreted
  66. 2. `$NNN` should be the last argument (IF you want to pass the hovered file name)
  67. 3. (_Again_) add `_` before the command
  68. ## Access level of plugins
  69. When `nnn` executes a plugin, it does the following:
  70. - Change to the directory where the plugin is to be run (`$PWD` pointing to the active directory)
  71. - Passes two arguments to the script:
  72. 1. The hovered file's name.
  73. 2. The working directory (might differ from `$PWD` in case of symlinked paths; non-canonical). Note that the second argument is not passed in case of commands starting with `_`.
  74. - Sets the environment variable `NNN_PIPE` used to control `nnn` active directory.
  75. Plugins can also access the current selections by reading the `.selections` file in the config directory (See the `ndiff` plugin for example).
  76. ## Create your own plugins
  77. Plugins are a powerful yet easy way to extend the capabilities of `nnn`.
  78. Plugins are scripts that can be written in any scripting language. However, POSIX-compliant shell scripts runnable in `sh` are preferred.
  79. Each script has a _Description_ section which provides more details on what the script does, if applicable.
  80. The plugins reside in `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`.
  81. #### Controlling `nnn`'s active directory
  82. `nnn` provides a mechanism for plugins to control its active directory.
  83. The way to do so is by writing to the pipe pointed by the environment variable `NNN_PIPE`.
  84. The plugin should write a single string in the format `<number><path>` without a newline at the end. For example, `1/etc`.
  85. The number indicates the context to change the active directory of (0 is used to indicate the current context).
  86. For convenience, we provided a helper script named `.nnn-plugin-helper` and a function named `nnn_cd` to ease this process. `nnn_cd` receives the path to change to as the first argument, and the context as an optional second argument.
  87. If a context is not provided, it is asked for explicitly.
  88. Usage examples can be found in the Examples section below.
  89. #### Examples
  90. There are many plugins provided by `nnn` which can be used as examples. Here are a few simple selected examples.
  91. - Show the git log of changes to the particular file along with the code for a quick and easy review.
  92. ```sh
  93. #!/usr/bin/env sh
  94. git log -p -- "$1"
  95. ```
  96. - Change to directory in clipboard using helper script
  97. ```sh
  98. #!/usr/bin/env sh
  99. . $(dirname $0)/.nnn-plugin-helper
  100. nnn_cd "$(xsel -ob)"
  101. ```
  102. - Change direcory to the location of a link using helper script with specific context (current)
  103. ```sh
  104. #!/usr/bin/env sh
  105. . $(dirname $0)/.nnn-plugin-helper
  106. nnn_cd "$(dirname $(readlink -fn $1))" 0
  107. ```
  108. - Change to arbitrary directory without helper script
  109. ```sh
  110. #!/usr/bin/env sh
  111. echo -n "cd to: "
  112. read dir
  113. echo -n "0$dir" > $NNN_PIPE
  114. ```
  115. ## Contributing plugins
  116. Please keep non-portable commands (like `notify-send`) commented so users from any other OS/DE aren't surprised.
  117. The plugins should be executable. Please add an entry in the table above.