diff options
Diffstat (limited to 'local')
| -rw-r--r-- | local/bin/README.txt | 10 | ||||
| -rwxr-xr-x | local/bin/audio_control.sh | 28 | ||||
| -rwxr-xr-x | local/bin/brightness_control.sh | 17 | ||||
| -rwxr-xr-x | local/bin/input_control.sh | 62 | ||||
| -rwxr-xr-x | local/bin/network_control.sh | 23 | ||||
| -rwxr-xr-x | local/bin/sb-audio | 30 | ||||
| -rwxr-xr-x | local/bin/sb-battery | 37 | ||||
| -rwxr-xr-x | local/bin/sb-input | 9 | ||||
| -rwxr-xr-x | local/bin/setup_default_apps.sh (renamed from local/bin/setup-default-apps.sh) | 0 |
9 files changed, 215 insertions, 1 deletions
diff --git a/local/bin/README.txt b/local/bin/README.txt index b9207a4..094a5b3 100644 --- a/local/bin/README.txt +++ b/local/bin/README.txt @@ -1,7 +1,15 @@ My Linux executable scripts. -Notes: +NOTES * Beware of not leaking personal information I also use other people's awesome scrips. I store them in `~/code` and then slink the ones I use in `~/.local/bin`. + +NOTATION +* All scripts here should end in ".sh" +* `laptop-*` scripts might only work on my current machine +* `sb-*` scripts are meant to be called by dwmblocks + See also: + https://github.com/LukeSmithxyz/voidrice/tree/master/.local/bin/statusbar + https://github.com/LukeSmithxyz/dwmblocks/blob/master/config.h diff --git a/local/bin/audio_control.sh b/local/bin/audio_control.sh new file mode 100755 index 0000000..516721a --- /dev/null +++ b/local/bin/audio_control.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +delta=${2:-10} +signal=10 + +# signal dwmblocks to update volume block +send_signal() { + pkill -RTMIN+$signal dwmblocks +} + +case $1 in + inc) pactl set-sink-volume @DEFAULT_SINK@ +$delta% ;; + dec) pactl set-sink-volume @DEFAULT_SINK@ -$delta% ;; + mutetoggle) pactl set-sink-mute @DEFAULT_SINK@ toggle ;; + deafentoggle) pactl set-source-mute @DEFAULT_SOURCE@ toggle ;; + *) + echo Speaker: + pactl get-sink-volume @DEFAULT_SINK@ + pactl get-sink-mute @DEFAULT_SINK@ + echo -e "\nMic:" + pactl get-source-volume @DEFAULT_SOURCE@ + pactl get-source-mute @DEFAULT_SOURCE@ + echo -e "\nApplications:" + pactl list sink-inputs | grep -e 'Sink Input' -e 'application.name' -e 'Volume:' + ;; +esac + +send_signal diff --git a/local/bin/brightness_control.sh b/local/bin/brightness_control.sh new file mode 100755 index 0000000..13345d7 --- /dev/null +++ b/local/bin/brightness_control.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +delta=${2:-10} +signal=11 + +# signal dwmblocks to update block +send_signal() { + pkill -RTMIN+$signal dwmblocks +} + +case $1 in + inc) xbacklight -inc $delta ;; + dec) xbacklight -dec $delta ;; + *) xbacklight -get ;; +esac + +send_signal diff --git a/local/bin/input_control.sh b/local/bin/input_control.sh new file mode 100755 index 0000000..05bc1cb --- /dev/null +++ b/local/bin/input_control.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Use either X keyboard extension layouts (setxkbmap), or fcitx (or both). +# +# At first I configured this to use setxkbmap, it works fine. +# +# fcitx already provides keybindings, but I wanted to display +# the current input method in dwmblocks immediatly. So I'm +# adding such support through fcitx5-remote. + +signal=20 + +# signal dwmblocks to update block +send_signal() { + pkill -RTMIN+$signal dwmblocks +} + +# Cycle X keyboard extension layouts +cycle_layouts() { + layouts=(us latam) # X keyboard extension + STATE_FILE="$XDG_STATE_HOME/keyboard_layout_state" + + if [ -f "$STATE_FILE" ]; then + index=$(cat "$STATE_FILE") + else + index=0 + fi + next_index=$(( (index + 1) % ${#layouts[@]} )) + echo $next_index > "$STATE_FILE" + + setxkbmap ${layouts[$index]} +} + +fcitx_control() { + # For this to correctly reflect the state of the system "Share Input State" + # should be set to "All" in fcitx5-configtool. + + case $1 in + en) + fcitx5-remote -g Default + fcitx5-remote -c # Closed + ;; + es) + fcitx5-remote -g Spanish + fcitx5-remote -c # Closed + ;; + ja) + fcitx5-remote -g Default + fcitx5-remote -o # Open + ;; + *) + fcitx5-remote -q # + fcitx5-remote -n + fcitx5-remote + ;; + esac +} + +#cycle_layouts +fcitx_control $1 + +send_signal diff --git a/local/bin/network_control.sh b/local/bin/network_control.sh new file mode 100755 index 0000000..381cbec --- /dev/null +++ b/local/bin/network_control.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +signal=30 + +# signal dwmblocks to update volume block +send_signal() { + pkill -RTMIN+$signal dwmblocks +} + +case $1 in + inc) pactl set-sink-volume @DEFAULT_SINK@ +$delta% ;; + dec) pactl set-sink-volume @DEFAULT_SINK@ -$delta% ;; + mutetoggle) pactl set-sink-mute @DEFAULT_SINK@ toggle ;; + deafentoggle) pactl set-source-mute @DEFAULT_SOURCE@ toggle ;; + *) + echo Wifi: + echo -e "\nBluetooth:" + bluetoothctl show + echo -e "\nEthernet:" + ;; +esac + +send_signal diff --git a/local/bin/sb-audio b/local/bin/sb-audio new file mode 100755 index 0000000..6258869 --- /dev/null +++ b/local/bin/sb-audio @@ -0,0 +1,30 @@ +#!/bin/sh + +# Prints the current volume and 🔇 if muted. + +case $BLOCK_BUTTON in + 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" ;; + 2) wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;; + 4) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+ ;; + 5) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%- ;; + 3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted. +- Middle click to mute. +- Scroll to change." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +#vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)" + +vol="$(pactl get-sink-volume @DEFAULT_SINK@ | awk '/Volume/ { gsub(/%/,"",$5); print $5 }')" + +case 1 in + $((vol >= 70)) ) icon="🔊" ;; + $((vol >= 30)) ) icon="🔉" ;; + * ) icon="🔈" ;; +esac + +if pactl get-sink-mute @DEFAULT_SINK@ | grep -q yes; then + icon="🔇" +fi + +echo "$icon$vol%" diff --git a/local/bin/sb-battery b/local/bin/sb-battery new file mode 100755 index 0000000..93cbe08 --- /dev/null +++ b/local/bin/sb-battery @@ -0,0 +1,37 @@ +#!/bin/sh + +# Prints all batteries, their percentage remaining and an emoji corresponding +# to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.). + +case $BLOCK_BUTTON in + 3) notify-send "🔋 Battery module" "🔋: discharging +🛑: not charging +♻: stagnant charge +🔌: charging +⚡: charged +❗: battery very low! +- Scroll to change adjust xbacklight." ;; + 4) xbacklight -inc 10 ;; + 5) xbacklight -dec 10 ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# Loop through all attached batteries and format the info +for battery in /sys/class/power_supply/BAT?*; do + # If non-first battery, print a space separator. + [ -n "${capacity+x}" ] && printf " " + # Sets up the status and capacity + case "$(cat "$battery/status" 2>&1)" in + "Full") status="⚡" ;; + "Discharging") status="🔋" ;; + "Charging") status="🔌" ;; + "Not charging") status="🛑" ;; + "Unknown") status="♻️" ;; + *) exit 1 ;; + esac + capacity="$(cat "$battery/capacity" 2>&1)" + # Will make a warn variable if discharging and low + [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗" + # Prints the info + printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn +done && printf "\\n" diff --git a/local/bin/sb-input b/local/bin/sb-input new file mode 100755 index 0000000..4fb1575 --- /dev/null +++ b/local/bin/sb-input @@ -0,0 +1,9 @@ +#!/bin/bash + +icon="🌐" +layout="$(setxkbmap -query | grep layout | awk '{print $2}')" + +# fcitx state, 0 for close, 1 for inactive, 2 for active +test $(fcitx5-remote) = 2 && layout="日本語" + +echo $icon$layout diff --git a/local/bin/setup-default-apps.sh b/local/bin/setup_default_apps.sh index 809824f..809824f 100755 --- a/local/bin/setup-default-apps.sh +++ b/local/bin/setup_default_apps.sh |
