From a792094e3ef91a0606d8c367f587861ec83a606d Mon Sep 17 00:00:00 2001 From: gotbletu Date: Wed, 9 Sep 2020 00:59:48 -0700 Subject: [PATCH] usbreset-helper with fzf cli options --- usbreset-helper | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 usbreset-helper diff --git a/usbreset-helper b/usbreset-helper new file mode 100755 index 0000000..c3126a8 --- /dev/null +++ b/usbreset-helper @@ -0,0 +1,38 @@ +#!/usr/bin/env sh +# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) + +helpmsg() { + printf "%s\n" "desc: reset usb device without unplugging" + printf "%s\n" "demo: https://youtu.be/SiupVru0I1s" + printf "%s\n" "depend: usbreset (https://github.com/jkulesza/usbreset" + printf "%s\n" " (https://marc.info/?l=linux-usb&m=121459435621262&w=2)" + printf "%s\n" " (https://askubuntu.com/a/661)" + printf "%s\n" " fzf (optional)" + printf "\n" + printf "%s\n" "fzfmode: ${0##*/}" + printf "%s\n" "usage: ${0##*/} " + printf "\n" + printf "%s\n" " $ lsusb" + printf "%s\n" " Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub" + printf "%s\n" " Bus 011 Device 003: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0" + printf "%s\n" " Bus 011 Device 005: ID 04d9:2519 Holtek Semiconductor, Inc. Shenzhen LogoTech 2.4GHz receiver" + printf "\n" + printf "%s\n" " $ ${0##*/} 011 005" +} + +if [ $# -lt 1 ]; then + # fzf mode + USBHW=$(lsusb | fzf) + [ -z "$USBHW" ] && exit + BUS=$(printf "%s" "$USBHW" | awk '{print $2}') + DEVICE=$(printf "%s" "$USBHW" | awk '{print $4}' | sed 's/://g') + sudo usbreset /dev/bus/usb/"$BUS"/"$DEVICE" +elif [ $# -lt 2 ] || [ "$1" = -h ] || [ "$1" = --help ]; then + helpmsg + exit +else + # commandline mode + BUS="$1" + DEVICE="$2" + sudo usbreset /dev/bus/usb/"$BUS"/"$DEVICE" +fi