Skip to content

Commit 7531d57

Browse files
committed
termux-usb: add option to open device based on vendor and productId
1 parent 3154dfd commit 7531d57

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

scripts/termux-usb.in

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e -u
33

44
SCRIPTNAME=termux-usb
55
show_usage () {
6-
echo "Usage: $SCRIPTNAME [-l | [-r] [-E] [-e command] [device]"
6+
echo "Usage: $SCRIPTNAME [-l | [-r] [-E] [-e command] [device | vendorId productId]]"
77
echo "List or access USB devices. Devices cannot be accessed directly,"
88
echo " only using $SCRIPTNAME."
99
echo " -l list available devices"
@@ -35,9 +35,20 @@ if [ "$ACTION" == "list" ]
3535
then
3636
if [ $# -gt 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
3737
else
38-
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
39-
if [ $# -lt 1 ]; then echo "$SCRIPTNAME: missing -l or device path"; exit 1; fi
40-
PARAMS="$PARAMS --es device $1"
38+
if [ $# -lt 1 ]; then
39+
echo "$SCRIPTNAME: missing -l or device path"
40+
exit 1
41+
elif [ $# -eq 1 ]; then
42+
# The device's usbfs path has been provided
43+
PARAMS="$PARAMS --es device $1"
44+
elif [ $# -eq 2 ]; then
45+
# A vendorId and ProductId of the device has been provided
46+
PARAMS="$PARAMS --es vendorId $1"
47+
PARAMS="$PARAMS --es productId $2"
48+
else
49+
echo "$SCRIPTNAME: too many arguments"
50+
exit 1
51+
fi
4152
fi
4253

4354
CMD="@TERMUX_PREFIX@/libexec/termux-api Usb -a $ACTION $PARAMS"

0 commit comments

Comments
 (0)