Skip to content

Commit

Permalink
shellcheck most scripts
Browse files Browse the repository at this point in the history
one thing left to do is unifying and standardizing the way the argument
string for the final call to termux-api is built.
  • Loading branch information
xalexalex committed Oct 25, 2019
1 parent b21388c commit ab18640
Show file tree
Hide file tree
Showing 35 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion scripts/termux-audio-info
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-battery-status
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-brightness
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if ! [[ $1 =~ ^([0-9]+)|auto$ ]]; then
show_usage
fi

if [ $1 == auto ]; then
if [ "$1" == auto ]; then
ARGS="--ez auto true"
else
ARGS="--ei brightness $1 --ez auto false"
Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-call-log
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-camera-info
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-camera-photo
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# = 0 ]; then echo "$SCRIPTNAME: missing file argument"; exit 1; fi
if [ $# != 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

touch $1
touch "$1"
PARAMS="$PARAMS --es file `realpath $1`"

/data/data/com.termux/files/usr/libexec/termux-api CameraPhoto $PARAMS
2 changes: 1 addition & 1 deletion scripts/termux-clipboard-get
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-clipboard-set
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

CMD="/data/data/com.termux/files/usr/libexec/termux-api Clipboard -e api_version 2 --ez set true"
if [ $# = 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-contact-list
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
20 changes: 10 additions & 10 deletions scripts/termux-dialog
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ list_widgets() {
echo

for w in "${widgets[@]}"; do
widget_usage $w
widget_usage "$w"
echo
done
}
Expand Down Expand Up @@ -183,14 +183,14 @@ parse_options() {
options_error () {
echo -e "ERROR: Invalid option(s) detected for '$1'\n"
echo "Usage '$1'"
widget_usage $1
widget_usage "$1"
exit 1
}

if [ $# -eq 0 ]; then
WIDGET=$DEFAULT_WIDGET
# First argument wasn't a widget
elif ! has_widget $1; then
elif ! has_widget "$1"; then
# we didn't receive a widget as an argument, check to see if we
# at least options (even if they're illegal)
if ! [[ $1 =~ -[a-z] ]]; then
Expand All @@ -211,35 +211,35 @@ case "$WIDGET" in
# Text (default) if no widget specified
"text")
if [ $((FLAGS & (RANGE_FLAG | VALUES_FLAG))) -ne 0 ]; then
options_error $WIDGET
options_error "$WIDGET"
fi

if [ $((FLAGS & MULTI_LINE_FLAG)) -ne 0 ] && [ $((FLAGS & NUM_FLAG)) -ne 0 ]; then
options_error $WIDGET
options_error "$WIDGET"
fi
;;

"confirm")
if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then
options_error $WIDGET
options_error "$WIDGET"
fi
;;

"counter")
if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then
options_error $WIDGET
options_error "$WIDGET"
fi
;;

"speech")
if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then
options_error $WIDGET
options_error "$WIDGET"
fi
;;

"date" | "time")
if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then
options_error $WIDGET
options_error "$WIDGET"
fi
;;

Expand All @@ -250,7 +250,7 @@ case "$WIDGET" in
fi

if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | NUM_FLAG))) -ne 0 ]; then
options_error $WIDGET
options_error "$WIDGET"
fi
;;

Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-download
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
Expand All @@ -34,6 +34,6 @@ URL_TO_DOWNLOAD="$1"
set --
if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi
if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
set -- "$@" $URL_TO_DOWNLOAD
set -- "$@" "$URL_TO_DOWNLOAD"

/data/data/com.termux/files/usr/libexec/termux-api Download "$@"
2 changes: 1 addition & 1 deletion scripts/termux-infrared-frequencies
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-infrared-transmit
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ -z "$FREQUENCY" ]; then echo "$SCRIPTNAME: No frequency specified"; exit 1; fi

Expand Down
6 changes: 3 additions & 3 deletions scripts/termux-location
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ while getopts :hr:p: option
do
case "$option" in
h) show_usage;;
r) validate_request $OPTARG; PARAMS="$PARAMS --es request $OPTARG";;
p) validate_provider $OPTARG; PARAMS="$PARAMS --es provider $OPTARG";;
r) validate_request "$OPTARG"; PARAMS="$PARAMS --es request $OPTARG";;
p) validate_provider "$OPTARG"; PARAMS="$PARAMS --es provider $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-media-scan
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get_paths() {
if [[ "$ARG" =~ ^/ ]]; then
echo "$ARG"
else
echo "`pwd`/$ARG"
echo "$(pwd)/$ARG"
fi
fi
done
Expand All @@ -34,7 +34,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# = 0 ]; then echo "$SCRIPTNAME: missing file argument"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-notification-list
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-notification-remove
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 1 ]; then echo "$SCRIPTNAME: no notification id specified"; exit 1; fi

/data/data/com.termux/files/usr/libexec/termux-api NotificationRemove --es id $1
/data/data/com.termux/files/usr/libexec/termux-api NotificationRemove --es id "$1"
6 changes: 3 additions & 3 deletions scripts/termux-sensor
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ set_flag () {
}

usage_error () {
echo "ERROR: $@"
echo "ERROR: $*"
show_usage
exit 1
}
Expand All @@ -92,8 +92,8 @@ do
c) set_flag $CLEANUP_FLAG; PARAMS=(-a cleanup) ;;
l) set_flag $LIST_FLAG; PARAMS=(-a list) ;;
s) set_flag $SENSOR_FLAG; get_sensors "$OPTARG"; PARAMS+=(-a sensors --es sensors "$OPTARG") ;;
d) set_flag $DELAY_FLAG; get_delay $OPTARG; PARAMS+=(--ei delay $OPTARG) ;;
n) set_flag $LIMIT_FLAG; get_limit $OPTARG; PARAMS+=(--ei limit $OPTARG) ;;
d) set_flag $DELAY_FLAG; get_delay "$OPTARG"; PARAMS+=(--ei delay "$OPTARG") ;;
n) set_flag $LIMIT_FLAG; get_limit "$OPTARG"; PARAMS+=(--ei limit "$OPTARG") ;;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-share
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ while getopts :ha:c:dt: option
do
case "$option" in
h) show_usage;;
a) validate_share $OPTARG; PARAMS="$PARAMS --es action $OPTARG";;
a) validate_share "$OPTARG"; PARAMS="$PARAMS --es action $OPTARG";;
c) PARAMS="$PARAMS --es content-type $OPTARG";;
d) PARAMS="$PARAMS --ez default-receiver true";;
t) PARAMS="$PARAMS --es title $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-sms-list
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-sms-send
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ -z "$RECIPIENTS" ]; then
echo "$SCRIPTNAME: no recipient number given"; exit 1;
Expand All @@ -28,5 +28,5 @@ CMD="/data/data/com.termux/files/usr/libexec/termux-api SmsSend $RECIPIENTS"
if [ $# = 0 ]; then
$CMD
else
echo $@ | $CMD
echo "$@" | $CMD
fi
2 changes: 1 addition & 1 deletion scripts/termux-speech-to-text
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-storage-get
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no output file specified"; exit 1; fi

/data/data/com.termux/files/usr/libexec/termux-api StorageGet --es file "`realpath "$1"`"
/data/data/com.termux/files/usr/libexec/termux-api StorageGet --es file "$(realpath "$1")"
2 changes: 1 addition & 1 deletion scripts/termux-telephony-call
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# = 1 ]; then
/data/data/com.termux/files/usr/libexec/termux-api TelephonyCall --es number "$1"
Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-telephony-cellinfo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-telephony-deviceinfo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/termux-toast
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

CMD="/data/data/com.termux/files/usr/libexec/termux-api Toast $PARAMS"

if [ $# = 0 ]; then
$CMD
else
echo $@ | $CMD
echo "$@" | $CMD
fi
4 changes: 2 additions & 2 deletions scripts/termux-torch
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fi

PARAMS=""

if [ $1 = 'on' ]; then
if [ "$1" = on ]; then
PARAMS="--ez enabled true"
elif [ $1 = 'off' ]; then
elif [ "$1" = off ]; then
PARAMS="--ez enabled false"
else
echo "Illegal parameter: $1"
Expand Down
2 changes: 1 addition & 1 deletion scripts/termux-tts-engines
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))

if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi

Expand Down
Loading

0 comments on commit ab18640

Please sign in to comment.