mirror of https://github.com/jarun/nnn.git
Replace which with builtin type in plugins
This commit is contained in:
parent
513b4f24a6
commit
f343f315b5
|
@ -23,28 +23,28 @@ IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
|
||||||
|
|
||||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||||
|
|
||||||
if which xsel >/dev/null 2>&1; then
|
if type xsel >/dev/null 2>&1; then
|
||||||
# Linux
|
# Linux
|
||||||
tr '\0' '\n' < "$selection" | xsel -bi
|
tr '\0' '\n' < "$selection" | xsel -bi
|
||||||
elif which xclip >/dev/null 2>&1; then
|
elif type xclip >/dev/null 2>&1; then
|
||||||
# Linux
|
# Linux
|
||||||
tr '\0' '\n' < "$selection" | xclip -sel clip
|
tr '\0' '\n' < "$selection" | xclip -sel clip
|
||||||
elif which pbcopy >/dev/null 2>&1; then
|
elif type pbcopy >/dev/null 2>&1; then
|
||||||
# macOS
|
# macOS
|
||||||
tr '\0' '\n' < "$selection" | pbcopy
|
tr '\0' '\n' < "$selection" | pbcopy
|
||||||
elif which termux-clipboard-set >/dev/null 2>&1; then
|
elif type termux-clipboard-set >/dev/null 2>&1; then
|
||||||
# Termux
|
# Termux
|
||||||
tr '\0' '\n' < "$selection" | termux-clipboard-set
|
tr '\0' '\n' < "$selection" | termux-clipboard-set
|
||||||
elif which clip.exe >/dev/null 2>&1; then
|
elif type clip.exe >/dev/null 2>&1; then
|
||||||
# WSL
|
# WSL
|
||||||
tr '\0' '\n' < "$selection" | clip.exe
|
tr '\0' '\n' < "$selection" | clip.exe
|
||||||
elif which clip >/dev/null 2>&1; then
|
elif type clip >/dev/null 2>&1; then
|
||||||
# Cygwin
|
# Cygwin
|
||||||
tr '\0' '\n' < "$selection" | clip
|
tr '\0' '\n' < "$selection" | clip
|
||||||
elif which wl-copy >/dev/null 2>&1; then
|
elif type wl-copy >/dev/null 2>&1; then
|
||||||
# Wayland
|
# Wayland
|
||||||
tr '\0' '\n' < "$selection" | wl-copy
|
tr '\0' '\n' < "$selection" | wl-copy
|
||||||
elif which clipboard >/dev/null 2>&1; then
|
elif type clipboard >/dev/null 2>&1; then
|
||||||
# Haiku
|
# Haiku
|
||||||
tr '\0' '\n' < "$selection" | clipboard --stdin
|
tr '\0' '\n' < "$selection" | clipboard --stdin
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -33,6 +33,6 @@ nnn_cd () {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_exists () {
|
cmd_exists () {
|
||||||
which "$1" > /dev/null 2>&1
|
type "$1" > /dev/null 2>&1
|
||||||
echo $?
|
echo $?
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
|
|
||||||
OS="$(uname)"
|
OS="$(uname)"
|
||||||
|
|
||||||
if which notify-send >/dev/null 2>&1; then
|
if type notify-send >/dev/null 2>&1; then
|
||||||
notify-send nnn "Done!"
|
notify-send nnn "Done!"
|
||||||
elif [ "$OS" = "Darwin" ]; then
|
elif [ "$OS" = "Darwin" ]; then
|
||||||
osascript -e 'display notification "Done!" with title "nnn"'
|
osascript -e 'display notification "Done!" with title "nnn"'
|
||||||
elif which ntfy >/dev/null 2>&1; then
|
elif type ntfy >/dev/null 2>&1; then
|
||||||
ntfy -t nnn send "Done!"
|
ntfy -t nnn send "Done!"
|
||||||
elif [ "$OS" = "Haiku" ]; then
|
elif [ "$OS" = "Haiku" ]; then
|
||||||
notify --title "nnn" "Done!"
|
notify --title "nnn" "Done!"
|
||||||
|
|
|
@ -291,7 +291,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are
|
||||||
printf "pattern: "
|
printf "pattern: "
|
||||||
read -r pattern
|
read -r pattern
|
||||||
|
|
||||||
if ! [ -z "$pattern" ]; then
|
if [ -n "$pattern" ]; then
|
||||||
printf "%s" "+l" > "$NNN_PIPE"
|
printf "%s" "+l" > "$NNN_PIPE"
|
||||||
eval "fd -HI $pattern -0" > "$NNN_PIPE"
|
eval "fd -HI $pattern -0" > "$NNN_PIPE"
|
||||||
fi
|
fi
|
||||||
|
@ -306,7 +306,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are
|
||||||
printf "pattern: "
|
printf "pattern: "
|
||||||
read -r pattern
|
read -r pattern
|
||||||
|
|
||||||
if ! [ -z "$pattern" ]; then
|
if [ -n "$pattern" ]; then
|
||||||
printf "%s" "+l" > "$NNN_PIPE"
|
printf "%s" "+l" > "$NNN_PIPE"
|
||||||
eval "rg -l0 --hidden -S $pattern" > "$NNN_PIPE"
|
eval "rg -l0 --hidden -S $pattern" > "$NNN_PIPE"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -16,18 +16,18 @@ if [ ! -p "$NNN_PIPE" ]; then
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if which jump >/dev/null 2>&1; then
|
if type jump >/dev/null 2>&1; then
|
||||||
printf "jump to : "
|
printf "jump to : "
|
||||||
read -r dir
|
read -r dir
|
||||||
odir="$(jump cd "$dir")"
|
odir="$(jump cd "$dir")"
|
||||||
printf "%s" "0c$odir" > "$NNN_PIPE"
|
printf "%s" "0c$odir" > "$NNN_PIPE"
|
||||||
elif which autojump >/dev/null 2>&1; then
|
elif type autojump >/dev/null 2>&1; then
|
||||||
printf "jump to : "
|
printf "jump to : "
|
||||||
read -r dir
|
read -r dir
|
||||||
odir="$(autojump "$dir")"
|
odir="$(autojump "$dir")"
|
||||||
printf "%s" "0c$odir" > "$NNN_PIPE"
|
printf "%s" "0c$odir" > "$NNN_PIPE"
|
||||||
elif which zoxide >/dev/null 2>&1; then
|
elif type zoxide >/dev/null 2>&1; then
|
||||||
if which fzf >/dev/null 2>&1; then
|
if type fzf >/dev/null 2>&1; then
|
||||||
odir="$(zoxide query -i --)"
|
odir="$(zoxide query -i --)"
|
||||||
printf "%s" "0c$odir" > "$NNN_PIPE"
|
printf "%s" "0c$odir" > "$NNN_PIPE"
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,7 +14,7 @@ if [ -n "$GUIPLAYER" ]; then
|
||||||
|
|
||||||
# detach the player
|
# detach the player
|
||||||
sleep 1
|
sleep 1
|
||||||
elif which mocp >/dev/null 2>&1; then
|
elif type mocp >/dev/null 2>&1; then
|
||||||
cmd=$(pgrep -x mocp 2>/dev/null)
|
cmd=$(pgrep -x mocp 2>/dev/null)
|
||||||
ret=$cmd
|
ret=$cmd
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# Description: Clean filename or dirname (either hovered or selections)
|
# Description: Clean filename or dirname (either hovered or selections)
|
||||||
# to be more shell-friendly. This script cleans
|
# to be more shell-friendly. This script cleans
|
||||||
# any character which is not A-Za-z0-9._-
|
# non A-Za-z0-9._- characters.
|
||||||
# and replaces it with underscore (_).
|
# and replaces it with underscore (_).
|
||||||
#
|
#
|
||||||
# It supports cleaning single/double quote, newline,
|
# It supports cleaning single/double quote, newline,
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
# qwe\trty -> __qwe_rty
|
# qwe\trty -> __qwe_rty
|
||||||
#
|
#
|
||||||
# And if there are two almost similar filenames
|
# And if there are two almost similar filenames
|
||||||
# like: 'asd]f' and 'asd f' which both will be renamed to 'asd_f',
|
# like: 'asd]f' and 'asd f' both will be renamed to 'asd_f',
|
||||||
# to avoid overwriting, the last file will be prepended by _.
|
# to avoid overwriting, the last file will be prepended by _.
|
||||||
# So they will be: 'asd_f' and '_asd_f'
|
# So they will be: 'asd_f' and '_asd_f'
|
||||||
#
|
#
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||||
|
|
||||||
if which nvim >/dev/null 2>&1; then
|
if type nvim >/dev/null 2>&1; then
|
||||||
diffcmd="nvim -d"
|
diffcmd="nvim -d"
|
||||||
else
|
else
|
||||||
diffcmd="vimdiff +0"
|
diffcmd="vimdiff +0"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||||
resp=f
|
resp=f
|
||||||
all=
|
all=
|
||||||
if which dragon-drag-and-drop >/dev/null 2>&1; then
|
if type dragon-drag-and-drop >/dev/null 2>&1; then
|
||||||
dnd="dragon-drag-and-drop"
|
dnd="dragon-drag-and-drop"
|
||||||
else
|
else
|
||||||
dnd="dragon"
|
dnd="dragon"
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Author: Arun Prakash Jana
|
# Author: Arun Prakash Jana
|
||||||
|
|
||||||
if which fzf >/dev/null 2>&1; then
|
if type fzf >/dev/null 2>&1; then
|
||||||
fuzzy=fzf
|
fuzzy=fzf
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Author: Arun Prakash Jana
|
# Author: Arun Prakash Jana
|
||||||
|
|
||||||
if which fzf >/dev/null 2>&1; then
|
if type fzf >/dev/null 2>&1; then
|
||||||
cmd="$FZF_DEFAULT_COMMAND"
|
cmd="$FZF_DEFAULT_COMMAND"
|
||||||
if which fd >/dev/null 2>&1; then
|
if type fd >/dev/null 2>&1; then
|
||||||
[ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
|
[ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
|
||||||
else
|
else
|
||||||
[ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
|
[ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
|
||||||
|
@ -19,7 +19,7 @@ if which fzf >/dev/null 2>&1; then
|
||||||
entry="$(eval "$cmd" | fzf --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
|
entry="$(eval "$cmd" | fzf --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
|
||||||
# To show only the file name
|
# To show only the file name
|
||||||
# entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
|
# entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
|
||||||
elif which sk >/dev/null 2>&1; then
|
elif type sk >/dev/null 2>&1; then
|
||||||
entry=$(find . -type f 2>/dev/null | sk)
|
entry=$(find . -type f 2>/dev/null | sk)
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -6,14 +6,13 @@
|
||||||
#
|
#
|
||||||
# For better compatibility with as many nnn plugins as possible, fzfplug will first execute
|
# For better compatibility with as many nnn plugins as possible, fzfplug will first execute
|
||||||
# the chosen script on the file hovered in nnn, and upon failure, try to run it with no target
|
# the chosen script on the file hovered in nnn, and upon failure, try to run it with no target
|
||||||
# (which should actually run it on selected files if nnn has an active selection). I don't
|
# (i.e on an active selection, if present).
|
||||||
# have the required dependencies to confirm compatibility with all scripts though.
|
|
||||||
#
|
#
|
||||||
# Dependencies: find, fzf, cat (or bat, if installed)
|
# Dependencies: find, fzf, cat (or bat, if installed)
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Author: Kabouik
|
# Author: Kabouik
|
||||||
|
|
||||||
# OPTIONAL SCRIPTS SOURCES
|
# Optional scripts sources
|
||||||
# Leave blank or fill with the absolute path of a folder containing executable scripts other than nnn plugins
|
# 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).
|
# (e.g., "$HOME/.local/share/nautilus/scripts", since there are numerous Nautilus script git repositories).
|
||||||
# Add extra variables if need be, but be sure to call them in the find command below at lines 28:49 and 30:49.
|
# Add extra variables if need be, but be sure to call them in the find command below at lines 28:49 and 30:49.
|
||||||
|
@ -21,28 +20,28 @@
|
||||||
CUSTOMDIR1=""
|
CUSTOMDIR1=""
|
||||||
CUSTOMDIR2=""
|
CUSTOMDIR2=""
|
||||||
|
|
||||||
# REQUIRED VARIABLES
|
|
||||||
nnnpluginsdir="$HOME/.config/nnn/plugins"
|
nnnpluginsdir="$HOME/.config/nnn/plugins"
|
||||||
|
|
||||||
# PREVIEW WITH bat INSTEAD OF cat IF INSTALLED
|
# Preview with bat if installed
|
||||||
if [ -z "$(command -v bat)" ]; then
|
if [ -z "$(command -v bat)" ]; then
|
||||||
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'cat {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
|
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'cat {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
|
||||||
else
|
else
|
||||||
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'bat --color=always --style=grid {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
|
plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'bat --color=always --style=grid {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TRY RUNNING THE SCRIPT ON HOVERED FILE FIRST, AND ABORT IF NO PLUGIN WAS SELECTED IN FZFPLUG (ESC OR ^C),
|
# Try running the script on the hovered file, and abort if no plugin was selected (ESC or ^C pressed),
|
||||||
err=0
|
err=0
|
||||||
if ! [ "$plugin" = "" ]; then
|
if ! [ "$plugin" = "" ]; then
|
||||||
"$plugin" "$1" || err=1
|
"$plugin" "$1" || err=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# IF THAT FAILS WITH HOVERED FILE, TRY WITH NO TARGET (nnn SELECTIONS SHOULD STILL BE PASSED TO THE SCRIPT IN THAT CASE)
|
# If attempt with hovered file fails, try without any target
|
||||||
|
# (nnn selections should still be passed to the script int hat case)
|
||||||
if [ "$err" -eq "1" ]; then
|
if [ "$err" -eq "1" ]; then
|
||||||
clear && "$plugin" || err=2
|
clear && "$plugin" || err=2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# IF THAT FAILS TOO, ABORT AND SHOW AN ERROR
|
# Abort and show error if both fail
|
||||||
if [ "$err" -eq "2" ]; then
|
if [ "$err" -eq "2" ]; then
|
||||||
sep="\n---\n"
|
sep="\n---\n"
|
||||||
printf "$sep""Failed to execute '%s'. See error above or try without fzfplug. Press return to continue. " "$plugin" && read -r _ && clear
|
printf "$sep""Failed to execute '%s'. See error above or try without fzfplug. Press return to continue. " "$plugin" && read -r _ && clear
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
. "$(dirname "$0")"/.nnn-plugin-helper
|
. "$(dirname "$0")"/.nnn-plugin-helper
|
||||||
|
|
||||||
if which fzf >/dev/null 2>&1; then
|
if type fzf >/dev/null 2>&1; then
|
||||||
fuzzy=fzf
|
fuzzy=fzf
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -8,13 +8,8 @@
|
||||||
CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/
|
CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/
|
||||||
PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
|
PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
|
||||||
|
|
||||||
# is_cmd_exists () {
|
|
||||||
# which "$1" > /dev/null 2>&1
|
|
||||||
# echo $?
|
|
||||||
# }
|
|
||||||
|
|
||||||
merge () {
|
merge () {
|
||||||
if which nvim >/dev/null 2>&1; then
|
if type nvim >/dev/null 2>&1; then
|
||||||
nvim -d "$1" "$2"
|
nvim -d "$1" "$2"
|
||||||
else
|
else
|
||||||
vimdiff +0 "$1" "$2"
|
vimdiff +0 "$1" "$2"
|
||||||
|
@ -35,18 +30,10 @@ prompt () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
|
||||||
# sucmd=sudo
|
|
||||||
# elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
|
||||||
# sucmd=doas
|
|
||||||
# else
|
|
||||||
# sucmd=: # noop
|
|
||||||
# fi
|
|
||||||
|
|
||||||
if [ "$1" = "master" ] ; then
|
if [ "$1" = "master" ] ; then
|
||||||
VER="master"
|
VER="master"
|
||||||
ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz
|
ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz
|
||||||
elif which nnn >/dev/null 2>&1; then
|
elif type nnn >/dev/null 2>&1; then
|
||||||
VER=$(nnn -V)
|
VER=$(nnn -V)
|
||||||
ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
|
ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# Author: Arun Prakash Jana
|
# Author: Arun Prakash Jana
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
if which hx >/dev/null 2>&1; then
|
if type hx >/dev/null 2>&1; then
|
||||||
hx "$1"
|
hx "$1"
|
||||||
else
|
else
|
||||||
xxd "$1" | $PAGER
|
xxd "$1" | $PAGER
|
||||||
|
|
|
@ -117,23 +117,23 @@ fi
|
||||||
|
|
||||||
# dependency check
|
# dependency check
|
||||||
if [ "${1}" = "--check" ]; then
|
if [ "${1}" = "--check" ]; then
|
||||||
(which grep &>/dev/null && echo "OK: found grep") || echo "ERROR: grep not found"
|
(type grep &>/dev/null && echo "OK: found grep") || echo "ERROR: grep not found"
|
||||||
if is_mac; then
|
if is_mac; then
|
||||||
if which growlnotify &>/dev/null; then
|
if type growlnotify &>/dev/null; then
|
||||||
echo "OK: found growlnotify"
|
echo "OK: found growlnotify"
|
||||||
elif which terminal-notifier &>/dev/null; then
|
elif type terminal-notifier &>/dev/null; then
|
||||||
echo "OK: found terminal-notifier"
|
echo "OK: found terminal-notifier"
|
||||||
else
|
else
|
||||||
echo "ERROR: growlnotify nor terminal-notifier found"
|
echo "ERROR: growlnotify nor terminal-notifier found"
|
||||||
fi
|
fi
|
||||||
(which screencapture &>/dev/null && echo "OK: found screencapture") || echo "ERROR: screencapture not found"
|
(type 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"
|
(type pbcopy &>/dev/null && echo "OK: found pbcopy") || echo "ERROR: pbcopy not found"
|
||||||
else
|
else
|
||||||
(which notify-send &>/dev/null && echo "OK: found notify-send") || echo "ERROR: notify-send (from libnotify-bin) not found"
|
(type 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"
|
(type 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"
|
(type xclip &>/dev/null && echo "OK: found xclip") || echo "ERROR: xclip not found"
|
||||||
fi
|
fi
|
||||||
(which curl &>/dev/null && echo "OK: found curl") || echo "ERROR: curl not found"
|
(type curl &>/dev/null && echo "OK: found curl") || echo "ERROR: curl not found"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ fi
|
||||||
# notify <'ok'|'error'> <title> <text>
|
# notify <'ok'|'error'> <title> <text>
|
||||||
function notify() {
|
function notify() {
|
||||||
if is_mac; then
|
if is_mac; then
|
||||||
if which growlnotify &>/dev/null; then
|
if type growlnotify &>/dev/null; then
|
||||||
growlnotify --icon "${imgur_icon_path}" --iconpath "${imgur_icon_path}" --title "${2}" --message "${3}"
|
growlnotify --icon "${imgur_icon_path}" --iconpath "${imgur_icon_path}" --title "${2}" --message "${3}"
|
||||||
else
|
else
|
||||||
terminal-notifier -appIcon "${imgur_icon_path}" -contentImage "${imgur_icon_path}" -title "imgur: ${2}" -message "${3}"
|
terminal-notifier -appIcon "${imgur_icon_path}" -contentImage "${imgur_icon_path}" -title "imgur: ${2}" -message "${3}"
|
||||||
|
|
|
@ -49,19 +49,19 @@ if uname | grep -q "Darwin"; then
|
||||||
fi
|
fi
|
||||||
# `imvr` is often callable as `imv` on Linux distros
|
# `imvr` is often callable as `imv` on Linux distros
|
||||||
# You might need to change the reference below
|
# You might need to change the reference below
|
||||||
elif which imvr >/dev/null 2>&1; then
|
elif type imvr >/dev/null 2>&1; then
|
||||||
if [ -f "$1" ]; then
|
if [ -f "$1" ]; then
|
||||||
view_dir imvr "$1" >/dev/null 2>&1 &
|
view_dir imvr "$1" >/dev/null 2>&1 &
|
||||||
elif [ -d "$1" ] || [ -h "$1" ]; then
|
elif [ -d "$1" ] || [ -h "$1" ]; then
|
||||||
imvr "$1" >/dev/null 2>&1 &
|
imvr "$1" >/dev/null 2>&1 &
|
||||||
fi
|
fi
|
||||||
elif which sxiv >/dev/null 2>&1; then
|
elif type sxiv >/dev/null 2>&1; then
|
||||||
if [ -f "$1" ]; then
|
if [ -f "$1" ]; then
|
||||||
view_dir sxiv "$1" >/dev/null 2>&1 &
|
view_dir sxiv "$1" >/dev/null 2>&1 &
|
||||||
elif [ -d "$1" ] || [ -h "$1" ]; then
|
elif [ -d "$1" ] || [ -h "$1" ]; then
|
||||||
sxiv -aqt "$1" >/dev/null 2>&1 &
|
sxiv -aqt "$1" >/dev/null 2>&1 &
|
||||||
fi
|
fi
|
||||||
elif which viu >/dev/null 2>&1; then
|
elif type viu >/dev/null 2>&1; then
|
||||||
viu -n "$1" | less -R
|
viu -n "$1" | less -R
|
||||||
else
|
else
|
||||||
printf "Please install imv/sxiv/viu and check their callable names match the plugin source"
|
printf "Please install imv/sxiv/viu and check their callable names match the plugin source"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
IFS=':'
|
IFS=':'
|
||||||
|
|
||||||
get_selection() {
|
get_selection() {
|
||||||
if which fzf >/dev/null 2>&1; then
|
if type fzf >/dev/null 2>&1; then
|
||||||
{ IFS=':'; ls -H $PATH; } | sort | fzf
|
{ IFS=':'; ls -H $PATH; } | sort | fzf
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
|
|
74
plugins/nuke
74
plugins/nuke
|
@ -91,36 +91,36 @@ handle_pdf() {
|
||||||
if [ "$GUI" -ne 0 ] && is_mac; then
|
if [ "$GUI" -ne 0 ] && is_mac; then
|
||||||
nohup open "${FPATH}" >/dev/null 2>&1 &
|
nohup open "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then
|
elif [ "$GUI" -ne 0 ] && type zathura >/dev/null 2>&1; then
|
||||||
nohup zathura "${FPATH}" >/dev/null 2>&1 &
|
nohup zathura "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif which pdftotext >/dev/null 2>&1; then
|
elif type pdftotext >/dev/null 2>&1; then
|
||||||
## Preview as text conversion
|
## Preview as text conversion
|
||||||
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER"
|
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which mutool >/dev/null 2>&1; then
|
elif type mutool >/dev/null 2>&1; then
|
||||||
mutool draw -F txt -i -- "${FPATH}" 1-10 | eval "$PAGER"
|
mutool draw -F txt -i -- "${FPATH}" 1-10 | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which exiftool >/dev/null 2>&1; then
|
elif type exiftool >/dev/null 2>&1; then
|
||||||
exiftool "${FPATH}" | eval "$PAGER"
|
exiftool "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_audio() {
|
handle_audio() {
|
||||||
if which mocp >/dev/null 2>&1 && which mocplay >/dev/null 2>&1; then
|
if type mocp >/dev/null 2>&1 && type mocplay >/dev/null 2>&1; then
|
||||||
mocplay "${FPATH}" "opener" >/dev/null 2>&1
|
mocplay "${FPATH}" "opener" >/dev/null 2>&1
|
||||||
exit 0
|
exit 0
|
||||||
elif which mpv >/dev/null 2>&1; then
|
elif type mpv >/dev/null 2>&1; then
|
||||||
mpv "${FPATH}" >/dev/null 2>&1 &
|
mpv "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif which media_client >/dev/null 2>&1; then
|
elif type media_client >/dev/null 2>&1; then
|
||||||
media_client play "${FPATH}" >/dev/null 2>&1 &
|
media_client play "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif which mediainfo >/dev/null 2>&1; then
|
elif type mediainfo >/dev/null 2>&1; then
|
||||||
mediainfo "${FPATH}" | eval "$PAGER"
|
mediainfo "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which exiftool >/dev/null 2>&1; then
|
elif type exiftool >/dev/null 2>&1; then
|
||||||
exiftool "${FPATH}"| eval "$PAGER"
|
exiftool "${FPATH}"| eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -130,22 +130,22 @@ handle_video() {
|
||||||
if [ "$GUI" -ne 0 ] && is_mac; then
|
if [ "$GUI" -ne 0 ] && is_mac; then
|
||||||
nohup open "${FPATH}" >/dev/null 2>&1 &
|
nohup open "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then
|
elif [ "$GUI" -ne 0 ] && type smplayer >/dev/null 2>&1; then
|
||||||
nohup smplayer "${FPATH}" >/dev/null 2>&1 &
|
nohup smplayer "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$GUI" -ne 0 ] && which mpv >/dev/null 2>&1; then
|
elif [ "$GUI" -ne 0 ] && type mpv >/dev/null 2>&1; then
|
||||||
nohup mpv "${FPATH}" >/dev/null 2>&1 &
|
nohup mpv "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif which ffmpegthumbnailer >/dev/null 2>&1; then
|
elif type ffmpegthumbnailer >/dev/null 2>&1; then
|
||||||
# Thumbnail
|
# Thumbnail
|
||||||
[ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}"
|
[ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}"
|
||||||
ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0
|
ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0
|
||||||
viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER"
|
viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which mediainfo >/dev/null 2>&1; then
|
elif type mediainfo >/dev/null 2>&1; then
|
||||||
mediainfo "${FPATH}" | eval "$PAGER"
|
mediainfo "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which exiftool >/dev/null 2>&1; then
|
elif type exiftool >/dev/null 2>&1; then
|
||||||
exiftool "${FPATH}"| eval "$PAGER"
|
exiftool "${FPATH}"| eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -157,22 +157,22 @@ handle_extension() {
|
||||||
## Archive
|
## Archive
|
||||||
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
|
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
|
||||||
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
|
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
|
||||||
if which atool >/dev/null 2>&1; then
|
if type atool >/dev/null 2>&1; then
|
||||||
atool --list -- "${FPATH}" | eval "$PAGER"
|
atool --list -- "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which bsdtar >/dev/null 2>&1; then
|
elif type bsdtar >/dev/null 2>&1; then
|
||||||
bsdtar --list --file "${FPATH}" | eval "$PAGER"
|
bsdtar --list --file "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
exit 1;;
|
exit 1;;
|
||||||
rar)
|
rar)
|
||||||
if which unrar >/dev/null 2>&1; then
|
if type unrar >/dev/null 2>&1; then
|
||||||
## Avoid password prompt by providing empty password
|
## Avoid password prompt by providing empty password
|
||||||
unrar lt -p- -- "${FPATH}" | eval "$PAGER"
|
unrar lt -p- -- "${FPATH}" | eval "$PAGER"
|
||||||
fi
|
fi
|
||||||
exit 1;;
|
exit 1;;
|
||||||
7z)
|
7z)
|
||||||
if which 7z >/dev/null 2>&1; then
|
if type 7z >/dev/null 2>&1; then
|
||||||
## Avoid password prompt by providing empty password
|
## Avoid password prompt by providing empty password
|
||||||
7z l -p -- "${FPATH}" | eval "$PAGER"
|
7z l -p -- "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -201,10 +201,10 @@ handle_extension() {
|
||||||
|
|
||||||
## BitTorrent
|
## BitTorrent
|
||||||
torrent)
|
torrent)
|
||||||
if which rtorrent >/dev/null 2>&1; then
|
if type rtorrent >/dev/null 2>&1; then
|
||||||
rtorrent "${FPATH}"
|
rtorrent "${FPATH}"
|
||||||
exit 0
|
exit 0
|
||||||
elif which transmission-show >/dev/null 2>&1; then
|
elif type transmission-show >/dev/null 2>&1; then
|
||||||
transmission-show -- "${FPATH}"
|
transmission-show -- "${FPATH}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -212,7 +212,7 @@ handle_extension() {
|
||||||
|
|
||||||
## OpenDocument
|
## OpenDocument
|
||||||
odt|ods|odp|sxw)
|
odt|ods|odp|sxw)
|
||||||
if which odt2txt >/dev/null 2>&1; then
|
if type odt2txt >/dev/null 2>&1; then
|
||||||
## Preview as text conversion
|
## Preview as text conversion
|
||||||
odt2txt "${FPATH}" | eval "$PAGER"
|
odt2txt "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -221,10 +221,10 @@ handle_extension() {
|
||||||
|
|
||||||
## Markdown
|
## Markdown
|
||||||
md)
|
md)
|
||||||
if which glow >/dev/null 2>&1; then
|
if type glow >/dev/null 2>&1; then
|
||||||
glow -sdark "${FPATH}" | eval "$PAGER"
|
glow -sdark "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which lowdown >/dev/null 2>&1; then
|
elif type lowdown >/dev/null 2>&1; then
|
||||||
lowdown -Tterm "${FPATH}" | eval "$PAGER"
|
lowdown -Tterm "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -233,13 +233,13 @@ handle_extension() {
|
||||||
## HTML
|
## HTML
|
||||||
htm|html|xhtml)
|
htm|html|xhtml)
|
||||||
## Preview as text conversion
|
## Preview as text conversion
|
||||||
if which w3m >/dev/null 2>&1; then
|
if type w3m >/dev/null 2>&1; then
|
||||||
w3m -dump "${FPATH}" | eval "$PAGER"
|
w3m -dump "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which lynx >/dev/null 2>&1; then
|
elif type lynx >/dev/null 2>&1; then
|
||||||
lynx -dump -- "${FPATH}" | eval "$PAGER"
|
lynx -dump -- "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which elinks >/dev/null 2>&1; then
|
elif type elinks >/dev/null 2>&1; then
|
||||||
elinks -dump "${FPATH}" | eval "$PAGER"
|
elinks -dump "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -247,10 +247,10 @@ handle_extension() {
|
||||||
|
|
||||||
## JSON
|
## JSON
|
||||||
json)
|
json)
|
||||||
if which jq >/dev/null 2>&1; then
|
if type jq >/dev/null 2>&1; then
|
||||||
jq --color-output . "${FPATH}" | eval "$PAGER"
|
jq --color-output . "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which python >/dev/null 2>&1; then
|
elif type python >/dev/null 2>&1; then
|
||||||
python -m json.tool -- "${FPATH}" | eval "$PAGER"
|
python -m json.tool -- "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -311,19 +311,19 @@ handle_multimedia() {
|
||||||
if [ "$GUI" -ne 0 ] && is_mac; then
|
if [ "$GUI" -ne 0 ] && is_mac; then
|
||||||
nohup open "${FPATH}" >/dev/null 2>&1 &
|
nohup open "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$GUI" -ne 0 ] && which imvr >/dev/null 2>&1; then
|
elif [ "$GUI" -ne 0 ] && type imvr >/dev/null 2>&1; then
|
||||||
load_dir imvr "${FPATH}" >/dev/null 2>&1 &
|
load_dir imvr "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$GUI" -ne 0 ] && which sxiv >/dev/null 2>&1; then
|
elif [ "$GUI" -ne 0 ] && type sxiv >/dev/null 2>&1; then
|
||||||
load_dir sxiv "${FPATH}" >/dev/null 2>&1 &
|
load_dir sxiv "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif which viu >/dev/null 2>&1; then
|
elif type viu >/dev/null 2>&1; then
|
||||||
viu -n "${FPATH}" | eval "$PAGER"
|
viu -n "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which img2txt >/dev/null 2>&1; then
|
elif type img2txt >/dev/null 2>&1; then
|
||||||
img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER"
|
img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which exiftool >/dev/null 2>&1; then
|
elif type exiftool >/dev/null 2>&1; then
|
||||||
exiftool "${FPATH}" | eval "$PAGER"
|
exiftool "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -466,11 +466,11 @@ handle_mime() {
|
||||||
|
|
||||||
## DjVu
|
## DjVu
|
||||||
image/vnd.djvu)
|
image/vnd.djvu)
|
||||||
if which djvutxt >/dev/null 2>&1; then
|
if type djvutxt >/dev/null 2>&1; then
|
||||||
## Preview as text conversion (requires djvulibre)
|
## Preview as text conversion (requires djvulibre)
|
||||||
djvutxt "${FPATH}" | eval "$PAGER"
|
djvutxt "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
elif which exiftool >/dev/null 2>&1; then
|
elif type exiftool >/dev/null 2>&1; then
|
||||||
exiftool "${FPATH}" | eval "$PAGER"
|
exiftool "${FPATH}" | eval "$PAGER"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -479,10 +479,10 @@ handle_mime() {
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_fallback() {
|
handle_fallback() {
|
||||||
if [ "$GUI" -ne 0 ] && which xdg-open >/dev/null 2>&1; then
|
if [ "$GUI" -ne 0 ] && type xdg-open >/dev/null 2>&1; then
|
||||||
nohup xdg-open "${FPATH}" >/dev/null 2>&1 &
|
nohup xdg-open "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$GUI" -ne 0 ] && which open >/dev/null 2>&1; then
|
elif [ "$GUI" -ne 0 ] && type open >/dev/null 2>&1; then
|
||||||
nohup open "${FPATH}" >/dev/null 2>&1 &
|
nohup open "${FPATH}" >/dev/null 2>&1 &
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -54,11 +54,11 @@ PAGER=${PAGER:-"vim -R"}
|
||||||
NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
|
NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
|
||||||
|
|
||||||
|
|
||||||
if which xterm >/dev/null 2>&1 ; then
|
if type xterm >/dev/null 2>&1 ; then
|
||||||
TERMINAL="xterm -into"
|
TERMINAL="xterm -into"
|
||||||
elif which urxvt >/dev/null 2>&1 ; then
|
elif type urxvt >/dev/null 2>&1 ; then
|
||||||
TERMINAL="urxvt -embed"
|
TERMINAL="urxvt -embed"
|
||||||
elif which st >/dev/null 2>&1 ; then
|
elif type st >/dev/null 2>&1 ; then
|
||||||
TERMINAL="st -w"
|
TERMINAL="st -w"
|
||||||
else
|
else
|
||||||
echo "No xembed term found" >&2
|
echo "No xembed term found" >&2
|
||||||
|
@ -142,28 +142,28 @@ previewer_loop () {
|
||||||
|
|
||||||
case "$MIME" in
|
case "$MIME" in
|
||||||
video/*)
|
video/*)
|
||||||
if which mpv >/dev/null 2>&1 ; then
|
if type mpv >/dev/null 2>&1 ; then
|
||||||
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
|
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
|
||||||
else
|
else
|
||||||
term_nuke "$XID" "$FILE"
|
term_nuke "$XID" "$FILE"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
audio/*)
|
audio/*)
|
||||||
if which mpv >/dev/null 2>&1 ; then
|
if type mpv >/dev/null 2>&1 ; then
|
||||||
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
|
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
|
||||||
else
|
else
|
||||||
term_nuke "$XID" "$FILE"
|
term_nuke "$XID" "$FILE"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
image/*)
|
image/*)
|
||||||
if which sxiv >/dev/null 2>&1 ; then
|
if type sxiv >/dev/null 2>&1 ; then
|
||||||
sxiv -e "$XID" "$FILE" &
|
sxiv -e "$XID" "$FILE" &
|
||||||
else
|
else
|
||||||
term_nuke "$XID" "$FILE"
|
term_nuke "$XID" "$FILE"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
application/pdf)
|
application/pdf)
|
||||||
if which zathura >/dev/null 2>&1 ; then
|
if type zathura >/dev/null 2>&1 ; then
|
||||||
zathura -e "$XID" "$FILE" &
|
zathura -e "$XID" "$FILE" &
|
||||||
else
|
else
|
||||||
term_nuke "$XID" "$FILE"
|
term_nuke "$XID" "$FILE"
|
||||||
|
|
|
@ -138,7 +138,7 @@ togglepreview() {
|
||||||
}
|
}
|
||||||
|
|
||||||
exists() {
|
exists() {
|
||||||
which "$1" >/dev/null 2>&1
|
type "$1" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
fifo_pager() {
|
fifo_pager() {
|
||||||
|
|
|
@ -158,7 +158,7 @@ togglepreview() {
|
||||||
}
|
}
|
||||||
|
|
||||||
exists() {
|
exists() {
|
||||||
which "$1" >/dev/null 2>&1
|
type "$1" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
fifo_pager() {
|
fifo_pager() {
|
||||||
|
|
|
@ -14,15 +14,15 @@ read -r psname
|
||||||
|
|
||||||
# shellcheck disable=SC2009
|
# shellcheck disable=SC2009
|
||||||
if [ -n "$psname" ]; then
|
if [ -n "$psname" ]; then
|
||||||
if which sudo >/dev/null 2>&1; then
|
if type sudo >/dev/null 2>&1; then
|
||||||
sucmd=sudo
|
sucmd=sudo
|
||||||
elif which doas >/dev/null 2>&1; then
|
elif type doas >/dev/null 2>&1; then
|
||||||
sucmd=doas
|
sucmd=doas
|
||||||
else
|
else
|
||||||
sucmd=: # noop
|
sucmd=: # noop
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if which fzf >/dev/null 2>&1; then
|
if type fzf >/dev/null 2>&1; then
|
||||||
fuzzy=fzf
|
fuzzy=fzf
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
|
|
||||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||||
|
|
||||||
if which qmv >/dev/null 2>&1; then
|
if type qmv >/dev/null 2>&1; then
|
||||||
batchrenamesel="qmv -fdo -da"
|
batchrenamesel="qmv -fdo -da"
|
||||||
batchrename="qmv -fdo -a"
|
batchrename="qmv -fdo -a"
|
||||||
elif which vidir >/dev/null 2>&1; then
|
elif type vidir >/dev/null 2>&1; then
|
||||||
batchrenamesel="vidir"
|
batchrenamesel="vidir"
|
||||||
batchrename="vidir"
|
batchrename="vidir"
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,15 +7,10 @@
|
||||||
|
|
||||||
EDITOR="${EDITOR:-vim}"
|
EDITOR="${EDITOR:-vim}"
|
||||||
|
|
||||||
is_cmd_exists () {
|
if type sudo >/dev/null 2>&1; then
|
||||||
which "$1" > /dev/null 2>&1
|
|
||||||
echo $?
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
|
||||||
sudo "$EDITOR" "$1"
|
sudo "$EDITOR" "$1"
|
||||||
elif [ "$(is_cmd_exists sudoedit)" -eq "0" ]; then
|
elif type sudoedit >/dev/null 2>&1; then
|
||||||
sudoedit "$1"
|
sudoedit "$1"
|
||||||
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
elif type doas >/dev/null 2>&1; then
|
||||||
doas "$EDITOR" "$1"
|
doas "$EDITOR" "$1"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -11,38 +11,38 @@
|
||||||
# TODO: Try better avoiding lazy unmount by forcing nnn context to leave the subfolder before fusermount.
|
# TODO: Try better avoiding lazy unmount by forcing nnn context to leave the subfolder before fusermount.
|
||||||
# I tried `printf "%s" "0c$m" > "$NNN_PIPE"` but this would break nnn UI all the time, see #854.
|
# I tried `printf "%s" "0c$m" > "$NNN_PIPE"` but this would break nnn UI all the time, see #854.
|
||||||
|
|
||||||
# ENVIRONMENT
|
|
||||||
err=0
|
err=0
|
||||||
m=$HOME/.config/nnn/mounts
|
m=$HOME/.config/nnn/mounts
|
||||||
if [ "$PWD" = "$m" ]; then # ALLOW USING THE SCRIPT ON HOVERED DIRECTORY IF USER IS IN ~/.config/nnn/mounts
|
if [ "$PWD" = "$m" ]; then
|
||||||
|
# Allow running the script on hovered directory if user is in ~/.config/nnn/mounts
|
||||||
d="$1"
|
d="$1"
|
||||||
else
|
else
|
||||||
d=$(dirname "$(readlink -f "$1")" | grep -oP "^$m\K.*" | cut -d"/" -f2)
|
d=$(dirname "$(readlink -f "$1")" | grep -oP "^$m\K.*" | cut -d"/" -f2)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TEST IF USER IS CURRENTLY WITHIN $m OR A SUBFOLDER, ABORT IF NOT
|
# Test if user is within $m or a subdir, abort if not
|
||||||
if [ "$d" = "" ]; then
|
if [ "$d" = "" ]; then
|
||||||
clear && printf "You are not in a remote folder mounted with nnn. Press return to continue. " && read -r _
|
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
|
else
|
||||||
# TEST IF $m/$d IS A MOUNTPOINT AND TRY UNMOUNTING IF YES
|
cd "$m" && fusermount -uq "$m/$d" || err=1
|
||||||
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 FAILURE TO UNMOUNT, OFFER TO TRY LAZY UNMOUNT
|
|
||||||
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
|
|
||||||
err=0
|
|
||||||
cd "$m" && fusermount -uqz "$m/$d" || err=1
|
|
||||||
if [ "$err" -eq "0" ]; then
|
if [ "$err" -eq "0" ]; then
|
||||||
rmdir "$m/$d" && clear && printf "Parent '%s' unmounted with lazy unmount. " "$d"
|
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
|
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
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
# Author: Arun Prakash Jana
|
# Author: Arun Prakash Jana
|
||||||
|
|
||||||
if [ -n "$1" ] && [ -s "$1" ]; then
|
if [ -n "$1" ] && [ -s "$1" ]; then
|
||||||
if which ffsend >/dev/null 2>&1; then
|
if type ffsend >/dev/null 2>&1; then
|
||||||
ffsend -fiq u "$1"
|
ffsend -fiq u "$1"
|
||||||
elif [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "text" ]; then
|
elif [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "text" ]; then
|
||||||
curl -F "f:1=@$1" ix.io
|
curl -F "f:1=@$1" ix.io
|
||||||
|
|
|
@ -6,16 +6,11 @@
|
||||||
# Shell: POSIX Compliant
|
# Shell: POSIX Compliant
|
||||||
# Author: juacq97
|
# Author: juacq97
|
||||||
|
|
||||||
cmd_exists () {
|
|
||||||
which "$1" > /dev/null 2>&1
|
|
||||||
echo $?
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
if [ "$(file --mime-type "$1" | awk '{print $NF}' | awk -F '/' '{print $1}')" = "image" ]; then
|
if [ "$(file --mime-type "$1" | awk '{print $NF}' | awk -F '/' '{print $1}')" = "image" ]; then
|
||||||
if [ "$(cmd_exists nitrogen)" -eq "0" ]; then
|
if type nitrogen >/dev/null 2>&1; then
|
||||||
nitrogen --set-zoom-fill --save "$1"
|
nitrogen --set-zoom-fill --save "$1"
|
||||||
elif [ "$(cmd_exists wal)" -eq "0" ]; then
|
elif type wal >/dev/null 2>&1; then
|
||||||
wal -i "$1"
|
wal -i "$1"
|
||||||
else
|
else
|
||||||
printf "nitrogen ir pywal missing"
|
printf "nitrogen ir pywal missing"
|
||||||
|
|
|
@ -22,28 +22,28 @@ selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||||
|
|
||||||
getclip () {
|
getclip () {
|
||||||
|
|
||||||
if which xsel >/dev/null 2>&1; then
|
if type xsel >/dev/null 2>&1; then
|
||||||
# Linux
|
# Linux
|
||||||
xsel -bo
|
xsel -bo
|
||||||
elif which xclip >/dev/null 2>&1; then
|
elif type xclip >/dev/null 2>&1; then
|
||||||
# Linux
|
# Linux
|
||||||
xclip -sel clip -o
|
xclip -sel clip -o
|
||||||
elif which pbpaste >/dev/null 2>&1; then
|
elif type pbpaste >/dev/null 2>&1; then
|
||||||
# macOS
|
# macOS
|
||||||
pbpaste
|
pbpaste
|
||||||
elif which termux-clipboard-get >/dev/null 2>&1; then
|
elif type termux-clipboard-get >/dev/null 2>&1; then
|
||||||
# Termux
|
# Termux
|
||||||
termux-clipboard-get
|
termux-clipboard-get
|
||||||
elif which powershell.exe >/dev/null 2>&1; then
|
elif type powershell.exe >/dev/null 2>&1; then
|
||||||
# WSL
|
# WSL
|
||||||
powershell.exe Get-Clipboard
|
powershell.exe Get-Clipboard
|
||||||
elif [ -r /dev/clipboard ] ; then
|
elif [ -r /dev/clipboard ] ; then
|
||||||
# Cygwin
|
# Cygwin
|
||||||
cat /dev/clipboard
|
cat /dev/clipboard
|
||||||
elif which wl-paste >/dev/null 2>&1; then
|
elif type wl-paste >/dev/null 2>&1; then
|
||||||
# Wayland
|
# Wayland
|
||||||
wl-paste
|
wl-paste
|
||||||
elif which clipboard >/dev/null 2>&1; then
|
elif type clipboard >/dev/null 2>&1; then
|
||||||
# Haiku
|
# Haiku
|
||||||
clipboard --print
|
clipboard --print
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue