Skip to content

Commit

Permalink
Fix Always Display Output (#19)
Browse files Browse the repository at this point in the history
* Fix Always Display Output

Signed-off-by: LanikSJ <[email protected]>

* Bump Version

Signed-off-by: LanikSJ <[email protected]>

---------

Signed-off-by: LanikSJ <[email protected]>
  • Loading branch information
LanikSJ authored Dec 10, 2023
1 parent 49055ab commit fa29a6a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lsusb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ shopt -s extglob

verbose() {
system_profiler SPUSBDataType 2>/dev/null

# Restore the IFS and exit
cleanup
}

version() {
echo "lsusb for macOS 1.1.2"
echo "lsusb for macOS 1.1.3"
}

help() {
Expand All @@ -32,6 +35,9 @@ List USB devices
-V Show version of program
-h Show usage and help
EOM

# Restore the IFS and exit
cleanup
}

usage() {
Expand Down Expand Up @@ -121,7 +127,7 @@ parse() {
esac
fi

if [ ${#bus_num} -ne 0 ]; then
if [ ${#bus_num} != 0 ]; then
# Convert bus number from hexadecimal to decimal.
bus_num=$(printf "%03d" "0x0$bus_num")
else
Expand Down Expand Up @@ -149,51 +155,55 @@ parse() {
# Filter by VID/PID if given as input argument.
if [ -n "$vid_pid" ]; then
# Convert input vid to lower case.
# shellcheck disable=SC2143
if [ -n "$(echo "$vid_pid" | grep ':')" ]; then
arg_vid=$(echo "$vid_pid" | awk -F':' '{print $1}' | sed 's/^0x//' | tr '[:upper:]' '[:lower:]')
if [ -n "$arg_vid" ]; then
if [ $((16#$arg_vid)) -ne $((16#$VID)) ]; then
if [ $((16#$arg_vid)) != $((16#$VID)) ]; then
return 1
fi
fi
arg_pid=$(echo "$vid_pid" | awk -F':' '{print $2}' | sed 's/^0x//' | tr '[:upper:]' '[:lower:]')
if [ -n "$arg_pid" ]; then
if [ $((16#$arg_pid)) -ne $((16#$PID)) ]; then
if [ $((16#$arg_pid)) != $((16#$PID)) ]; then
return 1
fi
fi
else
# Missing a colon is a syntax error in -d option
help
# shellcheck disable=SC2317
exit 1
fi
fi

# Filter by BUS/DEV if given as input argument.
if [ -n "$bus_dev" ]; then
# shellcheck disable=SC2143
if [ -n "$(echo "$bus_dev" | grep ':')" ]; then
# Convert input bus to lower case
arg_bus=$(echo "$bus_dev" | awk -F':' '{print $1}' | sed 's/^ *//; s/ *$//')
if [ -n "$arg_bus" ]; then
if [ "$arg_bus" -ne "$bus_num" ]; then
if [ "$arg_bus" != "$bus_num" ]; then
return 1
fi
fi
# Strip leading and trailing spaces from argument.
arg_dev=$(echo "$bus_dev" | awk -F':' '{print $2}' | sed 's/^ *//; s/ *$//')
if [ -n "$arg_dev" ]; then
if [ "$arg_dev" -ne "$device_num" ]; then
if [ "$arg_dev" != "$device_num" ]; then
return 1
fi
fi
fi
fi
# Special case: no colon after -s means device-only.
# shellcheck disable=SC2143
if [ -z "$(echo "$bus_dev" | grep ':')" ]; then
# Strip leading and trailing spaces from argument.
arg_dev=$(echo "$bus_dev" | sed 's/^ *//; s/ *$//')
if [ -n "$arg_dev" ]; then
if [ "$arg_dev" -ne "$device_num" ]; then
if [ "$arg_dev" != "$device_num" ]; then
return 1
fi
fi
Expand Down Expand Up @@ -222,6 +232,7 @@ setup() {

cleanup() {
IFS=$OIFS
# shellcheck disable=SC2086
exit $exitcode
}

Expand Down Expand Up @@ -260,7 +271,7 @@ tree() {

for device in $(get_devices); do
# Skip null device lines
if [ "${#device}" -ne 1 ]; then
if [ "${#device}" != 1 ]; then
parse
buildtreeline
treedata="$treedata""${treeline}"$'\n'
Expand Down

0 comments on commit fa29a6a

Please sign in to comment.