Skip to content

Instantly share code, notes, and snippets.

@adrolter
Last active March 10, 2016 09:24
Show Gist options
  • Save adrolter/e623432a86cee298ef49 to your computer and use it in GitHub Desktop.
Save adrolter/e623432a86cee298ef49 to your computer and use it in GitHub Desktop.
lsusb with vendor and product strings for BusyBox 1.2x
unalias lsusb &>/dev/null; lsusb() {
/usr/bin/lsusb "$@" | awk 'BEGIN { idexpr="[[:xdigit:]]{4}"; vexpr="^"idexpr"[[:space:]]+"; pexpr="^\t"idexpr"[[:space:]]+"
while (("curl -sS http://www.linux-usb.org/usb.ids") | getline) {
if($0 == "# List of known device classes, subclasses and protocols") {break}
else if(lastv == "" && substr($1, 0, 1) == "#") {continue}
else if(lastv != "" && $0 ~ pexpr) {lastp=$1; sub(pexpr, ""); r[lastv, lastp]=$0}
else if($0 ~ vexpr) {lastv=$1; sub(vexpr, ""); r[lastv]=$0}
}
}
"ID "idexpr":"idexpr"$" {split($6, id, ":"); printf "%s %s %s\n", $0, r[id[1]], (r[id[1], id[2]])}'
}
alias lsusb='/usr/bin/lsusb|awk '\''BEGIN{ie="[[:xdigit:]]{4}";ve="^"ie"[[:space:]]+";pe="^\t"ie"[[:space:]]+";while(("curl -sS http://www.linux-usb.org/usb.ids")|getline)if($0=="# List of known device classes, subclasses and protocols"){break}else if(lv==""&&substr($1,0,1)=="#"){continue}else if(lv!=""&&$0~pe){lp=$1;sub(pe,"");r[lv,lp]=$0}else if($0~ve){lv=$1;sub(ve,"");r[lv]=$0}}"ID "ie":"ie"$"{split($6,id,":");printf "%s %s %s\n",$0,r[id[1]],r[id[1],id[2]]}'\'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment