Instantly share code, notes, and snippets.

Embed
What would you like to do?
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