From 5cf34717161bd866a634d8a9ad209afb4004857b Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Thu, 18 Apr 2019 20:27:35 +0530 Subject: Plugins! --- README.md | 29 +-- nnn.1 | 4 +- plugins/README.md | 29 +++ plugins/edit | 8 + plugins/fzy | 8 + plugins/hexview | 11 + plugins/imgresize | 32 +++ plugins/imgur | 557 ++++++++++++++++++++++++++++++++++++++++ plugins/kdeconnect | 15 ++ plugins/ndiff | 8 + plugins/nwal | 16 ++ plugins/paste | 13 + plugins/picker | 26 ++ plugins/pywal | 16 ++ plugins/sxiv | 8 + plugins/transfer | 16 ++ plugins/upgrade | 24 ++ scripts/clipboard-copier/copier | 18 ++ src/nnn.c | 50 ++-- src/nnn.h | 8 +- user-scripts/README.md | 30 --- user-scripts/copier | 18 -- user-scripts/edit | 8 - user-scripts/fzy | 8 - user-scripts/hexview | 11 - user-scripts/imgresize | 32 --- user-scripts/imgur | 557 ---------------------------------------- user-scripts/kdeconnect | 15 -- user-scripts/ndiff | 8 - user-scripts/nwal | 16 -- user-scripts/paste | 13 - user-scripts/picker | 26 -- user-scripts/pywal | 16 -- user-scripts/sxiv | 8 - user-scripts/transfer | 16 -- user-scripts/upgrade | 24 -- 36 files changed, 850 insertions(+), 852 deletions(-) create mode 100644 plugins/README.md create mode 100755 plugins/edit create mode 100755 plugins/fzy create mode 100755 plugins/hexview create mode 100755 plugins/imgresize create mode 100755 plugins/imgur create mode 100755 plugins/kdeconnect create mode 100755 plugins/ndiff create mode 100755 plugins/nwal create mode 100755 plugins/paste create mode 100755 plugins/picker create mode 100755 plugins/pywal create mode 100755 plugins/sxiv create mode 100755 plugins/transfer create mode 100755 plugins/upgrade create mode 100755 scripts/clipboard-copier/copier delete mode 100644 user-scripts/README.md delete mode 100755 user-scripts/copier delete mode 100755 user-scripts/edit delete mode 100755 user-scripts/fzy delete mode 100755 user-scripts/hexview delete mode 100755 user-scripts/imgresize delete mode 100755 user-scripts/imgur delete mode 100755 user-scripts/kdeconnect delete mode 100755 user-scripts/ndiff delete mode 100755 user-scripts/nwal delete mode 100755 user-scripts/paste delete mode 100755 user-scripts/picker delete mode 100755 user-scripts/pywal delete mode 100755 user-scripts/sxiv delete mode 100755 user-scripts/transfer delete mode 100755 user-scripts/upgrade diff --git a/README.md b/README.md index ab24f6a..9b1b4bd 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ `nnn` works seamlessly with your DE and favourite GUI utilities. It runs on Linux, macOS, Raspberry Pi, BSD, Cygwin, Linux subsystem for Windows and Termux on Android. -Have as many scripts as you want to extend the power of `nnn`! Pick from the [scripts repository](https://github.com/jarun/nnn/tree/master/user-scripts) or add your own. +Have as many scripts as you want to extend the power of `nnn`! Pick from the available [plugins](https://github.com/jarun/nnn/tree/master/plugins) or add your own. [Quickstart](#quickstart) and see how `nnn` simplifies long desktop sessions. When you are ready for more, start [hacking `nnn`](https://github.com/jarun/nnn/wiki/hacking-nnn). @@ -60,7 +60,7 @@ Have as many scripts as you want to extend the power of `nnn`! Pick from the [sc - [File indicators](#file-indicators) - [Configuration](#configuration) - [Help](#help) -- [User scripts](#user-scripts) +- [Plugins](#plugins) - [Troubleshooting](#troubleshooting) - [Tmux configuration](#tmux-configuration) - [BSD terminal issue](#bsd-terminal-issue) @@ -102,13 +102,12 @@ Have as many scripts as you want to extend the power of `nnn`! Pick from the [sc - Copy, move, delete, archive, link selection - FreeDesktop compliant trash (needs trash-cli) - Show copy, move progress on Linux (needs avdcpmv) - - Script to view directory and file diff for selection + - Plugin repository - Transfer files using lftp - Batch rename (needs vidir) - Per-context directory color (default: blue) - Spawn a shell in the current directory - Launch applications, run a command - - Repository of custom scripts - Run current file as executable - Change directory at exit (*easy* shell integration) - Edit file in EDITOR or open in PAGER @@ -143,7 +142,7 @@ Have as many scripts as you want to extend the power of `nnn`! Pick from the [sc | advcpmv (Linux) ([integration](https://github.com/jarun/nnn/wiki/hacking-nnn#show-cp-mv-progress)) | copy, move progress | | $EDITOR (overridden by $VISUAL, if defined) | edit files (fallback vi) | | $PAGER (less, most) | page through files (fallback less) | -| $SHELL | spawn a shell, run script (fallback sh) | +| $SHELL | spawn a shell, run some commands (fallback sh) | #### From a package manager @@ -199,7 +198,7 @@ Option completion scripts for Bash, Fish and Zsh can be found in respective subd 5. To use `nnn` as a GUI app launcher with fuzzy selection menu, drop [`nlaunch`](https://github.com/jarun/nnn/blob/master/scripts/nlaunch/nlaunch) somewhere in your `$PATH`. Note that the launcher requires fzy. 6. Don't memorize keys. Arrows, / and q suffice. Press ? for help on keyboard shortcuts anytime. -- For additional functionality [setup custom scripts](#user-scripts). +- For additional functionality [setup plugins](#plugins). - Visit the wiki page [hacking `nnn`](https://github.com/jarun/nnn/wiki/hacking-nnn) for many more specific use cases. - To set `nnn` as the default file manager, follow these [instructions](https://github.com/jarun/nnn/wiki/nnn-as-default-file-manager). @@ -264,7 +263,7 @@ Press ? in `nnn` to see the list anytime. ^W Random s Size t Time modified MISC ! ^] Spawn SHELL C Execute entry - R ^V Run script L Lock terminal + R ^V Pick plugin L Lock terminal ^P Prompt ^N Note = Launcher ``` @@ -379,8 +378,8 @@ The following indicators are used in the detail view: | `NNN_OPENER_DETACH=1` | do not block when invoking file opener | | `NNN_CONTEXT_COLORS='1234'` | specify per context color [default: '4444' (all blue)] | | `NNN_IDLE_TIMEOUT=300` | idle seconds before locking terminal [default: disabled] | -| `NNN_COPIER='copier.sh'` | system clipboard copier script [default: none] | -| `NNN_SCRIPT_DIR=/home/user/scripts` | absolute path to script dir | +| `NNN_COPIER='/path/to/copier.sh'` | system clipboard copier script [default: none] | +| `NNN_PLUGIN_DIR=/home/user/nnn-plugins` | absolute path to plugins dir | | `NNN_NOTE=/home/user/Dropbox/Public/notes` | path to note file [default: none] | | `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit | | `NNN_USE_EDITOR=1` | Open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) | @@ -396,17 +395,17 @@ The following indicators are used in the detail view: $ man nnn To lookup keyboard shortcuts at runtime, press ?. -#### USER SCRIPTS +#### PLUGINS -`nnn` can invoke custom scripts in the current directory (`$PWD` for the script) with the currently selected file name as the argument. +`nnn` can invoke plugins in the current directory (`$PWD` for the plugin) with the currently selected file name as the argument. -Copy the scripts of your interest from the [user-scripts](https://github.com/jarun/nnn/tree/master/user-scripts) directory and let `nnn` know the location: +Copy the plugins of your interest from the [plugins](https://github.com/jarun/nnn/tree/master/plugins) directory and let `nnn` know the location: - export NNN_SCRIPT_DIR=/absolute/path/to/scripts_dir + export NNN_PLUGIN_DIR=/absolute/path/to/plugins_dir -Use the run script shortcut to jump to the script directory and pick a script. Repeating the same shortcut cancels the operation and puts you back in the original directory. +Use the pick plugin shortcut to visit the plugin directory and pick a plugin. Repeating the same shortcut cancels the operation and puts you back in the original directory. -If you have an interesting script feel free to raise a PR. +If you have an interesting plugin feel free to raise a PR. #### TROUBLESHOOTING diff --git a/nnn.1 b/nnn.1 index 11d44e4..8621776 100644 --- a/nnn.1 +++ b/nnn.1 @@ -174,9 +174,9 @@ when dealing with the !, e and p commands respectively. A single combination to The path is shown in the help and configuration screen. .Ed .Pp -\fBNNN_SCRIPT_DIR:\fR \fIabsolute\fR path to script directory. Selected script is invoked with currently selected file name as argument 1. +\fBNNN_PLUGIN_DIR:\fR \fIabsolute\fR path to plugin directory. Selected plugin is invoked with currently selected file name as argument 1. .Bd -literal - export NNN_SCRIPT_DIR=/absolute/path/to/scripts_dir + export NNN_PLUGIN_DIR=/absolute/path/to/plugins_dir .Ed .Pp \fBNNN_NOTE:\fR \fIabsolute\fR path to a note file. diff --git a/plugins/README.md b/plugins/README.md new file mode 100644 index 0000000..be8aa4c --- /dev/null +++ b/plugins/README.md @@ -0,0 +1,29 @@ +| Plugin (a-z) | Lang | Deps | Description | +| --- | --- | --- | --- | +| edit | sh | fzy | Fuzzy find a file in directory subtree and edit in vim | +| fzy | sh | fzy | Fuzzy find a file in directory subtree and open using xdg-open | +| hexview | sh | xxd, $PAGER | view a file in hex | +| imgresize | sh | [imgp](https://github.com/jarun/imgp) | Resize images in directory to screen resolution | +| imgur | bash | [imgur](https://github.com/jomo/imgur-screenshot) | Upload an image to imgur | +| kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device | +| ndiff | sh | vimdiff | File and directory diff for selection | +| nwal | sh | nitrogen | Set the selected image as wallpaper using nitrogen | +| paste | sh | [pastebinit](https://launchpad.net/pastebinit) | Paste contents of current (text) file to paste.ubuntu.com | +| picker | sh | nnn | Pick files and pipe the newline-separated list to another utility | +| pywal | sh | pywal | Set selected image as wallpaper, change terminal color scheme | +| sxiv | sh | sxiv | Open images in a dir in sxiv, set wallpaper, copy path ([tips](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))| +| transfer | sh | curl | Upload current file to transfer.sh | +| upgrade | sh | wget | Upgrade to latest nnn version manually on Debian 9 Stretch | + +### File access from plugins + +The design is flexible so a plugin can access: +- all files in the directory (`nnn` switches to the dir where the plugin is to be run so the dir is `$PWD` for the plugin) +- the currently highlighted file (the file name is passed as the argument to a plugin) +- the current selection (by reading the file .nnncp, see the plugin `ndiff`) + +### Contributing plugins + +Plugins are scripts and all scripting languages should work. However, POSIX-compliant shell scripts runnable in `sh` are preferred. If that's too rudimentary for your use case, use Python, Perl or Ruby. Please keep non-portable commands (like `notify-send`) commented so users from any other OS/DE aren't surprised. + +The plugins should be executable. Please add an entry in the table above. diff --git a/plugins/edit b/plugins/edit new file mode 100755 index 0000000..6155250 --- /dev/null +++ b/plugins/edit @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# Description: Fuzzy find a file in directory subtree with fzy and edit in vim +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +vim "$(find -type f | fzy)" diff --git a/plugins/fzy b/plugins/fzy new file mode 100755 index 0000000..0ddd229 --- /dev/null +++ b/plugins/fzy @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# Description: Fuzzy find a file in directory subtree with fzy and open using xdg-open +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +xdg-open "$(find -type f | fzy)" >/dev/null 2>&1 diff --git a/plugins/hexview b/plugins/hexview new file mode 100755 index 0000000..5125fa3 --- /dev/null +++ b/plugins/hexview @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# Description: View a file in hex +# Requires: xxd and $PAGER +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if ! [ -z "$1" ]; then + xxd "$1" | "$PAGER" +fi diff --git a/plugins/imgresize b/plugins/imgresize new file mode 100755 index 0000000..6d016f1 --- /dev/null +++ b/plugins/imgresize @@ -0,0 +1,32 @@ +#!/usr/bin/env sh + +# Description: Resize images in a directory to screen resolution with imgp +# imgp homepage: https://github.com/jarun/imgp +# +# Notes: +# 1. Set res if you don't want to be prompted for desktop resolution every 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= + +# set minimum image size (in bytes) to resize (default: 1MB) +minsize=1048576 + +if [ -z "$res" ]; then + echo -n "desktop resolution (hxv): " + read res +fi + +if ! [ -z "$res" ]; then + if ! [ -z "$minsize" ]; then + imgp -ackx "$res" -s "$minsize" + fi +fi diff --git a/plugins/imgur b/plugins/imgur new file mode 100755 index 0000000..0a660fc --- /dev/null +++ b/plugins/imgur @@ -0,0 +1,557 @@ +#!/usr/bin/env bash +# https://github.com/jomo/imgur-screenshot +# https://imgur.com/tools +# +# 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" + +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 + source "${settings_path}" +fi + +# dependency check +if [ "${1}" = "--check" ]; then + (which grep &>/dev/null && echo "OK: found grep") || echo "ERROR: grep not found" + if is_mac; then + if which growlnotify &>/dev/null; then + echo "OK: found growlnotify" + elif which terminal-notifier &>/dev/null; then + echo "OK: found terminal-notifier" + else + echo "ERROR: growlnotify nor terminal-notifier found" + fi + (which screencapture &>/dev/null && echo "OK: found screencapture") || echo "ERROR: screencapture not found" + (which pbcopy &>/dev/null && echo "OK: found pbcopy") || echo "ERROR: pbcopy not found" + else + (which notify-send &>/dev/null && echo "OK: found notify-send") || echo "ERROR: notify-send (from libnotify-bin) not found" + (which scrot &>/dev/null && echo "OK: found scrot") || echo "ERROR: scrot not found" + (which xclip &>/dev/null && echo "OK: found xclip") || echo "ERROR: xclip not found" + fi + (which curl &>/dev/null && echo "OK: found curl") || echo "ERROR: curl not found" + exit 0 +fi + + +# notify <'ok'|'error'> <text> +function notify() { + if is_mac; then + if which 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}} + + shot_err="$(${cmd} &>/dev/null)" #takes a screenshot with selection + if [ "${?}" != "0" ]; then + 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" | egrep -m 1 --color 'tag_name":\s*".*"' | cut -d '"' -f 4)" + if [ "${?}" -eq "0" ]; then + if [ ! "${current_version}" = "${remote_version}" ] && [ ! -z "${current_version}" ] && [ ! -z "${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 + source "${credentials_file}" + fi + current_time="$(date +%s)" + preemptive_refresh_time="$((10*60))" + expired="$((current_time > (token_expire_time - preemptive_refresh_time)))" + if [ ! -z "${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 + 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}")" + if [ ! "${?}" -eq "0" ]; 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="$(egrep -o 'access_token":".*"' <<<"${1}" | cut -d '"' -f 3)" + refresh_token="$(egrep -o 'refresh_token":".*"' <<<"${1}" | cut -d '"' -f 3)" + expires_in="$(egrep -o '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 egrep -q '"success":\s*true' <<<"${response}"; then + username="$(egrep -o '"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 egrep -q '"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 egrep -q '"success":\s*true' <<<"${response}"; then + img_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" + img_ext="$(egrep -o '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https! + del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" + + if [ ! -z "${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="$(egrep -o '"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 egrep -q '"success":\s*true' <<<"${response}"; then + img_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" + img_ext="$(egrep -o '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https! + del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" + + if [ ! -z "${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="$(egrep -o '"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) + 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 egrep -q '"success":\s*true' <<<"${response}"; then # Album creation successful + echo "Album '${album_title}' successfully created" + album_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" + del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" + handle_album_creation_success "http://imgur.com/a/${album_id}" "${del_id}" "${album_title}" + + if [ "${login}" = "false" ]; then + album_id="${del_id}" + fi + else # Album creation failed + err_msg="$(egrep -o '"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 + img_file="$(cd "$( dirname "${img_file}")" && echo "$(pwd)/$(basename "${img_file}")")" + + # check if file exists + if [ ! -f "${img_file}" ]; then + echo "file '${img_file}' doesn't exist !" + 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 diff --git a/plugins/kdeconnect b/plugins/kdeconnect new file mode 100755 index 0000000..0fbafbb --- /dev/null +++ b/plugins/kdeconnect @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +# Description: Send the selected files to your Android device using kdeconnect-cli. You must have installed and configured kdeconnect both on the Android device and on the PC. +# +# Shell: POSIX compliant +# Author: juacq97 + +id=$(kdeconnect-cli -a --id-only | awk '{print $1}') +if [ "$(find ~/.nnncp)" ]; then + kdeconnect-cli -d "$id" --share "$(cat ~/.nnncp)" +# If you want a system notification, uncomment the next 3 lines. +# notify-send -a "Kdeconnect" "Sending $(cat ~/.nnncp)" +#else +# notify-send -a "Kdeconnect" "No file selected" +fi diff --git a/plugins/ndiff b/plugins/ndiff new file mode 100755 index 0000000..10af0b3 --- /dev/null +++ b/plugins/ndiff @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# Description: File and directory diff using vimdiff +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +vimdiff $(cat ~/.nnncp | tr '\0' '\n') diff --git a/plugins/nwal b/plugins/nwal new file mode 100755 index 0000000..2f18b08 --- /dev/null +++ b/plugins/nwal @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# Description: Set the selected image as wallpaper using nitrogen. Just put the cursor on a image and run the script. +# +# Shell: POSIX Compliant +# Author: juacq97 + +if ! [ -z "$1" ]; then + if [ $(mimetype --output-format %m $1 | awk -F '/' '{print $1}') == "image" ]; then + nitrogen --set-zoom-fill --save $1 +# 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/plugins/paste b/plugins/paste new file mode 100755 index 0000000..de130e4 --- /dev/null +++ b/plugins/paste @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# Description: Paste contents of a text a file to paste.ubuntu.com using pastebinit +# +# pastebinit: https://launchpad.net/pastebinit +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if ! [ -z "$1" ]; then + pastebinit "$1" + read input +fi diff --git a/plugins/picker b/plugins/picker new file mode 100755 index 0000000..a500435 --- /dev/null +++ b/plugins/picker @@ -0,0 +1,26 @@ +#!/usr/bin/env sh + +# Description: Pick files and pipe the newline-separated list to another utility +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana +# +# Usage: +# Copy this file in your $PATH, make it executable and preferably name it to picker. +# Run commands like: +# ls -l `picker` +# cd `picker` +# vimdiff `picker` +# or, in fish shell: +# ls -l (picker) +# cd (picker) +# vimdiff (picker) +# +# NOTE: This use case is limited to picking files, other functionality may not work as expected. + +nnn -p /tmp/picked + +if [ -f /tmp/picked ]; then + cat /tmp/picked | tr '\0' '\n' + rm /tmp/picked +fi diff --git a/plugins/pywal b/plugins/pywal new file mode 100755 index 0000000..161bbb5 --- /dev/null +++ b/plugins/pywal @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# Description: Set the selected image as wallpaper using pywal and change the terminal color schemes. Just put the cursor on a image and run the script. +# +# Shell: POSIX Compliant +# Author: juacq97 + +if ! [ -z "$1" ]; then + if [ $(mimetype --output-format %m $1 | awk -F '/' '{print $1}') == "image" ]; then + wal -i $1 +# 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/plugins/sxiv b/plugins/sxiv new file mode 100755 index 0000000..ef21cf7 --- /dev/null +++ b/plugins/sxiv @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# Description: Open images in current directory in sxiv +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +sxiv -q * >/dev/null 2>&1 & diff --git a/plugins/transfer b/plugins/transfer new file mode 100755 index 0000000..7201b0b --- /dev/null +++ b/plugins/transfer @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# Description: Upload a file to transfer.sh +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +if ! [ -z "$1" ]; then + # Upload the file, show the download link and wait till user presses any key + curl -s --upload-file "$1" https://transfer.sh/`basename "$1"` + echo + read input + + # To write download link to "$1".loc and exit + # curl -s --upload-file "$1" https://transfer.sh/`basename "$1"` -o `basename "$1"`.loc +fi diff --git a/plugins/upgrade b/plugins/upgrade new file mode 100755 index 0000000..83b9949 --- /dev/null +++ b/plugins/upgrade @@ -0,0 +1,24 @@ +#!/usr/bin/env sh + +# Description: Check and update to latest version of nnn manually on Debian 9 Stretch +# +# Shell: POSIX-compliant +# Author: Arun Prakash Jana +# NOTE: This script installs a package, should be issued with admin privilege + +cur=`nnn -v` +new=`curl -s "https://github.com/jarun/nnn/releases/latest" | grep -Eo "[0-9]+\.[0-9]+"` + +if [ $cur_ver == $new_ver ]; then + echo 'Already at latest version' + exit 0 +fi + +# get the package +wget "https://github.com/jarun/nnn/releases/download/v$new/nnn_$new-1_debian9.amd64.deb" + +# install it +sudo dpkg -i nnn_$new-1_debian9.amd64.deb + +# remove the file +rm -rf nnn_$new-1_debian9.amd64.deb diff --git a/scripts/clipboard-copier/copier b/scripts/clipboard-copier/copier new file mode 100755 index 0000000..2aec820 --- /dev/null +++ b/scripts/clipboard-copier/copier @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +# Description: Copy selection to clipboard +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +# Linux +cat ~/.nnncp | xargs -0 | xsel -bi + +# macOS +# cat ~/.nnncp | xargs -0 | pbcopy + +# Termux +# cat /data/data/com.termux/files/home/.nnncp | xargs -0 | termux-clipboard-set + +# Cygwin +# cat ~/.nnncp | xargs -0 | clip diff --git a/src/nnn.c b/src/nnn.c index 72db2c5..05d1a26 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -217,8 +217,8 @@ typedef struct { uint autoselect : 1; /* Auto-select dir in nav-as-you-type mode */ uint metaviewer : 1; /* Index of metadata viewer in utils[] */ uint useeditor : 1; /* Use VISUAL to open text files */ - uint runscript : 1; /* Choose script to run mode */ - uint runctx : 2; /* The context in which script is to be run */ + uint runplugin : 1; /* Choose plugin mode */ + uint runctx : 2; /* The context in which plugin is to be run */ uint restrict0b : 1; /* Restrict 0-byte file opening */ uint filter_re : 1; /* Use regex filters */ uint wild : 1; /* Do not sort entries on dir load */ @@ -257,7 +257,7 @@ static settings cfg = { 1, /* autoselect */ 0, /* metaviewer */ 0, /* useeditor */ - 0, /* runscript */ + 0, /* runplugin */ 0, /* runctx */ 0, /* restrict0b */ 1, /* filter_re */ @@ -385,7 +385,7 @@ static const char * const messages[] = { #define NNN_CONTEXT_COLORS 2 #define NNN_IDLE_TIMEOUT 3 #define NNN_COPIER 4 -#define NNN_SCRIPT_DIR 5 +#define NNN_PLUGIN_DIR 5 #define NNN_NOTE 6 #define NNN_TMPFILE 7 #define NNNLVL 8 /* strings end here */ @@ -405,7 +405,7 @@ static const char * const env_cfg[] = { "NNN_CONTEXT_COLORS", "NNN_IDLE_TIMEOUT", "NNN_COPIER", - "NNN_SCRIPT_DIR", + "NNN_PLUGIN_DIR", "NNN_NOTE", "NNN_TMPFILE", "NNNLVL", @@ -2158,7 +2158,7 @@ static void savecurctx(settings *curcfg, char *path, char *curname, int r /* nex xstrlcpy(g_ctx[r].c_name, curname, NAME_MAX + 1); g_ctx[r].c_fltr[0] = g_ctx[r].c_fltr[1] = '\0'; g_ctx[r].c_cfg = cfg; - g_ctx[r].c_cfg.runscript = 0; + g_ctx[r].c_cfg.runplugin = 0; } cfg.curctx = r; @@ -2386,7 +2386,7 @@ static bool show_help(const char *path) "b^W Random s Size t Time modified\n" "1MISC\n" "9! ^] Spawn SHELL C Execute entry\n" - "9R ^V Run script L Lock terminal\n" + "9R ^V Pick plugin L Lock terminal\n" "b^P Prompt ^N Note = Launcher\n"}; if (g_tmpfpath[0]) @@ -2845,7 +2845,7 @@ static void browse(char *ipath) struct stat sb; char *path, *lastdir, *lastname; char *dir, *tmp; - char *scriptpath = getenv(env_cfg[NNN_SCRIPT_DIR]); + char *pluginpath = getenv(env_cfg[NNN_PLUGIN_DIR]); atexit(dentfree); @@ -3002,11 +3002,11 @@ nochange: if (cfg.nonavopen && sel == SEL_NAV_IN) continue; - /* Handle script selection mode */ - if (cfg.runscript) { - if (!scriptpath || (cfg.runctx != cfg.curctx) - /* Must be in script directory to select script */ - || (strcmp(path, scriptpath) != 0)) + /* Handle plugin selection mode */ + if (cfg.runplugin) { + if (!pluginpath || (cfg.runctx != cfg.curctx) + /* Must be in plugin directory to select plugin */ + || (strcmp(path, pluginpath) != 0)) continue; mkpath(path, dents[cur].name, newpath); @@ -3019,7 +3019,7 @@ nochange: } else spawn(newpath, NULL, NULL, path, F_NORMAL); rundir[0] = '\0'; - cfg.runscript = 0; + cfg.runplugin = 0; setdirwatch(); goto begin; } @@ -3739,7 +3739,7 @@ nochange: } case SEL_EXEC: // fallthrough case SEL_SHELL: // fallthrough - case SEL_SCRIPT: // fallthrough + case SEL_PLUGIN: // fallthrough case SEL_LAUNCH: // fallthrough case SEL_RUNCMD: switch (sel) { @@ -3766,13 +3766,13 @@ nochange: case SEL_SHELL: spawn(shell, NULL, NULL, path, F_CLI); break; - case SEL_SCRIPT: - if (!scriptpath) { - printwait("set NNN_SCRIPT_DIR", &presel); + case SEL_PLUGIN: + if (!pluginpath) { + printwait("set NNN_PLUGIN_DIR", &presel); goto nochange; } - if (stat(scriptpath, &sb) == -1) { + if (stat(pluginpath, &sb) == -1) { printwarn(); goto nochange; } @@ -3781,13 +3781,13 @@ nochange: if (!S_ISDIR(sb.st_mode)) break; - cfg.runscript ^= 1; - if (!cfg.runscript && rundir[0]) { + cfg.runplugin ^= 1; + if (!cfg.runplugin && rundir[0]) { /* - * If toggled, and still in the script dir, + * If toggled, and still in the plugin dir, * switch to original directory */ - if (strcmp(path, scriptpath) == 0) { + if (strcmp(path, pluginpath) == 0) { xstrlcpy(path, rundir, PATH_MAX); xstrlcpy(lastname, runfile, NAME_MAX); rundir[0] = runfile[0] = '\0'; @@ -3798,11 +3798,11 @@ nochange: } /* Check if directory is accessible */ - if (!xdiraccess(scriptpath)) + if (!xdiraccess(pluginpath)) goto nochange; xstrlcpy(rundir, path, PATH_MAX); - xstrlcpy(path, scriptpath, PATH_MAX); + xstrlcpy(path, pluginpath, PATH_MAX); if (ndents) xstrlcpy(runfile, dents[cur].name, NAME_MAX); cfg.runctx = cfg.curctx; diff --git a/src/nnn.h b/src/nnn.h index 839ec0c..dd21ef5 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -88,7 +88,7 @@ enum action { SEL_HELP, SEL_EXEC, SEL_SHELL, - SEL_SCRIPT, + SEL_PLUGIN, SEL_LAUNCH, SEL_RUNCMD, SEL_RUNEDIT, @@ -225,9 +225,9 @@ static struct key bindings[] = { /* Run command */ { '!', SEL_SHELL }, { CONTROL(']'), SEL_SHELL }, - /* Run a custom script */ - { 'R', SEL_SCRIPT }, - { CONTROL('V'), SEL_SCRIPT }, + /* Run a plugin */ + { 'R', SEL_PLUGIN }, + { CONTROL('V'), SEL_PLUGIN }, /* Launcher */ { '=', SEL_LAUNCH }, /* Run a command */ diff --git a/user-scripts/README.md b/user-scripts/README.md deleted file mode 100644 index 40aae40..0000000 --- a/user-scripts/README.md +++ /dev/null @@ -1,30 +0,0 @@ -| Script (a-z) | Lang | Deps | Description | -| --- | --- | --- | --- | -| copier | sh | OS-specific | Copy selection to clipboard | -| edit | sh | fzy | Fuzzy find a file in directory subtree and edit in vim | -| fzy | sh | fzy | Fuzzy find a file in directory subtree and open using xdg-open | -| hexview | sh | xxd, $PAGER | view a file in hex | -| imgresize | sh | [imgp](https://github.com/jarun/imgp) | Resize images in directory to screen resolution | -| imgur | bash | [imgur](https://github.com/jomo/imgur-screenshot) | Upload an image to imgur | -| kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device | -| ndiff | sh | vimdiff | File and directory diff for selection | -| nwal | sh | nitrogen | Set the selected image as wallpaper using nitrogen | -| paste | sh | [pastebinit](https://launchpad.net/pastebinit) | Paste contents of current (text) file to paste.ubuntu.com | -| picker | sh | nnn | Pick files and pipe the newline-separated list to another utility | -| pywal | sh | pywal | Set selected image as wallpaper, change terminal color scheme | -| sxiv | sh | sxiv | Open images in a dir in sxiv, set wallpaper, copy path ([tips](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))| -| transfer | sh | curl | Upload current file to transfer.sh | -| upgrade | sh | wget | Upgrade to latest nnn version manually on Debian 9 Stretch | - -### File access from scripts - -The design is flexible so a script can access: -- all files in the directory (`nnn` switches to the dir where the script is to be run so the dir is `$PWD` for the script) -- the currently highlighted file (the file name is passed as the first argument to a script) -- the current selection (by reading the file .nnncp, see the script `copier`) - -### Contributing scripts - -All scripting languages should work. However, POSIX-compliant shell scripts runnable in `sh` are preferred. If that's too rudimentary for your use case, use Python, Perl or Ruby. Please keep non-portable commands (like `notify-send`) commented so users from any other OS/DE aren't surprised. - -The scripts should be executable. Please add an entry in the table above. diff --git a/user-scripts/copier b/user-scripts/copier deleted file mode 100755 index 2aec820..0000000 --- a/user-scripts/copier +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env sh - -# Description: Copy selection to clipboard -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -# Linux -cat ~/.nnncp | xargs -0 | xsel -bi - -# macOS -# cat ~/.nnncp | xargs -0 | pbcopy - -# Termux -# cat /data/data/com.termux/files/home/.nnncp | xargs -0 | termux-clipboard-set - -# Cygwin -# cat ~/.nnncp | xargs -0 | clip diff --git a/user-scripts/edit b/user-scripts/edit deleted file mode 100755 index 6155250..0000000 --- a/user-scripts/edit +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -# Description: Fuzzy find a file in directory subtree with fzy and edit in vim -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -vim "$(find -type f | fzy)" diff --git a/user-scripts/fzy b/user-scripts/fzy deleted file mode 100755 index 0ddd229..0000000 --- a/user-scripts/fzy +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -# Description: Fuzzy find a file in directory subtree with fzy and open using xdg-open -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -xdg-open "$(find -type f | fzy)" >/dev/null 2>&1 diff --git a/user-scripts/hexview b/user-scripts/hexview deleted file mode 100755 index 5125fa3..0000000 --- a/user-scripts/hexview +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env sh - -# Description: View a file in hex -# Requires: xxd and $PAGER -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if ! [ -z "$1" ]; then - xxd "$1" | "$PAGER" -fi diff --git a/user-scripts/imgresize b/user-scripts/imgresize deleted file mode 100755 index 6d016f1..0000000 --- a/user-scripts/imgresize +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env sh - -# Description: Resize images in a directory to screen resolution with imgp -# imgp homepage: https://github.com/jarun/imgp -# -# Notes: -# 1. Set res if you don't want to be prompted for desktop resolution every 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= - -# set minimum image size (in bytes) to resize (default: 1MB) -minsize=1048576 - -if [ -z "$res" ]; then - echo -n "desktop resolution (hxv): " - read res -fi - -if ! [ -z "$res" ]; then - if ! [ -z "$minsize" ]; then - imgp -ackx "$res" -s "$minsize" - fi -fi diff --git a/user-scripts/imgur b/user-scripts/imgur deleted file mode 100755 index 0a660fc..0000000 --- a/user-scripts/imgur +++ /dev/null @@ -1,557 +0,0 @@ -#!/usr/bin/env bash -# https://github.com/jomo/imgur-screenshot -# https://imgur.com/tools -# -# 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" - -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 - source "${settings_path}" -fi - -# dependency check -if [ "${1}" = "--check" ]; then - (which grep &>/dev/null && echo "OK: found grep") || echo "ERROR: grep not found" - if is_mac; then - if which growlnotify &>/dev/null; then - echo "OK: found growlnotify" - elif which terminal-notifier &>/dev/null; then - echo "OK: found terminal-notifier" - else - echo "ERROR: growlnotify nor terminal-notifier found" - fi - (which screencapture &>/dev/null && echo "OK: found screencapture") || echo "ERROR: screencapture not found" - (which pbcopy &>/dev/null && echo "OK: found pbcopy") || echo "ERROR: pbcopy not found" - else - (which notify-send &>/dev/null && echo "OK: found notify-send") || echo "ERROR: notify-send (from libnotify-bin) not found" - (which scrot &>/dev/null && echo "OK: found scrot") || echo "ERROR: scrot not found" - (which xclip &>/dev/null && echo "OK: found xclip") || echo "ERROR: xclip not found" - fi - (which 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 which 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}} - - shot_err="$(${cmd} &>/dev/null)" #takes a screenshot with selection - if [ "${?}" != "0" ]; then - 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" | egrep -m 1 --color 'tag_name":\s*".*"' | cut -d '"' -f 4)" - if [ "${?}" -eq "0" ]; then - if [ ! "${current_version}" = "${remote_version}" ] && [ ! -z "${current_version}" ] && [ ! -z "${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 - source "${credentials_file}" - fi - current_time="$(date +%s)" - preemptive_refresh_time="$((10*60))" - expired="$((current_time > (token_expire_time - preemptive_refresh_time)))" - if [ ! -z "${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 - 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}")" - if [ ! "${?}" -eq "0" ]; 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="$(egrep -o 'access_token":".*"' <<<"${1}" | cut -d '"' -f 3)" - refresh_token="$(egrep -o 'refresh_token":".*"' <<<"${1}" | cut -d '"' -f 3)" - expires_in="$(egrep -o '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 egrep -q '"success":\s*true' <<<"${response}"; then - username="$(egrep -o '"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 egrep -q '"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 egrep -q '"success":\s*true' <<<"${response}"; then - img_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - img_ext="$(egrep -o '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https! - del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - - if [ ! -z "${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="$(egrep -o '"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 egrep -q '"success":\s*true' <<<"${response}"; then - img_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - img_ext="$(egrep -o '"link":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4 | rev | cut -d "." -f 1 | rev)" # "link" itself has ugly '\/' escaping and no https! - del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - - if [ ! -z "${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="$(egrep -o '"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) - 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 egrep -q '"success":\s*true' <<<"${response}"; then # Album creation successful - echo "Album '${album_title}' successfully created" - album_id="$(egrep -o '"id":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - del_id="$(egrep -o '"deletehash":\s*"[^"]+"' <<<"${response}" | cut -d "\"" -f 4)" - handle_album_creation_success "http://imgur.com/a/${album_id}" "${del_id}" "${album_title}" - - if [ "${login}" = "false" ]; then - album_id="${del_id}" - fi - else # Album creation failed - err_msg="$(egrep -o '"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 - img_file="$(cd "$( dirname "${img_file}")" && echo "$(pwd)/$(basename "${img_file}")")" - - # check if file exists - if [ ! -f "${img_file}" ]; then - echo "file '${img_file}' doesn't exist !" - 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 diff --git a/user-scripts/kdeconnect b/user-scripts/kdeconnect deleted file mode 100755 index 0fbafbb..0000000 --- a/user-scripts/kdeconnect +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh - -# Description: Send the selected files to your Android device using kdeconnect-cli. You must have installed and configured kdeconnect both on the Android device and on the PC. -# -# Shell: POSIX compliant -# Author: juacq97 - -id=$(kdeconnect-cli -a --id-only | awk '{print $1}') -if [ "$(find ~/.nnncp)" ]; then - kdeconnect-cli -d "$id" --share "$(cat ~/.nnncp)" -# If you want a system notification, uncomment the next 3 lines. -# notify-send -a "Kdeconnect" "Sending $(cat ~/.nnncp)" -#else -# notify-send -a "Kdeconnect" "No file selected" -fi diff --git a/user-scripts/ndiff b/user-scripts/ndiff deleted file mode 100755 index 10af0b3..0000000 --- a/user-scripts/ndiff +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -# Description: File and directory diff using vimdiff -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -vimdiff $(cat ~/.nnncp | tr '\0' '\n') diff --git a/user-scripts/nwal b/user-scripts/nwal deleted file mode 100755 index 2f18b08..0000000 --- a/user-scripts/nwal +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env sh - -# Description: Set the selected image as wallpaper using nitrogen. Just put the cursor on a image and run the script. -# -# Shell: POSIX Compliant -# Author: juacq97 - -if ! [ -z "$1" ]; then - if [ $(mimetype --output-format %m $1 | awk -F '/' '{print $1}') == "image" ]; then - nitrogen --set-zoom-fill --save $1 -# 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/user-scripts/paste b/user-scripts/paste deleted file mode 100755 index de130e4..0000000 --- a/user-scripts/paste +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env sh - -# Description: Paste contents of a text a file to paste.ubuntu.com using pastebinit -# -# pastebinit: https://launchpad.net/pastebinit -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if ! [ -z "$1" ]; then - pastebinit "$1" - read input -fi diff --git a/user-scripts/picker b/user-scripts/picker deleted file mode 100755 index a500435..0000000 --- a/user-scripts/picker +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env sh - -# Description: Pick files and pipe the newline-separated list to another utility -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana -# -# Usage: -# Copy this file in your $PATH, make it executable and preferably name it to picker. -# Run commands like: -# ls -l `picker` -# cd `picker` -# vimdiff `picker` -# or, in fish shell: -# ls -l (picker) -# cd (picker) -# vimdiff (picker) -# -# NOTE: This use case is limited to picking files, other functionality may not work as expected. - -nnn -p /tmp/picked - -if [ -f /tmp/picked ]; then - cat /tmp/picked | tr '\0' '\n' - rm /tmp/picked -fi diff --git a/user-scripts/pywal b/user-scripts/pywal deleted file mode 100755 index 161bbb5..0000000 --- a/user-scripts/pywal +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env sh - -# Description: Set the selected image as wallpaper using pywal and change the terminal color schemes. Just put the cursor on a image and run the script. -# -# Shell: POSIX Compliant -# Author: juacq97 - -if ! [ -z "$1" ]; then - if [ $(mimetype --output-format %m $1 | awk -F '/' '{print $1}') == "image" ]; then - wal -i $1 -# 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/user-scripts/sxiv b/user-scripts/sxiv deleted file mode 100755 index ef21cf7..0000000 --- a/user-scripts/sxiv +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh - -# Description: Open images in current directory in sxiv -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -sxiv -q * >/dev/null 2>&1 & diff --git a/user-scripts/transfer b/user-scripts/transfer deleted file mode 100755 index 7201b0b..0000000 --- a/user-scripts/transfer +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env sh - -# Description: Upload a file to transfer.sh -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if ! [ -z "$1" ]; then - # Upload the file, show the download link and wait till user presses any key - curl -s --upload-file "$1" https://transfer.sh/`basename "$1"` - echo - read input - - # To write download link to "$1".loc and exit - # curl -s --upload-file "$1" https://transfer.sh/`basename "$1"` -o `basename "$1"`.loc -fi diff --git a/user-scripts/upgrade b/user-scripts/upgrade deleted file mode 100755 index 83b9949..0000000 --- a/user-scripts/upgrade +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env sh - -# Description: Check and update to latest version of nnn manually on Debian 9 Stretch -# -# Shell: POSIX-compliant -# Author: Arun Prakash Jana -# NOTE: This script installs a package, should be issued with admin privilege - -cur=`nnn -v` -new=`curl -s "https://github.com/jarun/nnn/releases/latest" | grep -Eo "[0-9]+\.[0-9]+"` - -if [ $cur_ver == $new_ver ]; then - echo 'Already at latest version' - exit 0 -fi - -# get the package -wget "https://github.com/jarun/nnn/releases/download/v$new/nnn_$new-1_debian9.amd64.deb" - -# install it -sudo dpkg -i nnn_$new-1_debian9.amd64.deb - -# remove the file -rm -rf nnn_$new-1_debian9.amd64.deb -- cgit v1.2.3-70-g09d2