Last active
July 26, 2024 11:50
-
-
Save sgviking/3be0c3b05d5bb4fd429a to your computer and use it in GitHub Desktop.
Script for Lenevo Carbon X1 gen 2 to prepare for docking and undocking from One Link Pro Dock
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 | |
ethernet="enp0s20u3u1u3" | |
wireless_network="wlp3s0-syn-ack-5GHz" | |
monitor_left="DP1" | |
monitor_right="DP2-3" | |
monitor_laptop="eDP1" | |
status() { | |
level=$1 | |
message=$2 | |
echo "[${level}] $(date +"%Y-%m-%d %T") - ${message}" | |
} | |
dockon() { | |
all=$1 | |
status INFO "Preparing laptop for use on One Link Pro dock." | |
status INFO "Turn on monitor attached to mini-display port." | |
xrandr --output $monitor_left --auto 1>/dev/null | |
status INFO "Turn off laptop screen." | |
xrandr --output $monitor_laptop --off 1>/dev/null | |
status INFO "Turn on monitor attached to DVI on dock." | |
xrandr --output $monitor_right --auto --right-of $monitor_left 1>/dev/null | |
[ "$all" == "all" ] && \ | |
xrandr --output $monitor_laptop --auto --right-of $monitor_right 1>/dev/null | |
status INFO "Pull DHCP address for ethernet port on dock." | |
sudo dhcpcd $ethernet 1>/dev/null | |
status INFO "Turn off wireless internet." | |
sudo netctl stop-all 1>/dev/null | |
exit 0 | |
} | |
dockoff() { | |
status INFO "Preparing laptop to unplug from One Link Pro dock." | |
status INFO "Turn on laptop screen." | |
xrandr --output $monitor_laptop --auto 1>/dev/null | |
status INFO "Turn off monitor attached to mini-display port." | |
xrandr --output $monitor_left --off 1>/dev/null | |
status INFO "Turn off monitor attached to DVI on dock." | |
xrandr --output $monitor_right --off 1>/dev/null | |
status INFO "Release DHCP address for ethernet port on dock." | |
sudo dhcpcd -k $ethernet 1>/dev/null | |
status INFO "Connect to home wireless internet." | |
sudo netctl start $wireless_network 1>/dev/null | |
exit 0 | |
} | |
case "$1" in | |
on) | |
# Turns on two external monitors and turns laptop monitor off | |
dockon | |
;; | |
onall) | |
# Turns on two external monitors and sets laptop monitor to the right | |
dockon all | |
;; | |
off) | |
dockoff | |
;; | |
*) | |
status FATAL "Usage: $0 <on|onall|off>" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment