Last active
January 12, 2024 18:49
-
-
Save silverweed/3cdeb241c5988cafd54fb4572e34ce1c to your computer and use it in GitHub Desktop.
Util scripts
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/lib/systemd/system/asus-kbd-backlight.service | |
[Unit] | |
Description=Asus Keyboard Backlight | |
Wants=systemd-backlight@leds:asus::kbd_backlight.service | |
After=systemd-backlight@leds:asus::kbd_backlight.service | |
[Service] | |
Type=oneshot | |
RemainAfterExit=yes | |
ExecStart=/bin/chown root:backlight /sys/class/leds/asus::kbd_backlight/brightness | |
ExecStartPost=/bin/chmod g+rw /sys/class/leds/asus::kbd_backlight/brightness | |
[Install] | |
WantedBy=multi-user.target |
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/sh | |
# Usage: backlight.sh [-inc / -dec] N | |
# If you use the .service files provided with this gist, your user should be in group `backlight`. | |
# Else, add a `sudo` before the `tee` and add a file in /etc/sudoers.d with: | |
# #user host = (root) NOPASSWD: /bin/tee | |
BASEDIR="/sys/class/backlight/intel_backlight" | |
CUR_BRIGHTNESS=`cat "$BASEDIR/brightness"` | |
MAX_BRIGHTNESS=`cat "$BASEDIR/max_brightness"` | |
if [ $# -ne 2 ]; then | |
echo "Usage: $0 [-inc / -dec] N" >&2 | |
exit 1 | |
fi | |
CHANGE=$2 | |
if ! echo $CHANGE | egrep -q '^[0-9]+$'; then | |
echo "N is not a number!" >&2 | |
exit 2 | |
fi | |
case $1 in | |
"-inc") | |
NEW_BRIGHTNESS=$((CUR_BRIGHTNESS + MAX_BRIGHTNESS / 100 * CHANGE)) | |
if ((NEW_BRIGHTNESS > MAX_BRIGHTNESS)); then | |
NEW_BRIGHTNESS=$MAX_BRIGHTNESS | |
fi | |
;; | |
"-dec") | |
NEW_BRIGHTNESS=$((CUR_BRIGHTNESS - MAX_BRIGHTNESS / 100 * CHANGE)) | |
if ((NEW_BRIGHTNESS < 0)); then | |
NEW_BRIGHTNESS=0 | |
fi | |
;; | |
*) | |
echo "Invalid option: $1" | |
exit 3 | |
;; | |
esac | |
echo $NEW_BRIGHTNESS | tee "$BASEDIR/brightness" |
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 | |
USER_NAME=$(whoami) | |
USER_ID=$(id -u "$USER_NAME") | |
HDMI_STATUS=$(</sys/class/drm/card0/*HDMI*/status) | |
export PULSE_SERVER="unix:/run/user/"$USER_ID"/pulse/native" | |
if [[ $HDMI_STATUS == connected ]] | |
then | |
sudo -u "$USER_NAME" pactl --server "$PULSE_SERVER" set-card-profile 0 output:hdmi-stereo+input:analog-stereo | |
else | |
sudo -u "$USER_NAME" pactl --server "$PULSE_SERVER" set-card-profile 0 output:analog-stereo+input:analog-stereo | |
fi |
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/lib/systemd/system/intel-backlight.service | |
[Unit] | |
Description=Intel Backlight | |
Wants=systemd-backlight@intel_backlight.service | |
After=systemd-backlight@intel_backlight.service | |
[Service] | |
Type=oneshot | |
RemainAfterExit=yes | |
ExecStart=/bin/chown root:backlight /sys/class/backlight/intel_backlight/brightness | |
ExecStartPost=/bin/chmod g+rw /sys/class/backlight/intel_backlight/brightness | |
[Install] | |
WantedBy=multi-user.target |
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/sh | |
# Usage: kbacklight.sh <inc|dec> | |
BASEDIR="/sys/class/leds/asus::kbd_backlight" | |
CUR_BRIGHTNESS=`cat "$BASEDIR/brightness"` | |
MAX_BRIGHTNESS=`cat "$BASEDIR/max_brightness"` | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <inc|dec>" >&2 | |
exit 1 | |
fi | |
CHANGE=$1 | |
case $CHANGE in | |
inc) | |
NEW_BRIGHTNESS=$((CUR_BRIGHTNESS + 1)) | |
if ((NEW_BRIGHTNESS > MAX_BRIGHTNESS)); then | |
NEW_BRIGHTNESS=$MAX_BRIGHTNESS | |
fi | |
;; | |
dec) | |
NEW_BRIGHTNESS=$((CUR_BRIGHTNESS - 1)) | |
if ((NEW_BRIGHTNESS < 0)); then | |
NEW_BRIGHTNESS=0 | |
fi | |
;; | |
*) | |
echo "Invalid option: $1" | |
exit 3 | |
;; | |
esac | |
echo $NEW_BRIGHTNESS | tee "$BASEDIR/brightness" |
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 | |
[[ $(setxkbmap -query | grep layout | grep us) ]] && setxkbmap it || setxkbmap us | |
xmodmap ~/.xmodmaprc |
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 | |
usage() { | |
>&2 echo "Usage: $0 [-l] [ap]" | |
>&2 echo " -l: scan for available AP and list them" | |
exit 1 | |
} | |
ssid_to_id() { | |
wpa_cli list_networks | grep "$1" | cut -f1 | |
} | |
connect_known() { | |
local ap_id=$1 | |
wpa_cli select_network $ap_id | |
} | |
connect_unknown() { | |
local ap_ssid="$1" | |
wpa_cli scan | |
echo Scanning... | |
sleep 3 | |
(wpa_cli scan_results | grep "$ap_ssid") || { | |
>&2 echo "AP $ap_ssid not found." | |
exit 2 | |
} | |
read -p "Psk> " -s psk | |
local new_id=$(wpa_cli add_network) | |
wpa_cli set_network $new_id ssid "$ap_ssid" | |
wpa_cli set_network $new_id psk "$psk" | |
wpa_cli select_network $new_id | |
} | |
list_networks() { | |
wpa_cli scan | |
>&2 echo Scanning... | |
sleep 3 | |
>&2 echo Scan results: | |
>&2 echo ------------- | |
>&2 echo "SSID (dB)" | |
wpa_cli scan_results | tail -n +3 | awk ' | |
{ | |
for(i = 5; i <= NF; ++i) | |
printf $(i) " " | |
print "(" $3 ")" | |
}' | |
} | |
connect_interactive() { | |
list_networks | |
read -p "Insert SSID: " ssid | |
connect_known $(ssid_to_id "$ssid") | |
} | |
if [[ $1 =~ -.* ]]; then | |
case $1 in | |
-l|--list) | |
list_networks | |
exit 0 | |
;; | |
-*) | |
usage | |
esac | |
elif [[ $# < 1 ]]; then | |
connect_interactive | |
exit $? | |
fi | |
N=$(ssid_to_id "$1") | |
[[ $N ]] && connect_known $N || connect_unknown "$*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment