From 594d645e259083b217518ef0507edfe5395711af Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Fri, 22 Nov 2019 17:51:13 +0530 Subject: Rename plugins, group related ones --- plugins/README.md | 18 +++++++-------- plugins/checksum | 66 ------------------------------------------------------- plugins/chksum | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/diffs | 35 +++++++++++++++++++++++++++++ plugins/imgsxiv | 20 +++++++++++++++++ plugins/imgthumb | 17 ++++++++++++++ plugins/imgviu | 10 +++++++++ plugins/ndiff | 35 ----------------------------- plugins/pdfread | 30 +++++++++++++++++++++++++ plugins/readit | 30 ------------------------- plugins/sxiv | 20 ----------------- plugins/thumb | 17 -------------- plugins/viuimg | 10 --------- 13 files changed, 187 insertions(+), 187 deletions(-) delete mode 100755 plugins/checksum create mode 100755 plugins/chksum create mode 100755 plugins/diffs create mode 100755 plugins/imgsxiv create mode 100755 plugins/imgthumb create mode 100755 plugins/imgviu delete mode 100755 plugins/ndiff create mode 100755 plugins/pdfread delete mode 100755 plugins/readit delete mode 100755 plugins/sxiv delete mode 100755 plugins/thumb delete mode 100755 plugins/viuimg (limited to 'plugins') diff --git a/plugins/README.md b/plugins/README.md index f1146e7..11b7578 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -4,7 +4,7 @@

read ebooks with plugin gutenread (Android)

-

image preview with plugin thumb

+

image preview with plugin imgthumb

