Created
November 5, 2019 11:40
-
-
Save imaami/9a03301320d66dd0ffcd92ce3d670e54 to your computer and use it in GitHub Desktop.
Automatically launch urxvt serial consoles
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
# | |
# /etc/udev/rules.d/99-usb-serial-screen.rules | |
# | |
ACTION!="add", GOTO="usb_serial_screen_end" | |
KERNEL!="ttyUSB[0-9]*", GOTO="usb_serial_screen_end" | |
SUBSYSTEM!="tty", GOTO="usb_serial_screen_end" | |
# List of USB serial devices for which to launch a terminal | |
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GOTO="usb_serial_screen_run" | |
ATTRS{idVendor}=="0557", ATTRS{idProduct}=="2008", GOTO="usb_serial_screen_run" | |
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", GOTO="usb_serial_screen_run" | |
GOTO="usb_serial_screen_end" | |
LABEL="usb_serial_screen_run" | |
RUN+="/usr/local/bin/usb-serial-screen.sh --udev '%k' '%N' '%E{ID_MODEL_FROM_DATABASE}'" | |
LABEL="usb_serial_screen_end" |
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
#!/bin/bash | |
# | |
# /usr/local/bin/usb-serial-screen.sh | |
# | |
# Triggered by /etc/udev/rules.d/99-usb-serial-screen.rules | |
# | |
if [[ "$1" == '--udev' ]]; then | |
I3UID="$(ls -1 /run/user/*/i3/ipc-socket.*)" | |
[[ "$I3UID" ]] || exit 1 | |
I3UID=$(($(head -1 <<< "$I3UID" | cut -d/ -f4))) | |
if (( UID != I3UID )); then | |
shift | |
I3USER=$(getent passwd "$I3UID" | cut -d: -f1) | |
su -c "export DISPLAY=:0; /usr/local/bin/usb-serial-screen.sh '$1' '$2' '$3'" "$I3USER" | |
exit $? | |
fi | |
fi | |
/usr/bin/i3-msg "exec --no-startup-id /usr/bin/urxvt -title '$1: $3' -e screen -T screen.rxvt -S '$1' '$2' 115200" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment