# Add to your `.zshrc` file or use the function's contents as a script. # # With the former, add the function, restart your terminal, connect # a USB serial device, eg. a Raspberry Pi Pico, and then enter `dlist` # at the command line. # # You should see something like this: # `/dev/cu.usbserial-01AB8E0B` # # If you have only one device attached, you can include the function's # output in other command line call. For example: # # `pyboard -d $(dlist) -f cp prefs.json :prefs.json` # # If you have multiple devices attached, `dlist` will list them all: # # `1. /dev/cu.usbmodem1101 # 2. /dev/cu.usbserial-01AB8E0B` # # You can then specify a single device by number. For example: # # `pyboard -d $(dlist 2) -f cp prefs.json :prefs.json` # # NOTE Requires macOS dlist() { local devices=($(/bin/ls /dev/cu.usb* 2>/dev/null)) if [[ ${#devices} -gt 0 ]]; then if [[ ${#devices} -eq 1 ]]; then echo ${devices} else local count=1 for device in ${devices}; do if [[ -n "$1" && "$1" == "$count" ]]; then echo ${device} elif [[ -z "$1" ]]; then echo "${count}. ${device}" fi ((count+=1)) done fi fi }