## Introduction @@ -16,7 +16,8 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | --- | --- | --- | --- | | boom | Play random music from dir | sh | [moc](http://moc.daper.net/) | | dups | List non-empty duplicate files in current dir | sh | find, md5sum,
sort uniq xargs | -| checksum | Create and verify checksums | sh | md5sum,
sha256sum | +| chksum | Create and verify checksums | sh | md5sum,
sha256sum | +| diffs | Diff for selection (limited to 2 for directories) | sh | vimdiff | | dragdrop | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) | | exetoggle | Toggle executable status of hovered file | sh | chmod | | fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzy/fzf
(optional fd) | @@ -26,33 +27,32 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | gutenread | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m
[epr](https://github.com/wustho/epr) (optional) | | hexview | View a file in hex in `$PAGER` | sh | xxd | | imgresize | Resize images in dir to screen resolution | sh | [imgp](https://github.com/jarun/imgp) | +| imgsxiv | Browse images, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts)), [rename](https://github.com/jarun/nnn/wiki/Basic-use-cases#browse-rename-images)| sh | sxiv | +| imgthumb | View thumbnail of an image or dir of images | sh | [lsix](https://github.com/hackerb9/lsix) | | imgur | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) | bash | - | +| imgviu | View an image or images in dir in `$PAGER` | sh | [viu](https://github.com/atanunq/viu), less | | ipinfo | Fetch external IP address and whois information | sh | curl, whois | | kdeconnect | Send selected files to an Android device | sh | kdeconnect-cli | | mediainf | Show media information | sh | mediainfo | | moclyrics | Show lyrics of the track playing in moc | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) | | mocplay | Append (and/or play) selection/dir/file in moc | sh | [moc](http://moc.daper.net/) | -| ndiff | Diff for selection (limited to 2 for directories) | sh | vimdiff | | nmount | Toggle mount status of a device as normal user | sh | pmount, udisks2 | | notes | Open a quick notes file/dir in `$EDITOR` | sh | - | | oldbigfile | List large files by access time | sh | find, sort | | organize | Auto-organize files in directories by file type | sh | file | | pastebin | Paste contents of a text a file ix.io | sh | - | +| pdfread | Read a PDF or text file aloud | sh | pdftotext, mpv,
pico2wave | | pdfview | View PDF file in `$PAGER` | sh | pdftotext/
mupdf-tools | | picker | Pick files and list one per line (to pipe) | sh | nnn | | pskill | Fuzzy list by name and kill process or zombie | sh | fzy, sudo/doas | -| readit | Read a PDF or text file aloud | sh | pdftotext, mpv,
pico2wave | | ringtone | Create a variable bitrate mp3 ringtone from file | sh | date, ffmpeg | | splitjoin | Split file or join selection | sh | split, cat | | suedit | Edit file using superuser permissions | sh | sudoedit/sudo/doas | -| sxiv | Browse images, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts)), [rename](https://github.com/jarun/nnn/wiki/Basic-use-cases#browse-rename-images)| sh | sxiv | -| thumb | View thumbnail of an image or dir of images | sh | [lsix](https://github.com/hackerb9/lsix) | | transfer | Upload file to transfer.sh | sh | curl | | treeview | Informative tree output in `$EDITOR` | sh | tree | | uidgid | List user and group of all files in dir | sh | ls, less | | upgrade | Upgrade nnn manually on Debian 9 Stretch | sh | curl | | vidthumb | Show video thumbnails in terminal | sh | [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer),
[lsix](https://github.com/hackerb9/lsix) | -| viuimg | View an image or images in dir in `$PAGER` | sh | [viu](https://github.com/atanunq/viu), less | | wall | Set wallpaper or change colorscheme | sh | nitrogen/pywal | ## Installing plugins @@ -69,7 +69,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`. You ca **Method 1:** Directly with :key: - export NNN_PLUG='o:fzopen;p:mocplay;d:ndiff;m:nmount;n:notes;v:viuimg;t:thumb' + export NNN_PLUG='o:fzopen;p:mocplay;d:diffs;m:nmount;n:notes;v:imgviu;t:imgthumb' Now plugin `fzopen` can be run with the keybind :o, `mocplay` can be run with :p and so on... The key vs. plugin pairs are shown in the help and config screen. @@ -98,7 +98,7 @@ When `nnn` executes a plugin, it does the following: 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 `_`. - Sets the environment variable `NNN_PIPE` used to control `nnn` active directory. -Plugins can also access the current selections by reading the `.selections` file in the config directory (See the `ndiff` plugin for example). +Plugins can also access the current selections by reading the `.selections` file in the config directory (See the `diffs` plugin for example). ## Create your own plugins diff --git a/plugins/checksum b/plugins/checksum deleted file mode 100755 index 0c13da2..0000000 --- a/plugins/checksum +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env sh - -# Description: Create and verify checksums -# -# For selection: it will generate one file containing the checksums with file names -# [and with paths if they are in another directory] -# the output checksum filename will be checksum_timestamp.checksum_type -# For file: if the file is a checksum, the plugin does the verification -# if the file is not a checksum, checksum will be generated for it -# the output checksum filename will be filename.checksum_type -# For directory: recursively calculates checksum for all the files in the directory -# the output checksum filename will be directory.checksum_type -# -# Shell: POSIX compliant -# Author: ath3, Arun Prakash Jana - -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection -resp=f -chsum=md5 - -checksum_type() -{ - echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512" - printf "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: " - read -r chsum_resp - for chks in md5 sha1 sha224 sha256 sha384 sha512 - do - if [ "$chsum_resp" = "$chks" ]; then - chsum=$chsum_resp - return - fi - done - if [ "$chsum_resp" = "s" ]; then - chsum=sha256 - elif [ "$chsum_resp" = "S" ]; then - chsum=sha512 - fi -} - -if [ -s "$selection" ]; then - printf "work with selection (s) or current file (f) [default=f]: " - read -r resp -fi - -if [ "$resp" = "s" ]; then - checksum_type - sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -I{} ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum" -elif [ -n "$1" ]; then - if [ -f "$1" ]; then - for chks in md5 sha1 sha224 sha256 sha384 sha512 - do - if echo "$1" | grep -q \.${chks}$; then - ${chks}sum -c < "$1" - read -r _ - return - fi - done - checksum_type - file=$(basename "$1").$chsum - ${chsum}sum "$1" > "$file" - elif [ -d "$1" ]; then - checksum_type - file=$(basename "$1").$chsum - find "$1" -type f -exec ${chsum}sum "{}" + > "$file" - fi -fi diff --git a/plugins/chksum b/plugins/chksum new file mode 100755 index 0000000..0c13da2 --- /dev/null +++ b/plugins/chksum @@ -0,0 +1,66 @@ +#!/usr/bin/env sh + +# Description: Create and verify checksums +# +# For selection: it will generate one file containing the checksums with file names +# [and with paths if they are in another directory] +# the output checksum filename will be checksum_timestamp.checksum_type +# For file: if the file is a checksum, the plugin does the verification +# if the file is not a checksum, checksum will be generated for it +# the output checksum filename will be filename.checksum_type +# For directory: recursively calculates checksum for all the files in the directory +# the output checksum filename will be directory.checksum_type +# +# Shell: POSIX compliant +# Author: ath3, Arun Prakash Jana + +selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +resp=f +chsum=md5 + +checksum_type() +{ + echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512" + printf "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: " + read -r chsum_resp + for chks in md5 sha1 sha224 sha256 sha384 sha512 + do + if [ "$chsum_resp" = "$chks" ]; then + chsum=$chsum_resp + return + fi + done + if [ "$chsum_resp" = "s" ]; then + chsum=sha256 + elif [ "$chsum_resp" = "S" ]; then + chsum=sha512 + fi +} + +if [ -s "$selection" ]; then + printf "work with selection (s) or current file (f) [default=f]: " + read -r resp +fi + +if [ "$resp" = "s" ]; then + checksum_type + sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -I{} ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum" +elif [ -n "$1" ]; then + if [ -f "$1" ]; then + for chks in md5 sha1 sha224 sha256 sha384 sha512 + do + if echo "$1" | grep -q \.${chks}$; then + ${chks}sum -c < "$1" + read -r _ + return + fi + done + checksum_type + file=$(basename "$1").$chsum + ${chsum}sum "$1" > "$file" + elif [ -d "$1" ]; then + checksum_type + file=$(basename "$1").$chsum + find "$1" -type f -exec ${chsum}sum "{}" + > "$file" + fi +fi diff --git a/plugins/diffs b/plugins/diffs new file mode 100755 index 0000000..3680627 --- /dev/null +++ b/plugins/diffs @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +# Description: Show diff of 2 directories or multiple files in vimdiff +# +# Note: vim may show the warning: 'Vim: Warning: Input is not from a terminal' +# press 'Enter' to ignore and proceed. +# +# Shell: POSIX compliant +# Authors: Arun Prakash Jana, ath3 + +selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection + +if [ -s "$selection" ]; then + arr=$(tr '\0' '\n' < "$selection") + if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then + f1="$(echo "$arr" | sed -n '1p')" + f2="$(echo "$arr" | sed -n '2p')" + if [ -d "$f1" ] && [ -d "$f2" ]; then + dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$f1")".XXXXXXXX) + dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$f2")".XXXXXXXX) + ls -A1 "$f1" > "$dir1" + ls -A1 "$f2" > "$dir2" + vimdiff "$dir1" "$dir2" + rm "$dir1" "$dir2" + else + # If xargs supports the -o option, use it to get rid of: + # Vim: Warning: Input is not from a terminal + # xargs -0 -o vimdiff < $selection + + xargs -0 vimdiff +0 < "$selection" + fi + else + echo "needs at least 2 files or directories selected for comparison" + fi +fi diff --git a/plugins/imgsxiv b/plugins/imgsxiv new file mode 100755 index 0000000..1fe81b7 --- /dev/null +++ b/plugins/imgsxiv @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +# Description: Open images in hovered directory and thumbnails +# open hovered image in sxiv and browse other images in the directory +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if command -v sxiv >/dev/null 2>&1; then + if ! [ -z "$1" ]; then + if [ -f "$1" ]; then + sxiv -q "$PWD" + elif [ -d "$1" ] || [ -h "$1" ]; then + sxiv -qt "$1" + fi + fi +else + echo "sxiv missing" + read -r _ +fi diff --git a/plugins/imgthumb b/plugins/imgthumb new file mode 100755 index 0000000..8882115 --- /dev/null +++ b/plugins/imgthumb @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# Description: View thumbnail of an image or a directory of images with lsix +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if ! [ -z "$1" ]; then + if [ -d "$1" ]; then + lsix "$1"/* + else + lsix "$1" + fi + + printf "Press any key to exit..." + read -r _ +fi diff --git a/plugins/imgviu b/plugins/imgviu new file mode 100755 index 0000000..200a459 --- /dev/null +++ b/plugins/imgviu @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +# Description: View an image or images in a directory in $PAGER +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if ! [ -z "$1" ]; then + viu -n "$1" | less -R +fi diff --git a/plugins/ndiff b/plugins/ndiff deleted file mode 100755 index 3680627..0000000 --- a/plugins/ndiff +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env sh - -# Description: Show diff of 2 directories or multiple files in vimdiff -# -# Note: vim may show the warning: 'Vim: Warning: Input is not from a terminal' -# press 'Enter' to ignore and proceed. -# -# Shell: POSIX compliant -# Authors: Arun Prakash Jana, ath3 - -selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection - -if [ -s "$selection" ]; then - arr=$(tr '\0' '\n' < "$selection") - if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then - f1="$(echo "$arr" | sed -n '1p')" - f2="$(echo "$arr" | sed -n '2p')" - if [ -d "$f1" ] && [ -d "$f2" ]; then - dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$f1")".XXXXXXXX) - dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$f2")".XXXXXXXX) - ls -A1 "$f1" > "$dir1" - ls -A1 "$f2" > "$dir2" - vimdiff "$dir1" "$dir2" - rm "$dir1" "$dir2" - else - # If xargs supports the -o option, use it to get rid of: - # Vim: Warning: Input is not from a terminal - # xargs -0 -o vimdiff < $selection - - xargs -0 vimdiff +0 < "$selection" - fi - else - echo "needs at least 2 files or directories selected for comparison" - fi -fi diff --git a/plugins/pdfread b/plugins/pdfread new file mode 100755 index 0000000..4f47992 --- /dev/null +++ b/plugins/pdfread @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +# Description: Read a text or PDF file in British English +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if ! [ -z "$1" ]; then + tmpf="$(basename "$1")" + tmpf="${TMPDIR:-/tmp}"/"${tmpf%.*}" + + if [ "$(head -c 4 "$1")" = "%PDF" ]; then + # Convert using pdftotext + pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' > "$tmpf".txt + + pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$tmpf".txt)" + + rm "$tmpf".txt + else + pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$1")" + fi + + # to jump around and note the time + mpv "$tmpf".wav + + # flat read but better quality + # play -qV0 "$tmpf".wav treble 2 gain -l 2 + + rm "$tmpf".wav +fi diff --git a/plugins/readit b/plugins/readit deleted file mode 100755 index 4f47992..0000000 --- a/plugins/readit +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env sh - -# Description: Read a text or PDF file in British English -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if ! [ -z "$1" ]; then - tmpf="$(basename "$1")" - tmpf="${TMPDIR:-/tmp}"/"${tmpf%.*}" - - if [ "$(head -c 4 "$1")" = "%PDF" ]; then - # Convert using pdftotext - pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' > "$tmpf".txt - - pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$tmpf".txt)" - - rm "$tmpf".txt - else - pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$1")" - fi - - # to jump around and note the time - mpv "$tmpf".wav - - # flat read but better quality - # play -qV0 "$tmpf".wav treble 2 gain -l 2 - - rm "$tmpf".wav -fi diff --git a/plugins/sxiv b/plugins/sxiv deleted file mode 100755 index 1fe81b7..0000000 --- a/plugins/sxiv +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env sh - -# Description: Open images in hovered directory and thumbnails -# open hovered image in sxiv and browse other images in the directory -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if command -v sxiv >/dev/null 2>&1; then - if ! [ -z "$1" ]; then - if [ -f "$1" ]; then - sxiv -q "$PWD" - elif [ -d "$1" ] || [ -h "$1" ]; then - sxiv -qt "$1" - fi - fi -else - echo "sxiv missing" - read -r _ -fi diff --git a/plugins/thumb b/plugins/thumb deleted file mode 100755 index 8882115..0000000 --- a/plugins/thumb +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env sh - -# Description: View thumbnail of an image or a directory of images with lsix -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if ! [ -z "$1" ]; then - if [ -d "$1" ]; then - lsix "$1"/* - else - lsix "$1" - fi - - printf "Press any key to exit..." - read -r _ -fi diff --git a/plugins/viuimg b/plugins/viuimg deleted file mode 100755 index 200a459..0000000 --- a/plugins/viuimg +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env sh - -# Description: View an image or images in a directory in $PAGER -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if ! [ -z "$1" ]; then - viu -n "$1" | less -R -fi -- cgit v1.2.3-70-g09d2