mirror of https://github.com/jarun/nnn.git
misc changes
* disable notification by default * use a send function * remove temp file
This commit is contained in:
parent
f948a8966e
commit
ee6133469c
|
@ -11,7 +11,7 @@
|
|||
# Author: juacq97, raffaem
|
||||
|
||||
# If you want system notification, put this equal to 1
|
||||
notify=1
|
||||
notify=0
|
||||
|
||||
note() {
|
||||
if [ $notify = 1 ]; then
|
||||
|
@ -21,52 +21,23 @@ note() {
|
|||
fi
|
||||
}
|
||||
|
||||
# If you have only sh, use this
|
||||
send() {
|
||||
xargs -0 -I{} kdeconnect-cli --name "$devname" --share {}
|
||||
note "Files sent"
|
||||
}
|
||||
|
||||
devname=$(kdeconnect-cli --list-available --name-only 2>/dev/null | awk NR==1)
|
||||
if [ -z "$devname" ]; then
|
||||
note "No devices available"
|
||||
exit
|
||||
fi
|
||||
|
||||
# If you are privileged enough to have bash, use this instead
|
||||
# names=$(kdeconnect-cli --list-available --name-only 2>/dev/null)
|
||||
# IFS=$'\n' read -rd '' -a namesarr <<<"$names"
|
||||
# length=${#namesarr[@]}
|
||||
# if [ "$length" = 0 ]; then
|
||||
# note "No devices available"
|
||||
# exit
|
||||
# elif [ "$length" = 1 ]; then
|
||||
# devname="${namesarr[0]}"
|
||||
# else
|
||||
# for (( j=0; j<length; j++ ));
|
||||
# do
|
||||
# printf "%d. %s\n" "$j" "${namesarr[$j]}"
|
||||
# done
|
||||
# read -r -p "Choice: " choice
|
||||
# devname="${namesarr[$choice]}"
|
||||
# fi
|
||||
|
||||
# Get file that contains NULL-separated list of selected files
|
||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||
|
||||
if [ ! -s "$selection" ]; then
|
||||
if [ -n "$1" ]; then
|
||||
selection=$(mktemp)
|
||||
printf "%s" "$1" > "$selection"
|
||||
else
|
||||
note "No selected files, and no hovered file"
|
||||
exit
|
||||
fi
|
||||
if [ -s "$selection" ]; then
|
||||
send < "$selection"
|
||||
[ -p "$NNN_PIPE" ] && printf "-" > "$NNN_PIPE" # clear selection
|
||||
elif [ -n "$1" ]; then
|
||||
printf "$1" | send
|
||||
else
|
||||
note "No selection and no hovered file"
|
||||
fi
|
||||
|
||||
# Send files over
|
||||
<"$selection" xargs -0 -I{} kdeconnect-cli --name "$devname" --share {}
|
||||
|
||||
# Show notification
|
||||
note "Files sent"
|
||||
|
||||
# Clear selection
|
||||
if [ -p "$NNN_PIPE" ]; then
|
||||
printf "-" > "$NNN_PIPE"
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue