feat: Improve and make scripts POSIX compliant
This commit is contained in:
@ -1,38 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# This is an imgs <https://gitea.gch.icu/ge/imgs> "integration" for Nautilus.
|
||||
#!/bin/sh
|
||||
# This is an imgs https://git.nxhs.cloud/ge/imgs "integration" for Nautilus.
|
||||
# Place this script into path: $HOME/.local/share/nautilus/scripts
|
||||
# See more info at: <https://help.ubuntu.com/community/NautilusScriptsHowto>
|
||||
|
||||
imgs_check_vars() {
|
||||
[ "$IMGSLOG" ] || IMGSLOG=$HOME/imgs_debug.log
|
||||
[ "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
|
||||
IMGSLOG="${IMGSLOG:-$HOME/imgs_debug.log}"
|
||||
[ -n "$IMGSREMOTE" ] && return 0 # exit from func if variable is set
|
||||
|
||||
if [ -f "$HOME/.imgsremote" ]; then
|
||||
. $HOME/.imgsremote
|
||||
fi
|
||||
if [ -f "$HOME"/.imgsremote ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. "$HOME"/.imgsremote
|
||||
fi
|
||||
|
||||
if [ "$IMGSREMOTE" ]; then
|
||||
:
|
||||
else
|
||||
echo "$0: Error: IMGSREMOTE variable is not set." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
if [ -z "$IMGSREMOTE" ]; then
|
||||
echo "$0: Error: IMGSREMOTE variable is not set." >&2; exit 1
|
||||
fi
|
||||
|
||||
imgs_check_vars
|
||||
[ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" >> "$IMGSLOG"
|
||||
|
||||
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Started" >> "$IMGSLOG"
|
||||
|
||||
while read -r file; do
|
||||
[ "$file" ] || break
|
||||
if [ "$IMGSDEBUG" ]; then
|
||||
echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | while read -r file; do
|
||||
[ -z "$file" ] && break
|
||||
if [ -n "$IMGSDEBUG" ]; then
|
||||
image="$(curl -v -L -F "image=@$file" "$IMGSREMOTE" 2>&1 | tee -a "$IMGSLOG")"
|
||||
image="$(tail -n 1 <<< "$image")"
|
||||
image="$(echo "$image" | tail -n 1)"
|
||||
else
|
||||
image="$(curl -L -F "image=@$file" "$IMGSREMOTE")"
|
||||
fi
|
||||
[ "$IMGSDEBUG" ] && echo "$(date +"[%d %b %Y %H:%M:%S]") $file --> $image" >> "$IMGSLOG"
|
||||
[ -n "$IMGSDEBUG" ] && echo "$(date +"[%d %b %Y %H:%M:%S]") $file --> $image" >> "$IMGSLOG"
|
||||
notify-send "File uploaded to imgs!" "$image"
|
||||
done <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
|
||||
done
|
||||
|
||||
[ "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" >> "$IMGSLOG"
|
||||
[ -n "$IMGSDEBUG" ] && date +"[%d %b %Y %H:%M:%S] Finished" >> "$IMGSLOG"
|
||||
|
Reference in New Issue
Block a user