Last active
May 3, 2023 23:10
-
-
Save ia/500fd5b1061fca3c7254393526d723b2 to your computer and use it in GitHub Desktop.
useful personal oneliners in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#set -e | |
#set -x | |
# generate TOC from markdown file with ## & ### titles (V2) | |
cat README.md \ | |
| grep "^##" | sed '/##.*/p;s/\(.*\)/\L\1/;s,## ,,g;s,?,,g;s, ,-,g;s,^,(#,;s,$,),' | grep -v -e "Contents$" -e "contents)$" | tr '\n' ' ' | sed 's, ##,\n##,g;s, (,](,g;s,## , * [,g;' | sed 's,^ \* , * ,g; s,^\# \* , * ,; s,(##,(#,;' | |
# generate TOC from markdown file with ## titles (V1) | |
cat README.md \ | |
| grep "^##" | sed '/##.*/p;s/\(.*\)/\L\1/;s,## ,,g;s,?,,g;s, ,-,g;s,^,(#,;s,$,),' | tr '\n' ' ' | sed 's, ##,\n##,g;s, (,](,g;s,## , * [,g;' | |
# generate udev rule for symlink to usb/serial device (last connected based on dmesg) according to the following ATTRS: idVendor, idProduct, product, manufacturer | |
# based on http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/ | |
devname="PUT THE DESIRABLE NAME FOR ALREADY CONNECTED ttyUSBN DEVICE HERE MANUALLY" # (it will be /dev/$devname) | |
dmesg | tail -20 | grep -e ".*usb.*Product: .*" -e ".*usb.*Manufacturer.*" -e "New USB device found" | sed 's/.*New USB device found, //g;s/.*Product: //g;s/.*Manufacturer: //g;s/idVendor=/SUBSYSTEM=="tty, ATTRS{idVendor}=="/;s/idProduct=/ATTRS{idProduct}=="/;s/,/",/g;s/$/",/;' | tail -3 | sed '2s/^/ATTRS{product}=="/;3s/^/ATTRS{manufacturer}=="/;3s,$, SYMLINK+="'"$devname"'",;' | tr '\n' ' ' | sed '1p;s/^/\necho '"'"'/;s,$,'"'"' >> /etc/udev/rules.d/99-usb-serial.rules \&\& udevadm control --reload-rules \&\& udevadm trigger,' | |
# just for lulz: google errors from gcc on compilation right from a terminal: | |
gcc app.c -o app 2>&1 1>/dev/null | grep "error:" | sed 's/.*error: /gcc /;s,[‘’],,g;s,^,echo -ne ",;s,$,\nq\n,' | googler -n 5 -C < /dev/stdout | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment