commit c11972e0ed883cc95c3f313724351edcdd700e60 parent 5b782f131a34558273256dfc7bf2b0896ca4c5bd Author: mrgrouse <bdmfegys@duck.com> Date: Thu, 10 Oct 2024 00:10:54 -0400 nnn/plugins: delete unused plugins Diffstat:
| D | nnn/plugins/autojump | | | 74 | -------------------------------------------------------------------------- |
| D | nnn/plugins/boom | | | 50 | -------------------------------------------------- |
| D | nnn/plugins/bulknew | | | 32 | -------------------------------- |
| D | nnn/plugins/cbcopy-mac | | | 16 | ---------------- |
| D | nnn/plugins/cbpaste-mac | | | 24 | ------------------------ |
| D | nnn/plugins/cdpath | | | 56 | -------------------------------------------------------- |
| D | nnn/plugins/chksum | | | 75 | --------------------------------------------------------------------------- |
| D | nnn/plugins/cmusq | | | 80 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/diffs | | | 62 | -------------------------------------------------------------- |
| D | nnn/plugins/dragdrop | | | 77 | ----------------------------------------------------------------------------- |
| D | nnn/plugins/dups | | | 70 | ---------------------------------------------------------------------- |
| D | nnn/plugins/finder | | | 89 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/fixname | | | 75 | --------------------------------------------------------------------------- |
| D | nnn/plugins/fzcd | | | 89 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/fzhist | | | 53 | ----------------------------------------------------- |
| D | nnn/plugins/fzopen | | | 85 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/fzplug | | | 59 | ----------------------------------------------------------- |
| D | nnn/plugins/getplugs | | | 70 | ---------------------------------------------------------------------- |
| D | nnn/plugins/gitroot | | | 15 | --------------- |
| D | nnn/plugins/gpgd | | | 28 | ---------------------------- |
| D | nnn/plugins/gpge | | | 45 | --------------------------------------------- |
| D | nnn/plugins/gsconnect | | | 21 | --------------------- |
| D | nnn/plugins/gutenread | | | 49 | ------------------------------------------------- |
| D | nnn/plugins/imgresize | | | 31 | ------------------------------- |
| D | nnn/plugins/imgur | | | 597 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/imgview | | | 113 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/ipinfo | | | 13 | ------------- |
| D | nnn/plugins/kdeconnect | | | 66 | ------------------------------------------------------------------ |
| D | nnn/plugins/launch | | | 42 | ------------------------------------------ |
| D | nnn/plugins/mimelist | | | 23 | ----------------------- |
| D | nnn/plugins/moclyrics | | | 40 | ---------------------------------------- |
| D | nnn/plugins/mocq | | | 89 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/mp3conv | | | 41 | ----------------------------------------- |
| D | nnn/plugins/mtpmount | | | 76 | ---------------------------------------------------------------------------- |
| D | nnn/plugins/nbak | | | 75 | --------------------------------------------------------------------------- |
| D | nnn/plugins/nmount | | | 88 | ------------------------------------------------------------------------------- |
| D | nnn/plugins/oldbigfile | | | 16 | ---------------- |
| D | nnn/plugins/openall | | | 49 | ------------------------------------------------- |
| D | nnn/plugins/organize | | | 62 | -------------------------------------------------------------- |
| D | nnn/plugins/pdfread | | | 30 | ------------------------------ |
| D | nnn/plugins/pskill | | | 35 | ----------------------------------- |
| D | nnn/plugins/renamer | | | 45 | --------------------------------------------- |
| D | nnn/plugins/ringtone | | | 36 | ------------------------------------ |
| D | nnn/plugins/rsynccp | | | 26 | -------------------------- |
| D | nnn/plugins/splitjoin | | | 52 | ---------------------------------------------------- |
| D | nnn/plugins/suedit | | | 16 | ---------------- |
| D | nnn/plugins/togglex | | | 21 | --------------------- |
| D | nnn/plugins/umounttree | | | 52 | ---------------------------------------------------- |
| D | nnn/plugins/upload | | | 38 | -------------------------------------- |
| D | nnn/plugins/wallpaper | | | 45 | --------------------------------------------- |
| D | nnn/plugins/x2sel | | | 62 | -------------------------------------------------------------- |
51 files changed, 0 insertions(+), 3173 deletions(-)
diff --git a/nnn/plugins/autojump b/nnn/plugins/autojump @@ -1,74 +0,0 @@ -#!/usr/bin/env sh - -# Description: Navigate to directory using jump/autojump/zoxide/z -# -# Dependencies: -# - jump - https://github.com/gsamokovarov/jump -# - OR autojump - https://github.com/wting/autojump -# - OR zoxide - https://github.com/ajeetdsouza/zoxide -# - OR z - https://github.com/rupa/z (z requires fzf) -# - OR z (fish) - https://github.com/jethrokuan/z (z requires fzf) -# - OR z.lua - https://github.com/skywind3000/z.lua (z.lua can enhanced with fzf) -# -# Note: The dependencies STORE NAVIGATION PATTERNS -# -# to make z.lua work, you need to set $NNN_ZLUA to the path of script z.lua -# -# Shell: POSIX compliant -# Authors: Marty Buchaus, Dave Snider, Tim Adler, Nick Waywood - -if [ ! -p "$NNN_PIPE" ]; then - printf 'ERROR: NNN_PIPE is not set!' - read -r _ - exit 2 -fi - -if type jump >/dev/null 2>&1; then - printf "jump to : " - IFS= read -r line - # shellcheck disable=SC2086 - odir="$(jump cd ${line})" - printf "%s" "0c$odir" > "$NNN_PIPE" -elif type autojump >/dev/null 2>&1; then - printf "jump to : " - read -r dir - odir="$(autojump "$dir")" - printf "%s" "0c$odir" > "$NNN_PIPE" -elif type zoxide >/dev/null 2>&1; then - if type fzf >/dev/null 2>&1; then - odir="$(zoxide query -i --)" - printf "%s" "0c$odir" > "$NNN_PIPE" - else - printf "jump to : " - read -r dir - odir="$(zoxide query -- "$dir")" - printf "%s" "0c$odir" > "$NNN_PIPE" - fi -elif type lua >/dev/null 2>&1 && [ -n "$NNN_ZLUA" ]; then - printf "jump to : " - read -r line - if type fzf >/dev/null 2>&1; then - odir="$(lua "$NNN_ZLUA" -l "$line" | fzf --nth 2.. --reverse --inline-info --tac +s -e --height 35%)" - printf "%s" "0c$(echo "$odir" | awk '{print $2}')" > "$NNN_PIPE" - else - odir="$(lua "$NNN_ZLUA" -e "$line")" - printf "%s" "0c$odir" > "$NNN_PIPE" - fi -else - # rupa/z uses $_Z_DATA, jethrokuan/z (=port of z for fish) uses $Z_DATA - datafile="${_Z_DATA:-${Z_DATA:-$HOME/.z}}" - if type fzf >/dev/null 2>&1 && [ -f "$datafile" ]; then - # Read the data from z's file instead of calling - # z so the data doesn't need to be processed twice - sel=$(awk -F "|" '{print $1}' "$datafile" | fzf | awk '{$1=$1};1') - - # NOTE: Uncomment this line and comment out the line above if - # you want to see the weightings of the dir's in the fzf pane - # sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$datafile" | fzf | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1') - - printf "%s" "0c$sel" > "$NNN_PIPE" - else - printf "No supported autojump script [jump/autojump/zoxide/z (needs fzf)] found" - read -r _ - fi -fi diff --git a/nnn/plugins/boom b/nnn/plugins/boom @@ -1,50 +0,0 @@ -#!/usr/bin/env sh - -# Description: Play random music (MP3, FLAC, M4A, WEBM, WMA) from current dir. -# -# Dependencies: mocp (or custom) -# -# Note: You may want to set GUIPLAYER. -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -GUIPLAYER="${GUIPLAYER:-""}" -NUMTRACKS="${NUMTRACKS:-100}" - -if [ -n "$GUIPLAYER" ]; then - find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf -n "$NUMTRACKS" | xargs -d "\n" "$GUIPLAYER" > /dev/null 2>&1 & - - # detach the player - sleep 1 -elif type mocp >/dev/null 2>&1; then - cmd=$(pgrep -x mocp 2>/dev/null) - ret=$cmd - - if [ -z "$ret" ]; then - # start MOC server - mocp -S - mocp -o shuffle - else - # mocp running, check if it's playing - state=$(mocp -i | grep "State:" | cut -d' ' -f2) - if [ "$state" = 'PLAY' ]; then - # add up to 100 random audio files - find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a - exit - fi - fi - - # clear MOC playlist - mocp -c - mocp -o shuffle - - # add up to 100 random audio files - find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a - - # start playing - mocp -p -else - printf "moc missing" - read -r _ -fi diff --git a/nnn/plugins/bulknew b/nnn/plugins/bulknew @@ -1,32 +0,0 @@ -#!/usr/bin/env sh - -# Description: Allows for creation of multiple files/dirs simultaneously -# Creates a tmp file to write each entry in a separate line -# -# Note: Only relative paths are supported. Absolute paths are ignored -# Leading and trailing whitespace in path names is also ignored -# -# Shell: POSIX compliant -# Author: KlzXS - -EDITOR="${EDITOR:-vi}" -TMPDIR="${TMPDIR:-/tmp}" - -printf "'f'ile / 'd'ir? " -read -r resp - -if [ "$resp" = "f" ]; then - #shellcheck disable=SC2016 - cmd='mkdir -p "$(dirname "{}")" && touch "{}"' -elif [ "$resp" = "d" ]; then - cmd='mkdir -p {}' -else - exit 1 -fi - -tmpfile=$(mktemp "$TMPDIR/.nnnXXXXXX") -$EDITOR "$tmpfile" - -sed "/^\//d" "$tmpfile" | xargs -n1 -I{} sh -c "$cmd" - -rm -- "$tmpfile" diff --git a/nnn/plugins/cbcopy-mac b/nnn/plugins/cbcopy-mac @@ -1,16 +0,0 @@ -#!/usr/bin/osascript - -# Description: Copy the hovered file to MacOS clipboard. -# -# Note: Supports only MacOS -# -# Shell: POSIX compliant -# Author: Syed Umar Anis - - -on run args - set filePath to (second item of args & "/" & first item of args) - tell application "Finder" - set the clipboard to (filePath as POSIX file) - end tell -end diff --git a/nnn/plugins/cbpaste-mac b/nnn/plugins/cbpaste-mac @@ -1,24 +0,0 @@ -#!/usr/bin/env sh -# shellcheck disable=all - -# Description: Paste the clipboard files into the current directory. -# Only works if clipboard contents are files. -# -# Note: Supports only MacOS -# -# Shell: POSIX compliant -# Author: Syed Umar Anis - - -fs=($( osascript -e "use framework \"Foundation\" - property this : a reference to the current application - property NSPasteboard : a reference to NSPasteboard of this - property NSURL : a reference to NSURL of this - property pb : a reference to NSPasteboard's generalPasteboard - - property text item delimiters : linefeed - - pb's readObjectsForClasses:[NSURL] options:[] - (result's valueForKey:\"path\") as list as text" )) - -cp -R -- "${fs[@]}" "$2/" diff --git a/nnn/plugins/cdpath b/nnn/plugins/cdpath @@ -1,56 +0,0 @@ -#!/usr/bin/env sh - -# Description: 'cd' to the directory from CDPATH -# -# Details: If the CDPATH environment variable is not set, the default value of -# ${XDG_CONFIG_HOME:-$HOME/.config}/nnn/bookmarks will be used. -# You can create this directory and fill it with symbolic links to your -# favorite directories. It's a good idea to add it to CDPATH so that it -# could also be used from the command line outside of nnn. -# The fzf search is done on the directory basename (the first column). -# -# This plugin is an extended version of the bookmarks plugin. -# If you set your CDPATH to ${XDG_CACHE_HOME:-$HOME/.cache}/nnn/bookmarks -# or to the value of BOOKMARKS_DIR, you can use it as a bookmarks replacement. -# -# Shell: POSIX compliant -# Author: Yuri Kloubakov - -# shellcheck disable=SC1090,SC1091 -. "$(dirname "$0")"/.nnn-plugin-helper - -# Get a list of (symbolic links to) directories for every element of CDPATH -get_dirs() { - IFS=':' - for path in $CDPATH; do - for entry in "$path"/*; do - if [ -d "$entry" ]; then - name=$(basename "$entry" | grep -o '^.\{1,24\}') - if [ -h "$entry" ]; then - slink=$(ls -dl -- "$entry") - entry=${slink#*" $entry -> "} - fi - printf "%-24s :%s\n" "${name}" "$entry" - fi - done - done -} - -abort() { - echo "$1" - read -r _ - exit 1 -} - -if [ -z "$CDPATH" ]; then - CDPATH="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/bookmarks" - [ -d "$CDPATH" ] || abort "CDPATH is not set and there is no \"$CDPATH\" directory" -fi - -dir_list=$(get_dirs) -[ -n "$dir_list" ] || abort "There are no directories to choose from. Check your \"$CDPATH\"." - -dir=$(echo "$dir_list" | fzf --nth=1 --delimiter=':' | awk -F: 'END { print $2 }') -if [ -n "$dir" ]; then - nnn_cd "$dir" 0 -fi diff --git a/nnn/plugins/chksum b/nnn/plugins/chksum @@ -1,75 +0,0 @@ -#!/usr/bin/env sh - -# Description: Create and verify checksums -# -# Note: On macOS, install the relevant checksum packages from Homebrew with: -# brew install coreutils -# -# Details: -# - selection: it will generate one file with the checksums and filenames -# (and with paths if they are in another directory) -# output checksum filename format: checksum_timestamp.checksum_type -# - 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 -# - directory: recursively calculates checksum for all the files in the dir -# the output checksum filename will be directory.checksum_type -# -# Shell: POSIX compliant -# Authors: ath3, Arun Prakash Jana - -selection=${NNN_SEL:-${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" - - # Clear selection - if [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" - fi -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 _ - exit - 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/nnn/plugins/cmusq b/nnn/plugins/cmusq @@ -1,80 +0,0 @@ -#!/usr/bin/env sh - -# Description: Add selection or hovered file/directory to cmus queue -# -# Dependencies: cmus, pgrep, xdotool (optional) -# -# Notes: -# 1. If adding selection, files/dirs are added in the same order they were selected in nnn -# 2. A new window will be opened if cmus is not running already, playback will start immediately -# 3. If cmus is already running, files will be appended to the queue with no forced playback -# -# TODO: -# 1. Add cava and cmus-lyrics as optional dependencies -# 2. Start cava and/or cmus-lyrics in tmux or kitty panes next to cmus -# -# Shell: POSIX compliant -# Author: Kabouik - -# (Optional) Set preferred terminal emulator for cmus if not set in your env, -# or leave commented out to use OS default -#TERMINAL="kitty" - -if ! type cmus >/dev/null; then - printf "cmus missing" - read -r _ - exit 1 -fi - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -start_cmus() { - type xdotool >/dev/null && nnnwindow="$(xdotool getactivewindow)" - case "$TERMINAL" in - kitty | gnome-terminal | st) - nohup "$TERMINAL" -- cmus & ;; - havoc) - nohup "$TERMINAL" cmus & ;; - "") - nohup x-terminal-emulator -e cmus & ;; - *) - nohup "$TERMINAL" -e cmus & ;; - esac - # Give the new terminal some time to open - until cmus-remote -C; do sleep 0.1; done - [ -n "$nnnwindow" ] && xdotool windowactivate "$nnnwindow" -} >/dev/null 2>&1 - -fill_queue() { - if [ "$REPLY" = "s" ]; then - xargs < "$selection" -0 cmus-remote -q - elif [ -n "$1" ]; then - cmus-remote -q "$1" - fi -} - -# If active selection,then ask what to do -if [ -s "$selection" ]; then - printf "Queue [s]election or [c]urrently hovered? [default=c]: " - read -r REPLY -fi - -# If cmus is not running, start and play queue -if ! pgrep cmus >/dev/null; then - printf "cmus is not running, starting it in a new %s window.\n" "$TERMINAL" - start_cmus - fill_queue "$1" - cmus-remote -p - printf "Files added to cmus queue.\n" -else # Append to existing queue if cmus is already running - fill_queue "$1" - printf "Files appended to current cmus queue.\n" -fi - -# Change view -cmus-remote -C "view 4" - -# Clear selection -if [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" -fi diff --git a/nnn/plugins/diffs b/nnn/plugins/diffs @@ -1,62 +0,0 @@ -#!/usr/bin/env sh - -# Description: Show diff of 2 directories or multiple files in vimdiff -# -# Notes: -# 1. vim may show the warning: 'Vim: Warning: Input is not from a terminal' -# press 'Enter' to ignore and proceed. -# 2. if only one file is in selection, the hovered file is considered as the -# second file to diff with -# -# Shell: POSIX compliant -# Authors: Arun Prakash Jana, ath3 - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -if type nvim >/dev/null 2>&1; then - diffcmd="nvim -d" -else - diffcmd="vimdiff +0" -fi - -dirdiff() { - dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$1")".XXXXXXXX) - dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$2")".XXXXXXXX) - ls -A1 "$1" > "$dir1" - ls -A1 "$2" > "$dir2" - $diffcmd "$dir1" "$dir2" - rm -- "$dir1" "$dir2" -} - -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 - dirdiff "$f1" "$f2" - 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 - - eval xargs -0 "$diffcmd" < "$selection" - fi - elif [ -n "$1" ]; then - f1="$(echo "$arr" | sed -n '1p')" - if [ -d "$f1" ] && [ -d "$1" ]; then - dirdiff "$f1" "$1" - elif [ -f "$f1" ] && [ -f "$1" ]; then - $diffcmd "$f1" "$1" - else - echo "cannot compare file with directory" - fi - else - echo "needs at least 2 files or directories selected for comparison" - fi -fi - -# Clear selection -if [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" -fi diff --git a/nnn/plugins/dragdrop b/nnn/plugins/dragdrop @@ -1,77 +0,0 @@ -#!/usr/bin/env sh - -# Description: Open a Drag and drop window, to drop files onto other programs. -# Also provides drag and drop window for files. -# -# Dependencies: dragon - https://github.com/mwh/dragon -# -# Notes: -# 1. Files that are dropped will be added to nnn's selection -# Some web-based files will be downloaded to current dir -# with curl and it may overwrite some existing files -# 2. The user has to mm to clear nnn's selection first -# -# Shell: POSIX compliant -# Author: 0xACE - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} -resp=f -all= -if type dragon-drag-and-drop >/dev/null 2>&1; then - dnd="dragon-drag-and-drop" -elif type dragon-drop >/dev/null 2>&1; then - dnd="dragon-drop" -else - dnd="dragon" -fi - -add_file () -{ - printf '%s\0' "$@" >> "$selection" -} - -use_all () -{ - printf "mark --all (a) [default=none]: " - read -r resp - if [ "$resp" = "a" ]; then - all="--all" - else - all="" - fi -} - -if [ -s "$selection" ]; then - printf "Drop file (r). Drag selection (s), Drag current directory (d) or drag current file (f) [default=f]: " - read -r resp -else - printf "Drop file (r). Drag current directory (d) or drag current file (f) [default=f]: " - read -r resp - if [ "$resp" = "s" ]; then - resp=f - fi -fi - -if [ "$resp" = "s" ]; then - use_all - sed -z 's|'"$PWD/"'||g' < "$selection" | xargs -0 "$dnd" "$all" & -elif [ "$resp" = "d" ]; then - use_all - "$dnd" "$all" "$PWD/"* & -elif [ "$resp" = "r" ]; then - true > "$selection" - "$dnd" --print-path --target | while read -r f - do - if printf "%s" "$f" | grep '^\(https\?\|ftps\?\|s\?ftp\):\/\/' ; then - curl -LJO "$f" - add_file "$PWD/$(basename "$f")" - elif [ -e "$f" ]; then - add_file "$f" - fi - done & -else - if [ -n "$1" ] && [ -e "$1" ]; then - "$dnd" "$1" & - fi -fi - diff --git a/nnn/plugins/dups b/nnn/plugins/dups @@ -1,70 +0,0 @@ -#!/usr/bin/env sh - -# Description: List non-empty duplicates in the current dir (based on size followed by MD5) -# -# Source: https://www.commandlinefu.com/commands/view/3555/find-duplicate-files-based-on-size-first-then-md5-hash -# -# Dependencies: find md5sum sort uniq xargs gsed -# -# Notes: -# 1. If the file size exceeds $size_digits digits the file will be misplaced -# 12 digits fit files up to 931GiB -# 2. Bash compatible required for mktemp -# -# Shell: Bash -# Authors: syssyphus, KlzXS - -EDITOR="${EDITOR:-vi}" -TMPDIR="${TMPDIR:-/tmp}" - -size_digits=12 -tmpfile=$(mktemp "$TMPDIR/.nnnXXXXXX") - -printf "\ -## This is an overview of all duplicate files found. -## Comment out the files you wish to remove. You will be given an option to cancel. -## Lines with double comments (##) are ignored. -## You will have the option to remove the files with force or interactively.\n -" > "$tmpfile" - -# shellcheck disable=SC2016 -find . -size +0 -type f -printf "%${size_digits}s %p\n" | sort -rn | uniq -w"${size_digits}" -D | sed -e ' -s/^ \{0,12\}\([0-9]\{0,12\}\) \(.*\)$/printf "%s %s\\n" "$(md5sum "\2")" "d\1"/ -' | tr '\n' '\0' | xargs -0 -n1 sh -c | sort | { uniq -w32 --all-repeated=separate; echo; } | sed -ne ' -h -s/^\(.\{32\}\).* d\([0-9]*\)$/## md5sum: \1 size: \2 bytes/p -g - -:loop -N -/.*\n$/!b loop -p' | sed -e 's/^.\{32\} \(.*\) d[0-9]*$/\1/' >> "$tmpfile" - -"$EDITOR" "$tmpfile" - -printf "Remove commented files? (yes/no) [default=n]: " -read -r commented - -if [ "$commented" = "y" ]; then - sedcmd="/^##.*/d; /^[^#].*/d; /^$/d; s/^# *\(.*\)$/\1/" -else - printf "Press any key to exit" - read -r _ - exit -fi - -printf "Remove with force or interactive? (f/i) [default=i]: " -read -r force - -if [ "$force" = "f" ]; then - #shellcheck disable=SC2016 - sed -e "$sedcmd" "$tmpfile" | tr '\n' '\0' | xargs -0 -r sh -c 'rm -f -- "$0" "$@" </dev/tty' -else - #shellcheck disable=SC2016 - sed -e "$sedcmd" "$tmpfile" | tr '\n' '\0' | xargs -0 -r sh -c 'rm -i -- "$0" "$@" </dev/tty' -fi - -rm -- "$tmpfile" - -printf "Press any key to exit" -read -r _ diff --git a/nnn/plugins/finder b/nnn/plugins/finder @@ -1,89 +0,0 @@ -#!/usr/bin/env bash - -# Description: Run custom search and list results in smart context -# -# Note: This plugin retains search history -# -# Usage: -# Run plugin and enter e.g. "-size +10M" to list files in current -# directory larger than 10M. By default entered expressions are -# interpreted as arguments to find. Results have to be NUL -# terminated which is done by default for find. Alternatively one -# can prepend a '$' to run a custom search program such as fd or -# ripgrep. Entered expressions will be saved in history file to -# be listed as bookmarks and and can be entered by index and edited. -# -# Shell: Bash -# Author: Arun Prakash Jana, Luuk van Baal -TMPDIR="${TMPDIR:-/tmp}" -NNN_FINDHIST="${NNN_FINDHIST:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/finderbms}" -NNN_FINDHISTLEN="${NNN_FINDHISTLEN:-10000}" - -printexamples() { - printf -- "-maxdepth 1 -name pattern --maxdepth 1 -size +100M -\$fd -0 pattern -\$fd -0 -d 2 -S +100M -\$grep -rlZ pattern -\$rg -l0 pattern -\$fzf -m | tr '\\\n' '\\\0'\n" -} - -printexprs() { - for ((i = "$1"; i < ${#fexprs[@]}; i++)); do - printf '%s\t%s\n' "$((i + 1))" "${fexprs[$i]}" - done -} - -mapexpr() { - if [ "$fexpr" -eq "$fexpr" ] 2>/dev/null; then - fexpr=${fexprs[$((fexpr - 1))]} - read -r -e -p "Search expression: " -i "$fexpr" fexpr - else - return 1 - fi -} - -readexpr() { - case "$fexpr" in - h) clear - printf "Examples:\n" - mapfile -t fexprs < <(printexamples) - printexprs 0 - read -r -p "Search expression or index: " fexpr - mapexpr - [ -n "$fexpr" ] && readexpr ;; - \$*) cmd="${fexpr:1}" ;; - *) mapexpr && readexpr - cmd="find . $fexpr -print0" ;; - esac -} - -clear -[ -f "$NNN_FINDHIST" ] || printexamples > "$NNN_FINDHIST" - -mapfile -t fexprs < <(sort "$NNN_FINDHIST" | uniq -c | sort -nr | head -n5 |\ - awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}') -printf "Most used search expressions:\n" -printexprs 0 - -mapfile -t -O"$i" fexprs < <(tac "$NNN_FINDHIST" | awk '!a[$0]++' | head -n5) -printf "Most recently used search expressions:\n" -printexprs "$i" -read -r -p "Search expression or index (h for help): " fexpr - -mapexpr - -if [ -n "$fexpr" ]; then - printf "+l" > "$NNN_PIPE" - while :; do - readexpr - eval "$cmd" > "$NNN_PIPE" && break - read -r -e -p "Search expression: " -i "$fexpr" fexpr - done - if [ -n "$fexpr" ]; then - tail -n"$NNN_FINDHISTLEN" "$NNN_FINDHIST" > "$TMPDIR/finderbms" - printf "%s\n" "$fexpr" >> "$TMPDIR/finderbms" - mv -- "$TMPDIR/finderbms" "$NNN_FINDHIST" - fi -fi diff --git a/nnn/plugins/fixname b/nnn/plugins/fixname @@ -1,75 +0,0 @@ -#!/usr/bin/env bash - -# Description: Clean filename or dirname (either hovered or selections) -# to be more shell-friendly. This script cleans -# non A-Za-z0-9._- characters. -# and replaces it with underscore (_). -# -# It supports cleaning single/double quote, newline, -# leading, trailing spaces. -# -# eg. -# to be continued (つづく).mp4 -> to_be_continued______.mp4 -# [work] stuff.txt -> _work__stuff.txt -# home's server -> home_s_server -# qwe\trty -> __qwe_rty -# -# And if there are two almost similar filenames -# like: 'asd]f' and 'asd f' both will be renamed to 'asd_f', -# to avoid overwriting, the last file will be prepended by _. -# So they will be: 'asd_f' and '_asd_f' -# -# Dependencies: sed -# -# Shell: Bash -# Author: Benawi Adha - -prompt=true -sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -cleanup() { - # printf "%s" "$1" | sed -e 's/[^A-Za-z0-9._-]/_/g' - printf "%s" "$1" | sed 's/[^A-Za-z0-9._-]/_/g' | sed ':a;N;$!ba;s/\n/_/g' -} - -if [ -s "$sel" ]; then - targets=() - while IFS= read -r -d '' i || [ -n "$i" ]; do - targets+=( "$(basename "$i")" ) - done < "$sel" -else - targets=("$1") -fi - -for i in "${targets[@]}"; do - printf "%s -> %s\n" "$i" "$(cleanup "$i")"; -done - -if $prompt; then - echo - printf "Proceed [Yn]? " - read -r input - case "$input" in - y|Y|'') - ;; - *) - echo "Canceled" - exit - ;; - esac -fi - -for i in "${targets[@]}"; do - if [ "$i" != "$(cleanup "$i")" ]; then - tmp='' - if [ -e "$(cleanup "$i")" ]; then - tmp='_' - fi - mv -- "$i" "$tmp$(cleanup "$i")"; - fi -done - -# Clear selection -if [ -s "$sel" ] && [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" -fi diff --git a/nnn/plugins/fzcd b/nnn/plugins/fzcd @@ -1,89 +0,0 @@ -#!/usr/bin/env sh - -# Description: Fuzzy search multiple locations read-in from a path-list file -# (or $PWD) and open the selected file's dir in a smart context. -# Dependencies: fzf, find (only for multi-location search) -# -# Details: Paths in list file should be newline-separated absolute paths. -# Paths can be file paths; the script will scan the parent dirs. -# -# The path-list file precedence is: -# - "$1" (the hovered file) if it exists, is plain-text and the -# first line points to an existing file -# - "$LIST" if set below -# - "$2" (the current directory) [mimics plugin fzcd behaviour] -# -# The path-list file can be generated easily: -# - pick the (file)paths in picker mode to path-list file -# - OR, edit selection in nnn and save as path-list file -# -# Shell: POSIX compliant -# Author: Anna Arad, Arun Prakash Jana, KlzXS - -IFS="$(printf '\n\r')" - -# shellcheck disable=SC1090,SC1091 -. "$(dirname "$0")"/.nnn-plugin-helper - -CTX=+ -LIST="${LIST:-""}" - -if ! type fzf >/dev/null 2>&1; then - printf "fzf missing" - read -r _ - exit 1 -fi - -if [ -n "$1" ] && [ "$(file -b --mime-type "$1")" = 'text/plain' ] && [ -e "$(head -1 "$1")" ]; then - LIST="$1" -elif ! [ -s "$LIST" ]; then - sel=$(fzf) - # Show only the file and parent dir - # sel=$(fzf --delimiter / --with-nth=-2,-1 --tiebreak=begin --info=hidden) - - LIST='' -fi - -if [ -n "$LIST" ]; then - if type find >/dev/null 2>&1; then - tmpfile=$(mktemp /tmp/abc-script.XXXXXX) - - while IFS= read -r path; do - if [ -d "$path" ]; then - printf "%s\n" "$path" >> "$tmpfile" - elif [ -f "$path" ]; then - printf "%s\n" "$(dirname "$path")" >> "$tmpfile" - fi - done < "$LIST" - - sel=$(xargs -d '\n' < "$tmpfile" -I{} find {} -type f -printf "%H//%P\n" | sed '/.*\/\/\(\..*\|.*\/\..*\)/d; s:/\+:/:g' | fzf --delimiter / --tiebreak=begin --info=hidden) - # Alternative for 'fd' - # sel=$(xargs -d '\n' < "$tmpfile" fd . | fzf --delimiter / --tiebreak=begin --info=hidden) - - rm -- "$tmpfile" - else - printf "find missing" - read -r _ - exit 1 - fi -fi - -if [ -n "$sel" ]; then - if [ "$sel" = "." ] || { ! [ -d "$sel" ] && ! [ -f "$sel" ]; }; then - exit 0 - fi - - # Check if the selected path returned by fzf command is absolute - case $sel in - /*) nnn_cd "$sel" "$CTX" ;; - *) - # Remove "./" prefix if it exists - sel="${sel#./}" - - if [ "$PWD" = "/" ]; then - nnn_cd "/$sel" "$CTX" - else - nnn_cd "$PWD/$sel" "$CTX" - fi;; - esac -fi diff --git a/nnn/plugins/fzhist b/nnn/plugins/fzhist @@ -1,53 +0,0 @@ -#!/usr/bin/env sh - -# Description: Fuzzy find a command from history, -# edit in $EDITOR and run as a command -# -# Note: Supports only bash, zsh and fish history -# -# TODO: For zsh there's also $ZDOTDIR which might need to be checked as well for the -z $HISTFILE && -n $ZDOTDIR case. -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if type fzf >/dev/null 2>&1; then - fuzzy=fzf -else - exit 1 -fi - -shellname="$(basename "$SHELL")" - -if [ "$shellname" = "bash" ]; then - if [ -f "$HISTFILE" ]; then - hist_file="$HISTFILE" - else - hist_file="$HOME/.bash_history" - fi - entry="$("$fuzzy" < "$hist_file")" -elif [ "$shellname" = "zsh" ]; then - if [ -f "$HISTFILE" ]; then - hist_file="$HISTFILE" - else - hist_file="$HOME/.zsh_history" - fi - entry="$("$fuzzy" < "$hist_file")" -elif [ "$shellname" = "fish" ]; then - hist_file="$HOME/.local/share/fish/fish_history" - entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | "$fuzzy")" -fi - -if [ -n "$entry" ]; then - tmpfile=$(mktemp) - echo "$entry" >> "$tmpfile" - $EDITOR "$tmpfile" - - if [ -s "$tmpfile" ]; then - $SHELL -c "$(cat "$tmpfile")" - fi - - rm -- "$tmpfile" - - printf "Press any key to exit" - read -r _ -fi diff --git a/nnn/plugins/fzopen b/nnn/plugins/fzopen @@ -1,85 +0,0 @@ -#!/usr/bin/env sh - -# Description: Regular mode: -# Fuzzy find a file in directory subtree. -# Opens in $VISUAL or $EDITOR if text. -# Opens other type of files with xdg-open. -# Work only with a single file selected. -# -# Picker mode: -# If picker mode output file is passed, it -# will be overwritten with any picked files. -# Leaves untouched if no file is picked. -# Works with single/multiple files selected. -# -# Dependencies: fd/find, fzf/skim, xdg-open/open (on macOS) -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke" -USE_NUKE=0 - -# shellcheck disable=SC1090,SC1091 -. "$(dirname "$0")"/.nnn-plugin-helper - -if type fzf >/dev/null 2>&1; then - cmd="$FZF_DEFAULT_COMMAND" - if type fd >/dev/null 2>&1; then - [ -z "$cmd" ] && cmd="fd -t f 2>/dev/null" - else - [ -z "$cmd" ] && cmd="find . -type f 2>/dev/null" - fi - entry="$(eval "$cmd" | fzf -m)" - # To show only the file name - # entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden) -elif type sk >/dev/null 2>&1; then - entry=$(find . -type f 2>/dev/null | sk) -else - exit 1 -fi - -# Check for picker mode -if [ "$3" ]; then - if [ "$entry" ]; then - case "$entry" in - /*) fullpath="$entry" ;; - *) fullpath="$PWD/$entry" ;; - esac - if [ "-" = "$3" ]; then - printf "%s\n" "$fullpath" - else - printf "%s\n" "$fullpath" > "$3" - fi - - # Tell `nnn` to clear its internal selection - printf "%s" "0p" > "$NNN_PIPE" - fi - - exit 0 -fi - -if [ "$entry" ]; then - if [ "$USE_NUKE" -ne 0 ]; then - "$NUKE" "$entry" - exit 0 - fi - - # Open the file (works for a single file only) - cmd_file="" - cmd_open="" - if uname | grep -q "Darwin"; then - cmd_file="file -bIL" - cmd_open="open" - else - cmd_file="file -biL" - cmd_open="xdg-open" - fi - - case "$($cmd_file "$entry")" in - *text*) - "${VISUAL:-$EDITOR}" "$entry" ;; - *) - $cmd_open "$entry" >/dev/null 2>&1 ;; - esac -fi diff --git a/nnn/plugins/fzplug b/nnn/plugins/fzplug @@ -1,59 +0,0 @@ -#!/usr/bin/env sh - -# Description: Fuzzy find and execute nnn plugins (and optionally, -# custom scripts located elsewhere). -# Description and details of plugins can be previewed -# from the fzf interface. Use `?` to toggle preview -# pane on and off, ^Up/^Dn to scroll. -# -# Dependencies: find, fzf, cat (or bat, if installed) -# -# Note: For better compatibility with as many nnn plugins as possible, -# fzplug will first execute the chosen script on the file hovered -# in nnn, and upon failure, try to run it with no target (i.e on -# an active selection, if present). -# -# Shell: POSIX compliant -# Author: Kabouik - -# Optional scripts sources - -# Leave blank or fill with the absolute path of a folder containing executable -# scripts other than nnn plugins (e.g., "$HOME/.local/share/nautilus/scripts", -# since there are numerous Nautilus script git repositories). -# Add extra variables if needed, make sure you call them in the find command. - -#CUSTOMDIR1="$HOME/.local/share/nautilus/scripts" -CUSTOMDIR1="" -CUSTOMDIR2="" - -nnnpluginsdir="$HOME/.config/nnn/plugins" - -# Preview with bat if installed -if type bat >/dev/null; then - BAT="bat --terminal-width='$(tput cols)' --decorations=always --color=always --style='${BAT_STYLE:-header,numbers}'" -fi - -plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \ --maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \ - "${BAT:-cat} {}" --preview-window="right:66%:wrap" --delimiter / \ - --with-nth -1 --bind="?:toggle-preview") - -# Try running the script on the hovered file, and abort -# abort if no plugin was selected (ESC or ^C pressed). -err=0 -if ! [ "$plugin" = "" ]; then - "$plugin" "$1" || err=1 -fi - -# If attempt with hovered file fails, try without any target -# (nnn selections should still be passed to the script in that case) -if [ "$err" -eq "1" ]; then - clear && "$plugin" || err=2 -fi - -# Abort and show error if both fail -if [ "$err" -eq "2" ]; then - sep="\n---\n" - printf "$sep""Failed to execute '%s'. See error above or try without fzfplug. Press return to continue. " "$plugin" && read -r _ && clear -fi diff --git a/nnn/plugins/getplugs b/nnn/plugins/getplugs @@ -1,70 +0,0 @@ -#!/usr/bin/env sh - -# Description: Update nnn plugins to installed nnn version -# -# Shell: POSIX compliant -# Authors: Arun Prakash Jana, KlzXS - -CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/ -PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins - -merge () { - if type nvim >/dev/null 2>&1; then - nvim -d "$1" "$2" - else - vimdiff +0 "$1" "$2" - fi -} - -prompt () { - printf "%s\n" "Plugin $1 already exists and is different." - printf "Keep (k), merge (m), overwrite (o) [default: k]? " - read -r operation - - if [ "$operation" = "m" ]; then - op="merge" - elif [ "$operation" = "o" ]; then - op="cp -vRf --" - else - op="true" - fi -} - -if [ "$1" = "master" ] ; then - VER="master" - ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz -elif type nnn >/dev/null 2>&1; then - VER=$(nnn -V) - ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz -else - echo "nnn is not installed" - exit 1 -fi - -# backup any earlier plugins -if [ -d "$PLUGIN_DIR" ]; then - tar -C "$CONFIG_DIR" -czf "$CONFIG_DIR""plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/ -fi - -mkdir -p "$PLUGIN_DIR" -cd "$CONFIG_DIR" || exit 1 -curl -Ls "$ARCHIVE_URL" -o nnn-"$VER".tar.gz -tar -zxf nnn-"$VER".tar.gz - -cd nnn-"$VER"/plugins || exit 1 - -# shellcheck disable=SC2044 -# We do not use obnoxious names for plugins -for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do - if [ -f ../../plugins/"$f" ]; then - if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then - prompt "$f" - $op "$f" ../../plugins/ - fi - else - cp -vRf -- "$f" ../../plugins/ - fi -done -cd ../.. || exit 1 - -rm -rf nnn-"$VER"/ nnn-"$VER".tar.gz diff --git a/nnn/plugins/gitroot b/nnn/plugins/gitroot @@ -1,15 +0,0 @@ -#!/usr/bin/env sh - -# Description: cd to the top level of the current git repository in the current context -# Dependencies: git -# Shell: sh -# Author: https://github.com/PatrickF1 - -root="$(git rev-parse --show-toplevel 2>/dev/null)" -if [ -n "$root" ]; then - printf "%s" "0c$root" > "$NNN_PIPE" -else - printf "Not in a git repository" - read -r _ - exit 1 -fi diff --git a/nnn/plugins/gpgd b/nnn/plugins/gpgd @@ -1,28 +0,0 @@ -#!/usr/bin/env sh - -# Description: Decrypts selected files using gpg. The contents of the -# decrypted file are stored in a file with extension .dec -# -# Note: If an appropriate private key cannot be found gpg silently -# prints a message in the background and no files are written. -# -# Shell: POSIX compliant -# Author: KlzXS - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -printf "(s)election/(c)urrent? [default=c] " -read -r resp - -if [ "$resp" = "s" ]; then - files=$(tr '\0' '\n' < "$selection") -else - files=$1 -fi - -printf "%s" "$files" | xargs -n1 -I{} gpg --decrypt --output "{}.dec" {} - -# Clear selection -if [ "$resp" = "s" ] && [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" -fi diff --git a/nnn/plugins/gpge b/nnn/plugins/gpge @@ -1,45 +0,0 @@ -#!/usr/bin/env sh - -# Description: Encrypts selected files using gpg. Can encrypt -# asymmetrically (key) or symmetrically (passphrase). -# If asymmetric encryption is chosen a key can be -# chosen from the list of capable public keys using fzf. -# -# Note: Symmetric encryption only works for a single (current) file as per gpg limitations -# -# Shell: POSIX compliant -# Author: KlzXS - -# shellcheck disable=SC1090,SC1091 -. "$(dirname "$0")"/.nnn-plugin-helper - -printf "(s)ymmetric, (a)symmetric? [default=a] " -read -r symmetry - -if [ "$symmetry" = "s" ]; then - gpg --symmetric "$1" -else - if nnn_use_selection; then - clear_sel=1 - # shellcheck disable=SC2154 - files=$(tr '\0' '\n' < "$selection") - else - clear_sel=0 - files=$1 - fi - - keyids=$(gpg --list-public-keys --with-colons | grep -E "pub:(.*:){10}.*[eE].*:" | awk -F ":" '{print $5}') - - #awk needs literal $10 - #shellcheck disable=SC2016 - keyuids=$(printf "%s" "$keyids" | xargs -n1 -I{} sh -c 'gpg --list-key --with-colons "{}" | grep "uid" | awk -F ":" '\''{printf "%s %s\n", "{}", $10}'\''') - - recipient=$(printf "%s" "$keyuids" | fzf | awk '{print $1}') - - printf "%s" "$files" | xargs -n1 gpg --encrypt --recipient "$recipient" - - # Clear selection - if [ "$clear_sel" -eq 1 ] && [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" - fi -fi diff --git a/nnn/plugins/gsconnect b/nnn/plugins/gsconnect @@ -1,21 +0,0 @@ -#!/usr/bin/env sh - -#set -x -# Description: Send the selected (or hovered) files to your Android device using gsconnect daemon.js. -# GSConnect must be configured on the Android device and the PC. -# -# Shell: POSIX compliant -# Author: Darukutsu -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} -gsconnect=$HOME/.local/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/daemon.js -ids=$($gsconnect -l) - -for id in $ids; do - if [ -s "$selection" ]; then - xargs -0 < "$selection" -I{} "$gsconnect" -d "$id" --share-file="{}" - # Clear selection - printf "-" > "$NNN_PIPE" - else - "$gsconnect" -d "$id" --share-file="$2/$1" - fi -done diff --git a/nnn/plugins/gutenread b/nnn/plugins/gutenread @@ -1,49 +0,0 @@ -#!/usr/bin/env sh - -# Description: Browse Project Gutenberg catalogue by popularity, then download -# and read a book of your choice. -# -# Details: Set the variable EBOOK_ID to download in html format and read in w3m. -# Clear EBOOK_ID to browse available ebooks by popularity and set it to -# the ID once you find an interesting one. -# To download and read in epub format set READER to an epub reader like -# epr: https://github.com/wustho/epr -# -# More on EBOOK_ID: -# Wuthering Heights by Emily Brontë is at https://www.gutenberg.org/ebooks/768 -# So EBOOK_ID would be 768 -# -# Downloaded ebooks are at ${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/ -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -EBOOK_ID="${EBOOK_ID:-""}" -DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/$EBOOK_ID" -BROWSE_LINK="https://www.gutenberg.org/ebooks/search/?sort_order=downloads" -BROWSER="${BROWSER:-w3m}" -READER="${READER:-""}" - -if [ -n "$EBOOK_ID" ]; then - if [ ! -e "$DIR" ]; then - mkdir -p "$DIR" - cd "$DIR" || exit 1 - - if [ -z "$READER" ]; then - curl -L -O "https://www.gutenberg.org/files/$EBOOK_ID/$EBOOK_ID-h.zip" - unzip "$EBOOK_ID"-h.zip - else - curl -L -o "$EBOOK_ID".epub "https://www.gutenberg.org/ebooks/$EBOOK_ID.epub.noimages" - fi - fi - - if [ -d "$DIR" ]; then - if [ -z "$READER" ]; then - "$BROWSER" "$DIR/$EBOOK_ID-h/$EBOOK_ID-h.htm" - else - "$READER" "$DIR/$EBOOK_ID.epub" - fi - fi -else - "$BROWSER" "$BROWSE_LINK" -fi diff --git a/nnn/plugins/imgresize b/nnn/plugins/imgresize @@ -1,31 +0,0 @@ -#!/usr/bin/env sh - -# Description: Resize images in a directory to screen resolution with imgp -# -# Dependencipes: imgp - https://github.com/jarun/imgp -# -# Notes: -# 1. Set res to avoid the desktop resolution prompt each time -# 2. MINSIZE is set to 1MB by default, adjust it if you want -# 3. imgp options used: -# a - adaptive mode -# c - convert PNG to JPG -# k - skip images matching specified hres/vres -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -# set resolution (e.g. 1920x1080) -res="${RESOLUTION}" - -# set minimum image size (in bytes) to resize (default: 1MB) -MINSIZE="${MINSIZE:-1048576}" - -if [ -z "$res" ]; then - printf "desktop resolution (hxv): " - read -r res -fi - -if [ -n "$res" ] && [ -n "$MINSIZE" ]; then - imgp -ackx "$res" -s "$MINSIZE" -fi diff --git a/nnn/plugins/imgur b/nnn/plugins/imgur @@ -1,597 +0,0 @@ -#!/usr/bin/env bash - -########################################################################## -# The MIT License -# -# Copyright (c) jomo -# -# Permission is hereby granted, free of charge, -# to any person obtaining a copy of this software and -# associated documentation files (the "Software"), to -# deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom -# the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice -# shall be included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR -# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -########################################################################## - -# https://github.com/jomo/imgur-screenshot -# https://help.imgur.com/hc/en-us/articles/209592766-Tools-for-Imgur -# -# Slightly modified for `nnn` integration -# -# Shell: Bash -# Description: Upload an image file to imgur - -if [ "${1}" = "--debug" ]; then - echo "########################################" - echo "Enabling debug mode" - echo "Please remove credentials before pasting" - echo "########################################" - echo "" - uname -a - for arg in ${0} "${@}"; do - echo -n "'${arg}' " - done - echo -e "\n" - shift - set -x -fi - -current_version="v1.7.4" - -function is_mac() { - uname | grep -q "Darwin" -} - -### IMGUR-SCREENSHOT DEFAULT CONFIG #### - -# You can override the config in ~/.config/imgur-screenshot/settings.conf - -imgur_anon_id="ea6c0ef2987808e" -imgur_icon_path="${HOME}/Pictures/imgur.png" - -imgur_acct_key="" -imgur_secret="" -login="false" -album_title="" -album_id="" -credentials_file="${HOME}/.config/imgur-screenshot/credentials.conf" - -file_name_format="imgur-%Y_%m_%d-%H:%M:%S.png" # when using scrot, must end with .png! -file_dir="${HOME}/Pictures" - -upload_connect_timeout="5" -upload_timeout="120" -upload_retries="1" - -# shellcheck disable=SC2034 -if is_mac; then - screenshot_select_command="screencapture -i %img" - screenshot_window_command="screencapture -iWa %img" - screenshot_full_command="screencapture %img" - open_command="open %url" -else - screenshot_select_command="scrot -s %img" - screenshot_window_command="scrot %img" - screenshot_full_command="scrot %img" - open_command="xdg-open %url" -fi -open="true" - -mode="select" -edit_command="gimp %img" -edit="false" -exit_on_album_creation_fail="true" - -log_file="${HOME}/.imgur-screenshot.log" - -auto_delete="" -copy_url="true" -keep_file="true" -check_update="true" - -# NOTICE: if you make changes here, also edit the docs at -# https://github.com/jomo/imgur-screenshot/wiki/Config - -# You can override the config in ~/.config/imgur-screenshot/settings.conf - -############## END CONFIG ############## - -settings_path="${HOME}/.config/imgur-screenshot/settings.conf" -if [ -f "${settings_path}" ]; then - # shellcheck disable=SC1090 - source "${settings_path}" -fi - -# dependency check -if [ "${1}" = "--check" ]; then - (type grep &>/dev/null && echo "OK: found grep") || echo "ERROR: grep not found" - if is_mac; then - if type growlnotify &>/dev/null; then - echo "OK: found growlnotify" - elif type terminal-notifier &>/dev/null; then - echo "OK: found terminal-notifier" - else - echo "ERROR: growlnotify nor terminal-notifier found" - fi - (type screencapture &>/dev/null && echo "OK: found screencapture") || echo "ERROR: screencapture not found" - (type pbcopy &>/dev/null && echo "OK: found pbcopy") || echo "ERROR: pbcopy not found" - else - (type notify-send &>/dev/null && echo "OK: found notify-send") || echo "ERROR: notify-send (from libnotify-bin) not found" - (type scrot &>/dev/null && echo "OK: found scrot") || echo "ERROR: scrot not found" - (type xclip &>/dev/null && echo "OK: found xclip") || echo "ERROR: xclip not found" - fi - (type curl &>/dev/null && echo "OK: found curl") || echo "ERROR: curl not found" - exit 0 -fi - - -# notify <'ok'|'error'> <title> <text> -function notify() { - if is_mac; then - if type growlnotify &>/dev/null; then - growlnotify --icon "${imgur_icon_path}" --iconpath "${imgur_icon_path}" --title "${2}" --message "${3}" - else - terminal-notifier -appIcon "${imgur_icon_path}" -contentImage "${imgur_icon_path}" -title "imgur: ${2}" -message "${3}" - fi - else - if [ "${1}" = "error" ]; then - notify-send -a ImgurScreenshot -u critical -c "im.error" -i "${imgur_icon_path}" -t 500 "imgur: ${2}" "${3}" - else - notify-send -a ImgurScreenshot -u low -c "transfer.complete" -i "${imgur_icon_path}" -t 500 "imgur: ${2}" "${3}" - fi - fi -} - -function take_screenshot() { - echo "Please select area" - is_mac || sleep 0.1 # https://bbs.archlinux.org/viewtopic.php?pid=1246173#p1246173 - - cmd="screenshot_${mode}_command" - cmd=${!cmd//\%img/${1}} - - if ! shot_err="$(${cmd} &>/dev/null)"; then #takes a screenshot with selection - echo "Failed to take screenshot '${1}': '${shot_err}'. For more information visit https://github.com/jomo/imgur-screenshot/wiki/Troubleshooting" | tee -a "${log_file}" - notify error "Something went wrong :(" "Information has been logged" - exit 1 - fi -} - -function check_for_update() { - # exit non-zero on HTTP error, output only the body (no stats) but output errors, follow redirects, output everything to stdout - remote_version="$(curl --compressed -fsSL --stderr - "https://api.github.com/repos/jomo/imgur-screenshot/releases" | grep -Em 1 --color 'tag_name":\s*".*"' | cut -d '"' -f 4)" - if [ -n "$remote_version" ]; then - if [ ! "${current_version}" = "${remote_version}" ] && [ -n "${current_version}" ] && [ -n "${remote_version}" ]; then - echo "Update found!" - echo "Version ${remote_version} is available (You have ${current_version})" - notify ok "Update found" "Version ${remote_version} is available (You have ${current_version}). https://github.com/jomo/imgur-screenshot" - echo "Check https://github.com/jomo/imgur-screenshot/releases/${remote_version} for more info." - elif [ -z "${current_version}" ] || [ -z "${remote_version}" ]; then - echo "Invalid empty version string" - echo "Current (local) version: '${current_version}'" - echo "Latest (remote) version: '${remote_version}'" - else - echo "Version ${current_version} is up to date." - fi - else - echo "Failed to check for latest version: ${remote_version}" - fi -} - -function check_oauth2_client_secrets() { - if [ -z "${imgur_acct_key}" ] || [ -z "${imgur_secret}" ]; then - echo "In order to upload to your account, register a new application at:" - echo "https://api.imgur.com/oauth2/addclient" - echo "Select 'OAuth 2 authorization without a callback URL'" - echo "Then, set the imgur_acct_key (Client ID) and imgur_secret in your config." - exit 1 - fi -} - -function load_access_token() { - token_expire_time=0 - # check for saved access_token and its expiration date - if [ -f "${credentials_file}" ]; then - # shellcheck disable=SC1090 - source "${credentials_file}" - fi - current_time="$(date +%s)" - preemptive_refresh_time="$((10*60))" - expired="$((current_time > (token_expire_time - preemptive_refresh_time)))" - if [ -n "${refresh_token}" ]; then - # token already set - if [ "${expired}" -eq "0" ]; then - # token expired - refresh_access_token "${credentials_file}" - fi - else - acquire_access_token "${credentials_file}" - fi -} - -function acquire_access_token() { - check_oauth2_client_secrets - # prompt for a PIN - authorize_url="https://api.imgur.com/oauth2/authorize?client_id=${imgur_acct_key}&response_type=pin" - echo "Go to" - echo "${authorize_url}" - echo "and grant access to this application." - read -rp "Enter the PIN: " imgur_pin - - if [ -z "${imgur_pin}" ]; then - echo "PIN not entered, exiting" - exit 1 - fi - - # exchange the PIN for access token and refresh token - response="$(curl --compressed -fsSL --stderr - \ - -F "client_id=${imgur_acct_key}" \ - -F "client_secret=${imgur_secret}" \ - -F "grant_type=pin" \ - -F "pin=${imgur_pin}" \ - https://api.imgur.com/oauth2/token)" - save_access_token "${response}" "${1}" -} - -function refresh_access_token() { - check_oauth2_client_secrets - token_url="https://api.imgur.com/oauth2/token" - # exchange the refresh token for access_token and refresh_token - if ! response="$(curl --compressed -fsSL --stderr - \ - -F "client_id=${imgur_acct_key}" \ - -F "client_secret=${imgur_secret}" \ - -F "grant_type=refresh_token" \ - -F "refresh_token=${refresh_token}" \ - "${token_url}" - )"; then - # curl failed - handle_upload_error "${response}" "${token_url}" - exit 1 - fi - save_access_token "${response}" "${1}" -} - -function save_access_token() { - if ! grep -q "access_token" <<<"${1}"; then - # server did not send access_token - echo "Error: Something is wrong with your credentials:" - echo "${1}" - exit 1 - fi - - access_token="$(grep -Eo 'access_token":".*"' <<<"${1}" | cut -d '"' -f 3)" - refresh_token="$(grep -Eo 'refresh_token":".*"' <<<"${1}" | cut -d '"' -f 3)" - expires_in="$(grep -Eo 'expires_in":[0-9]*' <<<"${1}" | cut -d ':' -f 2)" - token_expire_time="$(( $(date +%s) + expires_in ))" - - # create dir if not exist - mkdir -p "$(dirname "${2}")" 2>/dev/null - touch "${2}" && chmod 600 "${2}" - cat <<EOF > "${2}" -access_token="${access_token}" -refresh_token="${refresh_token}" -token_expire_time="${token_expire_time}" -EOF -} - -function fetch_account_info() { - response="$(curl --compressed --connect-timeout "${upload_connect_timeout}" -m "${upload_timeout}" --retry "${upload_retries}" -fsSL --stderr - -H "Authorization: Bearer ${access_token}" https://api.imgur.com/3/account/me)" - if grep -Eq '"success":\s*true' <<<"${response}"; then - username="$(grep -Eo '"url":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - echo "Logged in as ${username}." - echo "https://${username}.imgur.com" - else - echo "Failed to fetch info: ${response}" - fi -} - -function delete_image() { - response="$(curl --compressed -X DELETE -fsSL --stderr - -H "Authorization: Client-ID ${1}" "https://api.imgur.com/3/image/${2}")" - if grep -Eq '"success":\s*true' <<<"${response}"; then - echo "Image successfully deleted (delete hash: ${2})." >> "${3}" - else - echo "The Image could not be deleted: ${response}." >> "${3}" - fi -} - -function upload_authenticated_image() { - echo "Uploading '${1}'..." - title="$(echo "${1}" | rev | cut -d "/" -f 1 | cut -d "." -f 2- | rev)" - if [ -n "${album_id}" ]; then - response="$(curl --compressed --connect-timeout "${upload_connect_timeout}" -m "${upload_timeout}" --retry "${upload_retries}" -fsSL --stderr - -F "title=${title}" -F "image=@\"${1}\"" -F "album=${album_id}" -H "Authorization: Bearer ${access_token}" https://api.imgur.com/3/image)" - else - response="$(curl --compressed --connect-timeout "${upload_connect_timeout}" -m "${upload_timeout}" --retry "${upload_retries}" -fsSL --stderr - -F "title=${title}" -F "image=@\"${1}\"" -H "Authorization: Bearer ${access_token}" https://api.imgur.com/3/image)" - fi - - # JSON parser premium edition (not really) - if grep -Eq '"success":\s*true' <<<"${response}"; then - img_id="$(grep -Eo '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - img_ext="$(grep -Eo '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https! - del_id="$(grep -Eo '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - - if [ -n "${auto_delete}" ]; then - export -f delete_image - echo "Deleting image in ${auto_delete} seconds." - nohup /bin/bash -c "sleep ${auto_delete} && delete_image ${imgur_anon_id} ${del_id} ${log_file}" & - fi - - handle_upload_success "https://i.imgur.com/${img_id}.${img_ext}" "https://imgur.com/delete/${del_id}" "${1}" - else # upload failed - err_msg="$(grep -Eo '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - test -z "${err_msg}" && err_msg="${response}" - handle_upload_error "${err_msg}" "${1}" - fi -} - -function upload_anonymous_image() { - echo "Uploading '${1}'..." - title="$(echo "${1}" | rev | cut -d "/" -f 1 | cut -d "." -f 2- | rev)" - if [ -n "${album_id}" ]; then - response="$(curl --compressed --connect-timeout "${upload_connect_timeout}" -m "${upload_timeout}" --retry "${upload_retries}" -fsSL --stderr - -H "Authorization: Client-ID ${imgur_anon_id}" -F "title=${title}" -F "image=@\"${1}\"" -F "album=${album_id}" https://api.imgur.com/3/image)" - else - response="$(curl --compressed --connect-timeout "${upload_connect_timeout}" -m "${upload_timeout}" --retry "${upload_retries}" -fsSL --stderr - -H "Authorization: Client-ID ${imgur_anon_id}" -F "title=${title}" -F "image=@\"${1}\"" https://api.imgur.com/3/image)" - fi - # JSON parser premium edition (not really) - if grep -Eq '"success":\s*true' <<<"${response}"; then - img_id="$(grep -Eo '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - img_ext="$(grep -Eo '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https! - del_id="$(grep -Eo '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - - if [ -n "${auto_delete}" ]; then - export -f delete_image - echo "Deleting image in ${auto_delete} seconds." - nohup /bin/bash -c "sleep ${auto_delete} && delete_image ${imgur_anon_id} ${del_id} ${log_file}" & - fi - - handle_upload_success "https://i.imgur.com/${img_id}.${img_ext}" "https://imgur.com/delete/${del_id}" "${1}" - else # upload failed - err_msg="$(grep -Eo '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - test -z "${err_msg}" && err_msg="${response}" - handle_upload_error "${err_msg}" "${1}" - fi -} - -function handle_upload_success() { - echo "" - echo "image link: ${1}" - echo "delete link: ${2}" - - if [ "${copy_url}" = "true" ] && [ -z "${album_title}" ]; then - if is_mac; then - echo -n "${1}" | pbcopy - else - echo -n "${1}" | xclip -selection clipboard - fi - echo "URL copied to clipboard" - fi - - # print to log file: image link, image location, delete link - echo -e "${1}\t${3}\t${2}" >> "${log_file}" - - notify ok "Upload done!" "${1}" - -# if [ ! -z "${open_command}" ] && [ "${open}" = "true" ]; then -# open_cmd=${open_command//\%url/${1}} -# open_cmd=${open_cmd//\%img/${2}} -# echo "Opening '${open_cmd}'" -# eval "${open_cmd}" -# fi -} - -function handle_upload_error() { - error="Upload failed: \"${1}\"" - echo "${error}" - echo -e "Error\t${2}\t${error}" >> "${log_file}" - notify error "Upload failed :(" "${1}" -} - -function handle_album_creation_success() { - echo "" - echo "Album link: ${1}" - echo "Delete hash: ${2}" - echo "" - - notify ok "Album created!" "${1}" - - if [ "${copy_url}" = "true" ]; then - if is_mac; then - echo -n "${1}" | pbcopy - else - echo -n "${1}" | xclip -selection clipboard - fi - echo "URL copied to clipboard" - fi - - # print to log file: album link, album title, delete hash - echo -e "${1}\t\"${3}\"\t${2}" >> "${log_file}" -} - -function handle_album_creation_error() { - error="Album creation failed: \"${1}\"" - echo -e "Error\t${2}\t${error}" >> "${log_file}" - notify error "Album creation failed :(" "${1}" - if [ ${exit_on_album_creation_fail} ]; then - exit 1 - fi -} - -while [ ${#} != 0 ]; do - case "${1}" in - -h | --help) - echo "usage: ${0} [--debug] [-c | --check | -v | -h | -u]" - echo " ${0} [--debug] [option]... [file]..." - echo "" - echo " --debug Enable debugging, must be first option" - echo " -h, --help Show this help, exit" - echo " -v, --version Show current version, exit" - echo " --check Check if all dependencies are installed, exit" - echo " -c, --connect Show connected imgur account, exit" - echo " -o, --open <true|false> Override 'open' config" - echo " -e, --edit <true|false> Override 'edit' config" - echo " -i, --edit-command <command> Override 'edit_command' config (include '%img'), sets --edit 'true'" - echo " -l, --login <true|false> Override 'login' config" - echo " -a, --album <album_title> Create new album and upload there" - echo " -A, --album-id <album_id> Override 'album_id' config" - echo " -k, --keep-file <true|false> Override 'keep_file' config" - echo " -d, --auto-delete <s> Automatically delete image after <s> seconds" - echo " -u, --update Check for updates, exit" - echo " file Upload file instead of taking a screenshot" - exit 0;; - -v | --version) - echo "${current_version}" - exit 0;; - -s | --select) - mode="select" - shift;; - -w | --window) - mode="window" - shift;; - -f | --full) - mode="full" - shift;; - -o | --open) - # shellcheck disable=SC2034 - open="${2}" - shift 2;; - -e | --edit) - edit="${2}" - shift 2;; - -i | --edit-command) - edit_command="${2}" - edit="true" - shift 2;; - -l | --login) - login="${2}" - shift 2;; - -c | --connect) - load_access_token - fetch_account_info - exit 0;; - -a | --album) - album_title="${2}" - shift 2;; - -A | --album-id) - album_id="${2}" - shift 2;; - -k | --keep-file) - keep_file="${2}" - shift 2;; - -d | --auto-delete) - auto_delete="${2}" - shift 2;; - -u | --update) - check_for_update - exit 0;; - *) - upload_files=("${@}") - break;; - esac -done - -if [ "${login}" = "true" ]; then - # load before changing directory - load_access_token -fi - - -if [ -n "${album_title}" ]; then - if [ "${login}" = "true" ]; then - response="$(curl -fsSL --stderr - \ - -F "title=${album_title}" \ - -H "Authorization: Bearer ${access_token}" \ - https://api.imgur.com/3/album)" - else - response="$(curl -fsSL --stderr - \ - -F "title=${album_title}" \ - -H "Authorization: Client-ID ${imgur_anon_id}" \ - https://api.imgur.com/3/album)" - fi - if grep -Eq '"success":\s*true' <<<"${response}"; then # Album creation successful - echo "Album '${album_title}' successfully created" - album_id="$(grep -Eo '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - del_id="$(grep -Eo '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - handle_album_creation_success "https://imgur.com/a/${album_id}" "${del_id}" "${album_title}" - - if [ "${login}" = "false" ]; then - album_id="${del_id}" - fi - else # Album creation failed - err_msg="$(grep -Eo '"error":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - test -z "${err_msg}" && err_msg="${response}" - handle_album_creation_error "${err_msg}" "${album_title}" - fi -fi - -if [ -z "${upload_files[*]}" ]; then - upload_files[0]="" -fi - -for upload_file in "${upload_files[@]}"; do - - if [ -z "${upload_file}" ]; then - cd "${file_dir}" || exit 1 - - # new filename with date - img_file="$(date +"${file_name_format}")" - take_screenshot "${img_file}" - else - # upload file instead of screenshot - img_file="${upload_file}" - fi - - # get full path - #cd "$(dirname "$(realpath "${img_file}")")" - #img_file="$(realpath "${img_file}")" - - # check if file exists - if ! [ -f "${img_file}" ]; then - echo "file '${img_file}' doesn't exist !" - read -r _ - exit 1 - fi - - # open image in editor if configured - if [ "${edit}" = "true" ]; then - edit_cmd=${edit_command//\%img/${img_file}} - echo "Opening editor '${edit_cmd}'" - if ! (eval "${edit_cmd}"); then - echo "Error for image '${img_file}': command '${edit_cmd}' failed, not uploading. For more information visit https://github.com/jomo/imgur-screenshot/wiki/Troubleshooting" | tee -a "${log_file}" - notify error "Something went wrong :(" "Information has been logged" - exit 1 - fi - fi - - if [ "${login}" = "true" ]; then - upload_authenticated_image "${img_file}" - else - upload_anonymous_image "${img_file}" - fi - - # delete file if configured - if [ "${keep_file}" = "false" ] && [ -z "${1}" ]; then - echo "Deleting temp file ${file_dir}/${img_file}" - rm -rf -- "${img_file}" - fi - - echo "" -done - - -if [ "${check_update}" = "true" ]; then - check_for_update -fi - -read -r _ diff --git a/nnn/plugins/imgview b/nnn/plugins/imgview @@ -1,113 +0,0 @@ -#!/usr/bin/env sh - -# Description: Open hovered or current directory in image viewer. -# Generates media thumbnails with optional dependencies. -# -# Dependencies: -# - imv (https://github.com/eXeC64/imv) or, -# - sxiv (https://github.com/muennich/sxiv) or, -# - nsxiv (https://codeberg.org/nsxiv/nsxiv) or, -# - ucollage (https://github.com/ckardaris/ucollage) or, -# - lsix (https://github.com/hackerb9/lsix), or -# - viu (https://github.com/atanunq/viu), or -# - catimg (https://github.com/posva/catimg), or -# - optional: ffmpeg for audio thumbnails (album art) -# - optional: ffmpegthumbnailer for video thumbnails -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana, Luuk van Baal -# -# Consider setting NNN_PREVIEWDIR to $XDG_CACHE_HOME/nnn/previews -# if you want to keep media thumbnails on disk between reboots. -NNN_PREVIEWDIR="${NNN_PREVIEWDIR:-${TMPDIR:-/tmp}/nnn/previews}" - -exit_prompt() { - [ -n "$1" ] && printf "%s\n" "$1" - printf "%s" "Press any key to exit..." - cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" - clear - exit -} - -make_thumbs() { - mkdir -p "$NNN_PREVIEWDIR$dir" || return - if [ "$1" = "viu" ] || [ "$1" = "catimg" ]; then - [ -d "$target" ] && exit_prompt "$1 can only display a single image" - mime="$(file -bL --mime-type -- "$target")" - case "$mime" in - audio/*) ffmpeg -i "$target" "$NNN_PREVIEWDIR$target.jpg" -y >/dev/null 2>&1 - ret="$NNN_PREVIEWDIR/$target.jpg" ;; - video/*) ffmpegthumbnailer -i "$target" -o "$NNN_PREVIEWDIR$target.jpg" 2> /dev/null - ret="$NNN_PREVIEWDIR/$target.jpg" ;; - *) ret="$target" ;; - esac - fi - for file in "$dir"/*; do - if [ ! -f "$NNN_PREVIEWDIR$file.jpg" ]; then - case "$(file -bL --mime-type -- "$file")" in - audio/*) [ "$1" != "sxiv" ] && - ffmpeg -i "$file" "$NNN_PREVIEWDIR$file.jpg" -y >/dev/null 2>&1 ;; - video/*) [ "$1" != "ucollage" ] && - ffmpegthumbnailer -i "$file" -o "$NNN_PREVIEWDIR$file.jpg" 2> /dev/null ;; - esac - fi - done - for file in "$NNN_PREVIEWDIR$dir"/*; do - filename="$(basename "$file" .jpg)" - [ ! -e "$dir/$filename" ] && rm -- "$file" 2>/dev/null - done -} - -listimages() { - find -L "$dir" "$NNN_PREVIEWDIR$dir" -maxdepth 1 -type f -print0 2>/dev/null | sort -z -} - -view_files() { - [ -f "$target" ] && count="-n $(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)" - case "$1" in - nsxiv) listimages | xargs -0 nsxiv -a "${count:--t}" -- ;; - sxiv) listimages | xargs -0 sxiv -a "${count:--t}" -- ;; - imv*) listimages | xargs -0 "$1" "${count:-}" -- ;; - esac -} - -target="$(readlink -f "$1")" -[ -d "$target" ] && dir="$target" || dir="${target%/*}" -if uname | grep -q "Darwin"; then - [ -f "$1" ] && open "$1" >/dev/null 2>&1 & -elif type lsix >/dev/null 2>&1; then - if [ -d "$target" ]; then - cd "$target" || exit_prompt - fi - make_thumbs lsix - clear - lsix - cd "$NNN_PREVIEWDIR$dir" && lsix - exit_prompt -elif type ucollage >/dev/null 2>&1; then - type ffmpeg >/dev/null 2>&1 && make_thumbs ucollage - UCOLLAGE_EXPAND_DIRS=1 ucollage "$dir" "$NNN_PREVIEWDIR$dir" || exit_prompt -elif type sxiv >/dev/null 2>&1; then - type ffmpegthumbnailer >/dev/null 2>&1 && make_thumbs sxiv - view_files sxiv >/dev/null 2>&1 & -elif type nsxiv >/dev/null 2>&1; then - type ffmpegthumbnailer >/dev/null 2>&1 && make_thumbs sxiv - view_files nsxiv >/dev/null 2>&1 & -elif type imv >/dev/null 2>&1; then - make_thumbs imv - view_files imv >/dev/null 2>&1 & -elif type imvr >/dev/null 2>&1; then - make_thumbs imv - view_files imvr >/dev/null 2>&1 & -elif type viu >/dev/null 2>&1; then - clear - make_thumbs viu - viu -n "$ret" - exit_prompt -elif type catimg >/dev/null 2>&1; then - make_thumbs catimg - catimg "$ret" - exit_prompt -else - exit_prompt "Please install sxiv/nsxiv/imv/viu/catimg/lsix." -fi diff --git a/nnn/plugins/ipinfo b/nnn/plugins/ipinfo @@ -1,13 +0,0 @@ -#!/usr/bin/env sh - -# Description: Shows the external IP address and whois information. Useful over VPNs. -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -IP=$(curl -s ifconfig.me) - -whois "$IP" -echo your external IP address is "$IP" - -read -r _ diff --git a/nnn/plugins/kdeconnect b/nnn/plugins/kdeconnect @@ -1,66 +0,0 @@ -#!/usr/bin/env sh - -# Description: Send files or folders to your Android device using kdeconnect-cli. -# kdeconnect must be configured on the Android device and the PC. -# -# Usage: -# - Hover over a file or a folder and call the plugin. -# - Alternatively, select the files and folders you would like to send, and activate the plugin. -# -# Shell: POSIX compliant -# Author: juacq97, raffaem, N-R-K - -# If you want system notification, put this equal to 1 -notify=0 - -note() { - if [ $notify = 1 ]; then - notify-send -a "Kdeconnect" "$1" - else - echo "[Kdeconnect] $1" - fi -} - -# kdeconnect doesn't cope with non-files -filter_files() { - xargs -0 -I{} sh -c ' - if [ -f "{}" ]; then - printf "%s\0" "{}"; - else - printf "Error: not a regular file: %s\n" "{}" >&2; - fi;' -} - -send() { - filter_files | xargs -0 -I{} kdeconnect-cli --name "$devname" --share {} - note "Files sent" -} - -# Select paired device -names=$(kdeconnect-cli --list-available --name-only 2>/dev/null) -if [ -z "$names" ]; then - note "No devices paired and available" - exit -fi - -ndevs=$(printf "%s" "$names" | awk 'END{print NR}') -if [ "$ndevs" -eq 1 ]; then - devname="$names" -else - printf "%s" "$names" | awk '{ print NR ". " $0 }' - printf "Pick a device: " - read -r pick - if [ -n "$pick" ] && [ "$pick" -eq "$pick" ]; then - devname=$(printf '%s' "$names" | awk "NR==$pick") - fi -fi - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} -if [ -s "$selection" ]; then - send < "$selection" - [ -p "$NNN_PIPE" ] && printf "-" > "$NNN_PIPE" # clear selection -elif [ -n "$1" ]; then - printf "%s" "$1" | send -else - note "No selection and no hovered file" -fi diff --git a/nnn/plugins/launch b/nnn/plugins/launch @@ -1,42 +0,0 @@ -#!/usr/bin/env sh - -# Description: Independent POSIX-compliant GUI application launcher. -# Fuzzy find executables in $PATH and launch an application. -# stdin, stdout, stderr are suppressed so CLI tools exit silently. -# -# To configure launch as an independent app launcher add a keybind -# to open launch in a terminal e.g., -# -# xfce4-terminal -e "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/launch -# -# Dependencies: fzf -# -# Usage: launch [delay] -# delay is in seconds, if omitted launch waits for 1 sec -# -# Integration with nnn: launch is installed with other plugins, nnn picks it up. -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -# shellcheck disable=SC2086 - -IFS=':' - -get_selection() { - if type fzf >/dev/null 2>&1; then - { IFS=':'; ls -H $PATH; } | sort | fzf - else - exit 1 - fi -} - -if selection=$( get_selection ); then - setsid "$selection" 2>/dev/null 1>/dev/null & - - if [ -n "$1" ]; then - sleep "$1" - else - sleep 1 - fi -fi diff --git a/nnn/plugins/mimelist b/nnn/plugins/mimelist @@ -1,23 +0,0 @@ -#!/usr/bin/env sh - -# Description: Find and list files by mime type in smart context -# -# Dependencies: -# - file -# - mimetype (optional, PERL File MimeInfo) -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana, Michel DHOOGE - -# shellcheck disable=SC1090,SC1091 -. "$(dirname "$0")"/.nnn-plugin-helper - -printf "mime (e.g., video/audio/image): " -read -r mime - -printf "%s" "+l" > "$NNN_PIPE" -if type mimetype >/dev/null 2>&1; then - find . | mimetype -f - | grep "$mime" | awk -F: '{printf "%s%c", $1, 0}' > "$NNN_PIPE" -else - find . | file -if- | grep "$mime" | awk -F: '{printf "%s%c", $1, 0}' > "$NNN_PIPE" -fi diff --git a/nnn/plugins/moclyrics b/nnn/plugins/moclyrics @@ -1,40 +0,0 @@ -#!/usr/bin/env sh - -# Description: Fetches the lyrics of the track currently playing in MOC -# -# Dependencies: ddgr (https://github.com/jarun/ddgr) -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -# Check if MOC server is running -cmd=$(pgrep -x mocp 2>/dev/null) -ret=$cmd -if [ -z "$ret" ]; then - exit -fi - -# Grab the output -out="$(mocp -i)" - -# Check if anything is playing -state=$(echo "$out" | grep "State:" | cut -d' ' -f2) -if ! [ "$state" = 'PLAY' ]; then - exit -fi - -# Try by Artist and Song Title first -ARTIST="$(echo "$out" | grep 'Artist:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')" -TITLE="$(echo "$out" | grep 'SongTitle:' | cut -d':' -f2 | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')" - -if [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then - ddgr -w azlyrics.com --ducky "$ARTIST" "$TITLE" -else - # Try by file name - FILENAME="$(basename "$(echo "$out" | grep 'File:' | cut -d':' -f2)")" - FILENAME="$(echo "${FILENAME%%.*}" | tr -d -)" - - if [ -n "$FILENAME" ]; then - ddgr -w azlyrics.com --ducky "$FILENAME" - fi -fi diff --git a/nnn/plugins/mocq b/nnn/plugins/mocq @@ -1,89 +0,0 @@ -#!/usr/bin/env sh - -# Description: Appends and optionally plays music in MOC -# -# Notes: -# - if selection is available, plays it, else plays the current file or directory -# - appends tracks and exits is MOC is running, else clears playlist and adds tracks -# - to let mocp shuffle tracks, set SHUFFLE=1 -# -# Shell: POSIX compliant -# Authors: Arun Prakash Jana, ath3 - -IFS="$(printf '\n\r')" -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} -cmd=$(pgrep -x mocp 2>/dev/null) -ret=$cmd - -SHUFFLE="${SHUFFLE:-0}" - -mocp_add () -{ - if [ "$SHUFFLE" = 1 ]; then - if [ "$resp" = "y" ]; then - arr=$(tr '\0' '\n' < "$selection") - elif [ -n "$1" ]; then - arr="$1" - fi - - for entry in $arr - do - if [ -d "$entry" ]; then - arr2=$arr2$(find "$entry" -type f \( ! -iname "*.m3u" ! -iname "*.pls" \)) - elif echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then - arr2=$(printf "%s\n%s" "$entry" "$arr2") - fi - done - - mocp -o shuffle - echo "$arr2" | xargs -d "\n" mocp -a - else - if [ "$resp" = "y" ]; then - xargs < "$selection" -0 mocp -a - else - mocp -a "$1" - fi - fi -} - -if [ ! -s "$selection" ] && [ -z "$1" ]; then - exit -fi - -if [ "$2" = "opener" ]; then - : -elif [ -s "$selection" ]; then - printf "Work with selection? Enter 'y' to confirm: " - read -r resp -fi - -if [ -z "$ret" ]; then - # mocp not running - mocp -S -else - # mocp running, check if it's playing - state=$(mocp -i | grep "State:" | cut -d' ' -f2) - - if [ "$state" = 'PLAY' ]; then - # add to playlist and exit - mocp_add "$1" - - # uncomment the line below to show mocp interface after appending - # mocp - - exit - fi -fi - -# clear selection and play -mocp -c -mocp_add "$1" "$resp" -mocp -p - -# uncomment the line below to show mocp interface after appending -# mocp - -# Clear selection -if [ "$resp" = "y" ] && [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" -fi diff --git a/nnn/plugins/mp3conv b/nnn/plugins/mp3conv @@ -1,41 +0,0 @@ -#!/usr/bin/env sh - -# Description: Extract audio from multimedia files and convert to mp3 -# -# Dependencies: ffmpeg compiled with libmp3lame audio codec support -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -outdir=_mp3files - -handle_multimedia() { - mime="${1}" - file="${2}" - - case "${mime}" in - audio/* | video/*) - ffmpeg -i "${file}" -vn -codec:a libmp3lame -q:a 2 "${outdir}/${file%.*}.mp3" - ;; - *) - ;; - esac -} - -printf "Process 'a'll in directory or 'c'urrent? " -read -r resp - -if [ "$resp" = "a" ]; then - if ! [ -e "${outdir}" ]; then - mkdir "${outdir}" - fi - - for f in *; do - if [ -f "${f}" ]; then - mimestr="$( file --dereference --brief --mime-type -- "${f}" )" - handle_multimedia "${mimestr}" "${f}" - fi - done -elif [ "$resp" = "c" ] && [ -f "$1" ]; then - ffmpeg -i "${1}" -vn -codec:a libmp3lame -q:a 2 "${1%.*}.mp3" -fi diff --git a/nnn/plugins/mtpmount b/nnn/plugins/mtpmount @@ -1,76 +0,0 @@ -#!/usr/bin/env sh - -# Description: Toggle mount of MTP device (eg. Android device) -# 'l' to list mountable devices -# 'n' integer associated to device to mount -# 'q'/'Return' exit -# -# Dependencies: gvfs-mtp -# -# Notes: The MTP device should be mounted at /run/user/$UID/gvfs. -# Put /run/user/$UID/gvfs to bookmark entries (NNN_BMS) for faster access. -# Make sure the device is unlocked when mounting. -# -# When doing copy-paste into MTP device, you will get an error like this: -# cp: preserving times for './gambar1.png': Operation not supported -# That just means the file is copied but timestamp won't be preserved. -# It's like doing `cp -p localfile.txt file-to-SMB.txt`. -# -# Shell: POSIX compliant -# Author: Benawi Adha - -prompt="Device number ('l' to list): " - -IFS=' -' - -lsmtp () { - devs=$(gio mount -li | grep -e 'activation_root' | sed 's/\s*activation_root=//g') - c=1 - printf "Devices list:\n" - for i in $devs; do - printf "%s %s\\n" "$c" "$i" - c=$(( c + 1 )) - done - echo -} - -lsmtp -printf "%s" "$prompt" -read -r input - -while [ -n "$input" ] -do - if [ "$input" = "l" ]; then - lsmtp - elif [ "$input" = "q" ] || [ "$input" -eq 0 ]; then - exit - elif [ "$input" -le "$(printf '%s\n' "${devs}" | grep -c '^')" ]; then - # dev=$(printf "%s\n" "$devs" | cut -d$'\n' -f${input}) - c=1 - for i in $devs; do - dev=$i - if [ "$input" -eq $c ]; then - break - fi - c=$(( c + 1 )) - done - - if (gio mount -l | grep '^Mount([1-9]).*'"$dev" ) 1>/dev/null; then - if gio mount -u "${dev}"; then - printf "%s unmounted\n" "$dev" - fi - else - if gio mount "${dev}"; then - printf "%s mounted to /run/user/\$UID/gvfs\n" "$dev" - fi - fi - echo - else - printf "Invalid input\n" - fi - - printf "%s" "$prompt" - read -r input -done - diff --git a/nnn/plugins/nbak b/nnn/plugins/nbak @@ -1,75 +0,0 @@ -#!/usr/bin/env sh - -# Description: Backup nnn configuration -# - config dir content -# - environment config -# - shell functions and aliases -# -# Shell: POSIX compliant -# Author: Léo Villeveygoux - -nnn_aliases="n nnn" - -outdir="nnn-$(whoami)@$(hostname)" - -outfile="${outdir}.tar.bz2" - -shellname="$(basename "$SHELL")" - -conffile="config.txt" - -configdir="${XDG_CONFIG_HOME:-$HOME/.config}/nnn" - -workdir="$PWD" - -tempdir="$(mktemp -d)" - -mkdir "$tempdir/$outdir" - -if [ ! -d "$tempdir" ]; then - echo "Can't create work directory." >&2 - exit 1 -fi - -cd "$tempdir/$outdir" || exit 1 - -# Backing up config dir content -cp -r -- "$configdir" . || exit 1 - -# Environment config -env | sed "s/'/'\\\\''/" |\ - awk '/^NNN_/{print "export '\''"$0"'\''"}' > "$conffile" - -# Shell functions/aliases -case "$shellname" in - bash) - for name in $nnn_aliases ; do - if [ "$(bash -ic "type -t $name")" = "function" ] ; then - bash -ic "type $name" | tail -n+2 >> "$conffile" - elif bash -ic "alias $name" >/dev/null 2>&1 ; then - bash -ic "alias $name" >> "$conffile" - fi - done - ;; - zsh) - for name in $nnn_aliases ; do - if zsh -ic "functions $name" ; then - zsh -ic "functions $name" >> "$conffile" - elif zsh -ic "alias $name" ; then - echo alias "$(zsh -ic "alias $name")" >> "$conffile" - fi - done - ;; - - *) - echo "Unknown shell, skipping alias/function checking." >&2 - ;; -esac - -cd .. || exit 1 - -printf "Saving as '%s' ... " "$workdir/$outfile" - -tar caf "$workdir/$outfile" "$outdir" && echo "Done" || echo "Failed" - -cd "$workdir" && rm -rf -- "$tempdir" diff --git a/nnn/plugins/nmount b/nnn/plugins/nmount @@ -1,88 +0,0 @@ -#!/usr/bin/env sh - -# Description: Toggle mount status of a device using pmount -# If the device is not mounted, it will be mounted. -# If the device is mounted, it will be unmounted and powered down. -# -# Dependencies: lsblk, pmount (optional), udisks2 -# -# Usage: Runs `lsblk` on 'l', exits on 'Return`. -# -# Notes: -# - The script uses Linux-specific lsblk to list block devices. Alternatives: -# macOS: "diskutil list" -# BSD: "geom disk list" -# - The script uses udisksctl (from udisks2) to power down devices. This is also Linux-specific. -# Users on non-Linux platforms can comment it and use an alternative to power-down disks. -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -prompt="device name [e.g. sdXn] ('l'ist, 'q'uit): " - -lsblk - -printf "\nEnsure you aren't still in the mounted device.\n" -printf "%s" "$prompt" -read -r dev - -while [ -n "$dev" ]; do - if [ "$dev" = "l" ]; then - lsblk - elif [ "$dev" = "q" ]; then - exit - else - # LUKS volumes mounted with udisksctl appear differently than with pmount - if grep -qs "$dev " /proc/mounts || [ -n "$(lsblk -n "/dev/$dev" -o MOUNTPOINT)" ]; then - sync "$(lsblk -n "/dev/$dev" -o MOUNTPOINT | sed "/^$/d")" - if type pumount >/dev/null 2>&1; then - pumount "/dev/$dev" - exit_code="$?" - else - # Unlike pmount, udisksctl does not transparently handle LUKS volumes - # We need to manually get the unlocked device, unmount it, and then lock the volume - if lsblk -n "/dev/$dev" -o FSTYPE | grep "crypto_LUKS" >/dev/null; then - dev_map="$(udisksctl info -b /dev/"$dev" | grep "CleartextDevice" | grep -o "dm_2d[[:digit:]]*" | sed "s/_2d/-/")" - udisksctl unmount -b "/dev/$dev_map" --no-user-interaction >/dev/null - exit_code="$?" - udisksctl lock -b "/dev/$dev" --no-user-interaction >/dev/null - else - udisksctl unmount -b "/dev/$dev" --no-user-interaction >/dev/null - exit_code="$?" - fi - fi - if [ $exit_code -eq 0 ]; then - echo "/dev/$dev unmounted." - if udisksctl power-off -b "/dev/$dev" --no-user-interaction; then - echo "/dev/$dev ejected." - fi - fi - elif [ -b "/dev/$dev" ]; then - if type pmount >/dev/null 2>&1; then - pmount "/dev/$dev" - exit_code="$?" - else - # Unlike pmount, udisksctl does not transparently handle LUKS volumes - # We need to manually get the unlocked device and mount that instead of the volume itself - if [ "$(lsblk "/dev/$dev" -n -o FSTYPE)" = "crypto_LUKS" ]; then - dev_map=$(udisksctl unlock -b "/dev/$dev" --no-user-interaction | grep -o "dm-[[:digit:]]*") - udisksctl mount -b "/dev/$dev_map" --no-user-interaction >/dev/null - exit_code="$?" - else - udisksctl mount -b "/dev/$dev" --no-user-interaction >/dev/null - exit_code="$?" - fi - fi - if [ $exit_code -eq 0 ]; then - sleep 1 - echo "/dev/$dev mounted to $(lsblk -n "/dev/$dev" -o MOUNTPOINT | sed "/^$/d")." - fi - else - echo "/dev/$dev does not exist or is not a block device." - fi - fi - - echo - printf "%s" "$prompt" - read -r dev -done diff --git a/nnn/plugins/oldbigfile b/nnn/plugins/oldbigfile @@ -1,16 +0,0 @@ -#!/usr/bin/env sh - -# Description: List files bigger than input size by ascending access date. -# -# Dependencies: find sort -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -printf "Min file size (MB): " -read -r size - -find . -size +"$size"M -type f -printf '%A+ %s %p\n' | sort - -echo "Press any key to exit" -read -r _ diff --git a/nnn/plugins/openall b/nnn/plugins/openall @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -# Description: Open selected files in nuke one by one or in oneshot -# -# Notes: 1. Opens the hovered file if the selection is empty -# 2. nuke is the default, set OPENER below for custom -# 3. Opener is invoked once for each file in a loop -# 4. Keep pressing "Enter" to open files one by one -# -# Shell: bash -# Author: Arun Prakash Jana - -sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} -OPENER="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke" - -if [ -s "$sel" ]; then - targets=() - while IFS= read -r -d '' entry || [ -n "$entry" ]; do - targets+=( "$entry" ) - done < "$sel" - - elements=${#targets[@]} - - if (( elements == 1 )); then - # If there's only one file selected, open without prompts - "$OPENER" "${targets[0]}" - else - printf "open [A]ll? " - read -r all - - for ((index=0; index <= ${#targets[@]}; index++)); do - "$OPENER" "${targets[index]}" - if [ "$all" != "A" ] && (( index+1 < elements )); then - printf "press Enter to open '%s'\n" "${targets[index+1]}" - read -r -s -n 1 key - if [[ $key != "" ]]; then - break - fi - fi - done - fi - - # Clear selection - if [ -s "$sel" ] && [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" - fi -elif [ -n "$1" ]; then - "$OPENER" "$1" -fi diff --git a/nnn/plugins/organize b/nnn/plugins/organize @@ -1,62 +0,0 @@ -#!/usr/bin/env sh - -# Description: Organize files in directories by category -# -# Note: This plugin clears the selection as it changes the contents of the current dir -# -# Shell: POSIX compliant -# Author: th3lusive - -sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -organize() { - case "$(file -biL "$1")" in - *video*) - [ ! -d "Videos" ] && mkdir "Videos" - mv -- "$1" "Videos/$1" - printf "Moved %s to Videos\n" "$1" ;; - - *audio*) [ ! -d "Audio" ] && mkdir "Audio" - mv -- "$1" "Audio/$1" - printf "Moved %s to Audio\n" "$1" ;; - - *image*) - [ ! -d "Images" ] && mkdir "Images" - mv -- "$1" "Images/$1" - printf "Moved %s to Images\n" "$1" ;; - - *pdf*|*document*|*epub*|*djvu*|*cb*) - [ ! -d "Documents" ] && mkdir "Documents" - mv -- "$1" "Documents/$1" - printf "Moved %s to Documents\n" "$1" ;; - - *text*) - [ ! -d "Plaintext" ] && mkdir "Plaintext" - mv -- "$1" "Plaintext/$1" - printf "Moved %s to Plaintext\n" "$1" ;; - - *tar*|*xz*|*compress*|*7z*|*rar*|*zip*) - [ ! -d "Archives" ] && mkdir "Archives" - mv -- "$1" "Archives/$1" - printf "Moved %s to Archives\n" "$1" ;; - - *binary*) - [ ! -d "Binaries" ] && mkdir "Binaries" - mv -- "$1" "Binaries/$1" - printf "Moved %s to Binaries\n" "$1" ;; - esac -} - -main() { - for file in * - do - [ -f "$file" ] && organize "$file" - done - - # Clear selection - if [ -s "$sel" ] && [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" - fi -} - -main "$@" diff --git a/nnn/plugins/pdfread b/nnn/plugins/pdfread @@ -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 [ -n "$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/nnn/plugins/pskill b/nnn/plugins/pskill @@ -1,35 +0,0 @@ -#!/usr/bin/env sh - -# Description: Fuzzy list and kill a (zombie) process by name -# -# Dependencies: fzf, ps -# -# Note: To kill a zombie process enter "zombie" -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -printf "Enter process name ['defunct' for zombies]: " -read -r psname - -# shellcheck disable=SC2009 -if [ -n "$psname" ]; then - if type sudo >/dev/null 2>&1; then - sucmd=sudo - elif type doas >/dev/null 2>&1; then - sucmd=doas - else - sucmd=: # noop - fi - - if type fzf >/dev/null 2>&1; then - fuzzy=fzf - else - exit 1 - fi - - cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)" - if [ -n "$cmd" ]; then - $sucmd kill -9 "$cmd" - fi -fi diff --git a/nnn/plugins/renamer b/nnn/plugins/renamer @@ -1,45 +0,0 @@ -#!/usr/bin/env sh - -# Description: Batch rename selection or current directory with qmv or vidir -# -# Notes: -# - Try to mimic current batch rename functionality but with correct -# handling of edge cases by qmv or vidir. -# - Qmv opens with hidden files if no selection is used. Selected -# directories are shown. -# - Vidir don't show directories nor hidden files. -# -# Shell: POSIX compliant -# Author: José Neder - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -if type qmv >/dev/null 2>&1; then - batchrenamesel="qmv -fdo -da" - batchrename="qmv -fdo -a" -elif type vidir >/dev/null 2>&1; then - batchrenamesel="vidir" - batchrename="vidir" -else - printf "there is not batchrename program installed." - exit -fi - -if [ -s "$selection" ]; then - printf "rename selection? " - read -r resp -fi - -if [ "$resp" = "y" ]; then - # -o flag is necessary for interactive editors - xargs -o -0 $batchrenamesel < "$selection" - - # Clear selection - if [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" - fi -elif [ ! "$(LC_ALL=C ls -a)" = ". -.." ]; then - # On older systems that don't have ls -A - $batchrename -fi diff --git a/nnn/plugins/ringtone b/nnn/plugins/ringtone @@ -1,36 +0,0 @@ -#!/usr/bin/env sh - -# Description: Create an mp3 ringtone out of an audio file in any format -# Needs user to provide start and end where to cut the file -# Input file audio.ext results in audio_ringtone.mp3 -# -# Tip: To convert a complete media file, set start as 0 and -# the runtime of the file as end. -# -# Dependencies: date, ffmpeg -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if [ -n "$1" ]; then - printf "start (hh:mm:ss): " - read -r start - st=$(date -d "$start" +%s) || exit 1 - - printf "end (hh:mm:ss): " - read -r end - et=$(date -d "$end" +%s) || exit 1 - - if [ "$st" -ge "$et" ]; then - printf "error: start >= end " - read -r _ - exit 1 - fi - - interval=$(( et - st )) - - outfile=$(basename "$1") - outfile="${outfile%.*}"_ringtone.mp3 - - ffmpeg -i "$1" -ss "$start" -t "$interval" -vn -sn -acodec libmp3lame -q:a 2 "$outfile" -fi diff --git a/nnn/plugins/rsynccp b/nnn/plugins/rsynccp @@ -1,26 +0,0 @@ -#!/usr/bin/env sh - -# Description: Simple script to give copy-paste a progress percentage -# by utilizing rsync. -# -# LIMITATION: this won't work when pasting to MTP device. -# -# Dependencies: rsync -# -# Shell: POSIX compliant -# Author: Benawi Adha - -sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -# Choose one of these two schemes by commenting - -# more verbose -xargs -0 -I % rsync -ah --progress % "$PWD" < "$sel" - -# less verbose -# xargs -0 -I % rsync -ah --info=progress2 % "$PWD" < "$sel" - -# Clear selection -if [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" -fi diff --git a/nnn/plugins/splitjoin b/nnn/plugins/splitjoin @@ -1,52 +0,0 @@ -#!/usr/bin/env sh - -# Description: Splits the file passed as argument or joins selection -# -# Note: Adds numeric suffix to split files -# Adds '.out suffix to the first file to be joined and saves as output file for join -# -# Shell: POSIX compliant -# Authors: Arun Prakash Jana, ath3 - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} -resp=s - -if [ -s "$selection" ]; then - printf "press 's' (split current file) or 'j' (join selection): " - read -r resp -fi - -if [ "$resp" = "j" ]; then - if [ -s "$selection" ]; then - arr=$(tr '\0' '\n' < "$selection") - if [ "$(echo "$arr" | wc -l)" -lt 2 ]; then - echo "joining needs at least 2 files" - exit - fi - for entry in $arr - do - if [ -d "$entry" ]; then - echo "can't join directories" - exit - fi - done - - file="$(basename "$(echo "$arr" | sed -n '1p' | sed -e 's/[0-9][0-9]$//')")" - sort -z < "$selection" | xargs -0 -I{} cat {} > "${file}.out" - - # Clear selection - if [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" - fi - fi -elif [ "$resp" = "s" ]; then - if [ -n "$1" ] && [ -f "$1" ]; then - # a single file is passed - printf "split size in MB: " - read -r size - - if [ -n "$size" ]; then - split -d -b "$size"M "$1" "$1" - fi - fi -fi diff --git a/nnn/plugins/suedit b/nnn/plugins/suedit @@ -1,16 +0,0 @@ -#!/usr/bin/env sh - -# Description: Edit file as superuser -# -# Shell: POSIX compliant -# Author: Anna Arad - -EDITOR="${EDITOR:-vim}" - -if type sudo >/dev/null 2>&1; then - sudo -E "$EDITOR" "$1" -elif type sudoedit >/dev/null 2>&1; then - sudoedit -E "$1" -elif type doas >/dev/null 2>&1; then - doas "$EDITOR" "$1" -fi diff --git a/nnn/plugins/togglex b/nnn/plugins/togglex @@ -1,21 +0,0 @@ -#!/usr/bin/env sh - -# Description: Toggles executable mode for selection -# -# Dependencies: chmod -# -# Note: Works _only_ with selection (nnn can toggle the mode for the hovered file) -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -if [ -s "$selection" ]; then - xargs -0 -I {} sh -c 'if [ -x "{}" ] ; then chmod -x "{}" ; else chmod +x "{}" ; fi' < "$selection" - - # Clear selection - if [ -p "$NNN_PIPE" ]; then - printf "-" > "$NNN_PIPE" - fi -fi diff --git a/nnn/plugins/umounttree b/nnn/plugins/umounttree @@ -1,52 +0,0 @@ -#!/usr/bin/env sh - -# Description: Autodetects a nnn remote mountpoint (mounted with `c`) -# from any of its subfolders and allows unmounting it -# from the subdir without navigating to the mountppoint -# or entering the remote name. Also works when hovering -# the mountpoint directly like vanilla `u`. -# -# Dependencies: fusermount -# -# Shell: POSIX compliant -# Authors: Kabouik & 0xACE -# -# TODO: -# - Avoid lazy unmount by forcing nnn context to leave the subfolder before fusermount. -# Tried `printf "%s" "0c$m" > "$NNN_PIPE"` but it breaks the nnn interface, see #854. - -err=0 -m=$HOME/.config/nnn/mounts -if [ "$PWD" = "$m" ]; then - # Allow running the script on hovered directory if user is in ~/.config/nnn/mounts - d="$1" -else - d=$(dirname "$(readlink -f "$1")" | grep -oP "^$m\K.*" | cut -d"/" -f2) -fi - -# Test if user is within $m or a subdir, abort if not -if [ "$d" = "" ]; then - clear && printf "You are not in a remote folder mounted with nnn. Press return to continue. " && read -r _ -else - # Test if $m/$d is a mountpoint and try unmounting if it is - mountpoint -q -- "$m/$d" - if [ "$?" -eq "1" ]; then - clear && printf "Parent '%s' is not a mountpoint. Press return to continue. " "$d" && read -r _ - else - cd "$m" && fusermount -uq "$m/$d" || err=1 - if [ "$err" -eq "0" ]; then - rmdir "$m/$d" && clear && printf "Parent '%s' unmounted." "$d" - else - clear && printf "Failed to unmount. Try lazy unmount? [Yy/Nn] " && read -r - fi - fi -fi - -# If unmount fails, offer lazy unmount -if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then - err=0 - cd "$m" && fusermount -uqz "$m/$d" || err=1 - if [ "$err" -eq "0" ]; then - rmdir "$m/$d" && clear && printf "Parent '%s' unmounted with lazy unmount. " "$d" - fi -fi diff --git a/nnn/plugins/upload b/nnn/plugins/upload @@ -1,38 +0,0 @@ -#!/usr/bin/env sh - -# Description: Selections are archived into a tar file (uncompressed) and uploaded to file.io -# For single files: -# Paste contents of a text file to http://ix.io -# Upload a binary file to file.io -# -# Dependencies: curl, jq, tar, file with `--mime-type` support -# -# Note: Binary file set to expire after a week -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} -if [ -s "$selection" ]; then - xargs -0 tar -c < "$selection" | \ - curl -s -F "file=@/dev/stdin;filename=selection.tar" 'https://file.io/?expires=1w' | \ - jq '.link' | tr -d '"' - - # Clear selection - printf "-" > "$NNN_PIPE" -else - if [ -n "$1" ] && [ -s "$1" ]; then - if file --mime-type "$1" | grep -q -F "text/"; then - curl -F "file=@$1" https://0x0.st - else - # Upload the file, show the download link and wait till user presses any key - curl -s -F "file=@$1" https://file.io/?expires=1w | jq '.link' | tr -d '"' - # To write download link to "$1".loc and exit - # curl -s -F "file=@$1" https://file.io/?expires=1w -o `basename "$1"`.loc - fi - else - printf "empty file!" - fi -fi - -read -r _ diff --git a/nnn/plugins/wallpaper b/nnn/plugins/wallpaper @@ -1,45 +0,0 @@ -#!/usr/bin/env sh - -# Description: Set the selected image as wallpaper. -# Uses nitrogen or pywal on X11, swww on wayland. -# -# Usage: Hover on an image and run the script to set it as wallpaper. -# -# Shell: POSIX compliant -# Author: juacq97 - -resp= - -if [ -n "$1" ]; then - if [ "$(file --mime-type "$1" | awk '{print $NF}' | awk -F '/' '{print $1}')" = "image" ]; then - if [ "$XDG_SESSION_TYPE" = "x11" ]; then - if type nitrogen >/dev/null 2>&1; then - printf "Set to full desktop or a specific monitors? [0, 1, etc. Defaults to full.]" - read -r resp - if [ "$resp" != "" ]; then - nitrogen --set-zoom-fill --save "$1" --head="$resp" - else - nitrogen --set-zoom-fill --save "$1" - fi - elif type wal >/dev/null 2>&1; then - wal -i "$1" - else - printf "nitrogen or pywal missing" - read -r _ - fi - else - if type swww >/dev/null 2>&1; then - swww img "$1" - else - printf "swww missing" - read -r _ - fi - fi - - # If you want a system notification, uncomment the next 3 lines. - # notify-send -a "nnn" "Wallpaper changed!" - # else - # notify-send -a "nnn" "No image selected" - - fi -fi diff --git a/nnn/plugins/x2sel b/nnn/plugins/x2sel @@ -1,62 +0,0 @@ -#!/usr/bin/env sh - -# Description: Copy system clipboard newline-separated file list to selection -# -# Dependencies: -# - tr -# - xclip/xsel (Linux) -# - pbpaste (macOS) -# - termux-clipboard-get (Termux) -# - powershell (WSL) -# - cygwim's /dev/clipboard (Cygwin) -# - wl-paste (Wayland) -# - clipboard (Haiku) -# -# Note: -# - Limitation: breaks if a filename has newline in it -# -# Shell: POSIX compliant -# Author: Léo Villeveygoux, after Arun Prakash Jana's .cbcp - -IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n - -selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} - -getclip () { - if [ "$XDG_SESSION_TYPE" = "wayland" ]; then - # Wayland - wl-paste - elif type xsel >/dev/null 2>&1; then - # Linux - xsel -bo - elif type xclip >/dev/null 2>&1; then - # Linux - xclip -sel clip -o - elif type pbpaste >/dev/null 2>&1; then - # macOS - pbpaste - elif type termux-clipboard-get >/dev/null 2>&1; then - # Termux - termux-clipboard-get - elif type powershell.exe >/dev/null 2>&1; then - # WSL - powershell.exe Get-Clipboard - elif [ -r /dev/clipboard ] ; then - # Cygwin - cat /dev/clipboard - elif type clipboard >/dev/null 2>&1; then - # Haiku - clipboard --print - fi -} - -CLIPBOARD=$(getclip) - -# Check if clipboard actually contains a file list -for file in $CLIPBOARD ; do - if [ ! -e "$file" ] ; then - exit 1; - fi -done - -printf "%s" "$CLIPBOARD" | tr '\n' '\0' > "$selection"