Skip to content

Instantly share code, notes, and snippets.

@dardo82
Last active January 31, 2022 04:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dardo82/52799ae762e8673c8726 to your computer and use it in GitHub Desktop.
Save dardo82/52799ae762e8673c8726 to your computer and use it in GitHub Desktop.
Morse code USB light
#!/bin/zsh
# Flash a message in Morse code with an USB light
uhubctl -a 1; sleep 4.0
UHCOPTS=$(uhubctl | awk '{ text=text"\n"$0; if ($0~/hub/) text=$0; if (text~/power$/) { print text; text="" } }' \
| awk -F',| |:' -v ORS=" " '{ print $5 }' | awk '{ print "-p "$2" -l "$1 }')
uhubctl -a 0 ${=UHCOPTS}
alias dit="uhubctl -a 1 $UHCOPTS; sleep 0.1; uhubctl -a 0 $UHCOPTS"
alias dah="uhubctl -a 1 $UHCOPTS; sleep 0.6; uhubctl -a 0 $UHCOPTS"
alias sbs="sleep 0.25"
alias sbl="sleep 0.75"
eval "$(morse $1 | sed 's/\./dit;sbs;/g; s/-/dah;sbs;/g; s/ /sbl;/g' | sed 's/sbs;/& /g; s/sbs; sbl;/sbl; /g')"
unalias dit dah
unalias sbs sbl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment