Browse Source

Better argument handling; cleanup

master
Jack L. Frost 7 years ago
parent
commit
71f6a3e256
  1. 58
      sup

58
sup

@ -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
}
@ -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}")"
@ -92,32 +92,43 @@ sup.mktemp() {
echo "${tmp_dir}/${tmp_file_name}"
}
sup.getopt() {
local keys
set_argv() {
declare arg opt c
declare -g argv
for i in "$@"; do
case "$i" in
--*) echo "$i";;
while (( $# )); do
unset -v arg opt c
-*)
keys=( $(echo "${i##*-}" | fold -w1) )
case "$1" in
(--) argv+=( "$1" ); break;;
(--*)
IFS='=' read arg opt <<< "$1"
argv+=( "$arg" )
if [[ "${#keys[@]}" -gt 1 ]]; then
for k in "${keys[@]}"; do
echo "-${k}"
done
else
echo "$i"
fi
[[ "$opt" ]] && {
argv+=( "$opt" )
}
;;
*) echo "$i";;
(-*)
while read -n1 c
do
case "$c" in
-|'') :;;
*) argv+=( "-$c" );;
esac
done <<< "$1"
;;
(*) argv+=( "$1" );;
esac
shift
done
}
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
@ -130,19 +141,19 @@ main() {
-h|--help|--usage) sup.usage; return;;
--) break;;
--) shift; break;;
*) args+=( "$1" );;
*) break;;
esac
shift
done
sup.env
if [[ "$flag_scrot" ]]; then
if (( flag_scrot )); then
file="$(sup.scrot)" || { return 1; }
else
target="${args[0]}"; [[ "$target" ]] || { sup.usage; exit 1; }
target="$1"; [[ "$target" ]] || { sup.usage; exit 1; }
if sup.if_url "$target"; then
file=$(sup.mktemp "$cfg_tmp_dir")
@ -159,4 +170,5 @@ main() {
sup.upload
}
main $(sup.getopt "$@")
set_argv "$@"
main "${argv[@]}"

Loading…
Cancel
Save