From c1c5924c56ead377dd87d9b9edd60097962cd525 Mon Sep 17 00:00:00 2001 From: Carl Norum Date: Mon, 28 Nov 2022 10:50:42 -0800 Subject: [PATCH 1/2] fix device parsing If a device has fewer than 6 lines in its system profiler description, it will get merged with the following device in the egrep output. This patch changes the device splitting logic into an awk script that is more context aware about the format of the system profiler output. --- lsusb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lsusb b/lsusb index 0890c2a..e91e26c 100755 --- a/lsusb +++ b/lsusb @@ -25,6 +25,30 @@ EOM } usage () { echo "Usage: $(basename "$0") [options]..."; } +split_devices() { + awk ' \ + /Product ID:/ { \ + print TWO_BEFORE; \ + print ONE_BEFORE; \ + PRINTING=1; \ + } \ + \ + /^$/ { \ + if (PRINTING == 1) { \ + PRINTING=0; \ + print "#"; \ + } \ + } \ + \ + { \ + if (PRINTING == 1) { \ + print \ + } \ + TWO_BEFORE=ONE_BEFORE; \ + ONE_BEFORE=$0; \ + }' <<< "$rawlog" +} + parse () { # Get the name of the device, it is the first line that ends with a ':' # Trim the string at the end @@ -210,7 +234,7 @@ tree () { setup treeflag="yes" - devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'` + devices=$(split_devices) for device in $devices do # Skip null device lines @@ -282,7 +306,7 @@ setup # with the '#' symbol in case other parameters that contain a dash # will not be interfered -devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'` +devices=$(split_devices) # Iterate over each entry for device in $devices do From 5a591ccb0d9dcaeaa78f44b12d8aa08a2ea616a1 Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Wed, 15 Feb 2023 23:37:44 +0200 Subject: [PATCH 2/2] fix bus_num 000 (merged from tomtastic) --- lsusb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lsusb b/lsusb index e91e26c..4093553 100755 --- a/lsusb +++ b/lsusb @@ -4,7 +4,7 @@ # # Disclaimer: usage info and functionality from lsusb under Linux -verbose () { system_profiler SPUSBDataType; } +verbose () { system_profiler SPUSBDataType 2>/dev/null; } version () { echo "lsusb for Mac OS X 007"; } help () { cat >&2 <