diff --git a/sup b/sup index 32771dc..d29b4c7 100755 --- a/sup +++ b/sup @@ -13,11 +13,11 @@ cfg_screenshot_ext='png' [[ -f $HOME/.suprc ]] && { source "$HOME/.suprc"; } -sup.msg() { echo "[sup] $1"; } +sup.msg() { printf '%s\n' "[sup] $1"; } sup.err() { sup.msg "(error) $1" >&2; } sup.usage() { - echo "Usage: ${_self} [-RsF] [-D num] [file/url]" + printf '%s\n' "Usage: ${_self} [-RsF] [-D num] [file/url]" } sup.env() { @@ -34,7 +34,7 @@ sup.upload() { -F submit="" \ "$cfg_script_url" -sL -A 'zerofiles.org upload script' || { return 1; } - [[ "$flag_rm" ]] && { rm "$file"; } + (( "$flag_rm" )) && { rm "$file"; } return 0 } @@ -45,11 +45,11 @@ sup.mktemp() { return 1 } - echo "$1" + printf '%s\n' "$1" } sup.scrot() { - local tmp_file + declare tmp_file [[ "$scrot_exec" ]] || { scrot_exec=$(type -P scrot); } [[ "$scrot_exec" ]] || { @@ -57,7 +57,7 @@ sup.scrot() { return 1 } - [[ "$flag_scrot_fullscreen" ]] || { scrot_args+=( '-s' ); } + (( "$flag_scrot_fullscreen" )) || { scrot_args+=( '-s' ); } [[ "$cfg_scrot_delay" ]] && { scrot_args+=( "-d $cfg_scrot_delay" ); } tmp_file="$(sup.mktemp "${cfg_tmp_dir}" ".${cfg_screenshot_ext}")" @@ -67,18 +67,13 @@ sup.scrot() { return 1 } - echo "$tmp_file" + printf '%s\n' "$tmp_file" } -sup.exclude() { - [[ "$2" ]] && { echo "$1"; return 1; } - return 0 -} - -sup.if_url() { echo "$1" | grep -oE "$cfg_url_regex" &>/dev/null; } +sup.if_url() { printf '%s\n' "$1" | grep -oE "$cfg_url_regex" &>/dev/null; } sup.mktemp() { - local tmp_file_name tmp_file_name_extra="$2" tmp_dir="$1" + declare tmp_file_name tmp_file_name_extra="$2" tmp_dir="$1" [[ -d "$tmp_dir" ]] || { sup.err "${tmp_dir} does not exist or is not a directory." @@ -89,7 +84,7 @@ sup.mktemp() { tmp_file_name="${RANDOM}${RANDOM}${tmp_file_name_extra}" done - echo "${tmp_dir}/${tmp_file_name}" + printf '%s\n' "${tmp_dir}/${tmp_file_name}" } sup.set_argv() { @@ -128,7 +123,7 @@ sup.set_argv() { } main() { - local args file target flag_private flag_rm flag_scrot flag_scrot_fullscreen cfg_scrot_delay + declare args file target flag_private flag_rm flag_scrot flag_scrot_fullscreen cfg_scrot_delay while [[ "$1" ]]; do case "$1" in @@ -141,19 +136,24 @@ main() { -h|--help|--usage) sup.usage; return;; - --) break;; + --) shift; break;; - *) args+=( "$1" );; + *) break;; esac shift done sup.env - if [[ "$flag_scrot" ]]; then - file="$(sup.scrot)" || { return 1; } + if (( flag_scrot )); then + file=$(sup.scrot) || { return 1; } else - target="${args[0]}"; [[ "$target" ]] || { sup.usage; exit 1; } + (( $# )) || { + sup.usage + return 1 + } + + target="$1" if sup.if_url "$target"; then file=$(sup.mktemp "$cfg_tmp_dir")