BIG reorganisation.

This commit is contained in:
Bartek Stalewski 2023-07-13 17:01:13 +02:00
parent 3be3ccbbea
commit e20e00ef8a
122 changed files with 36 additions and 109 deletions

2
_gui/_scripts/firefox Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
[ -n "$1" ] && flatpak run org.mozilla.firefox -P priv "$*" || flatpak run org.mozilla.firefox -P priv

17
_gui/_scripts/sb-battery Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
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")" in
"Full") status="\uf102" ;;
"Discharging") status="\uf078" ;;
"Charging") status="\uf077" ;;
"Not charging") status="\uf444"; exit 0 ;;
"Unknown") status="\uf128" ;;
esac
capacity=$(cat "$battery/capacity")
# Will make a warn variable if discharging and low
[ "$capacity" -le 20 ] && printf "<span size='140%%' background='#770000' foreground='#ffffff'>${status} ${capacity}%%</span>" || printf "${status} ${capacity}%%"
done && exit 0

8
_gui/_scripts/sb-network Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
ip a | grep -q wg0 && wg_status="wireguard running " || wg_status=""
case "$(cat /sys/class/net/wlan0/operstate 2>/dev/null)" in
down) printf "${wg_status} no wifi" ;;
up)
[ -n "$(ip address show dev wlan0 | grep 'inet ')" ] && printf "${wg_status}"|| printf "${wg_status}no ip" ;;
esac

38
_gui/_scripts/sb-volume Executable file
View file

@ -0,0 +1,38 @@
#!/bin/bash
key_micmute() {
state=$(pactl get-source-mute @DEFAULT_SOURCE@ | awk -F': ' '{print $2}')
case ${state} in
yes)
echo 0 | doas tee /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness
pactl set-source-mute @DEFAULT_SOURCE@ 0 ;;
no)
echo 1 | doas tee /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness
pactl set-source-mute @DEFAULT_SOURCE@ 1 ;;
esac
}
vol_decrease() {
pactl set-sink-volume @DEFAULT_SINK@ -5%
volume=$(pactl get-sink-volume @DEFAULT_SINK@ | head -n 1 | awk -F' / *' '{print $2}')
notify-send -t 2000 -u low "volume: $volume"
}
vol_increase() {
pactl set-sink-volume @DEFAULT_SINK@ +5%
volume=$(pactl get-sink-volume @DEFAULT_SINK@ | head -n 1 | awk -F' / *' '{print $2}')
notify-send -t 2000 -u low "volume: $volume"
}
if [ $1 ]; then
case $1 in
dec) vol_decrease ;;
inc) vol_increase ;;
key) key_micmute ;;
esac
else
mic=$(pactl get-source-volume @DEFAULT_SOURCE@ | awk -F' / ' '{print $2}' | tr -d '%')
[ $(pactl get-source-mute @DEFAULT_SOURCE@ | awk -F': ' '{print $2}') = yes ] || [ "$mic" -eq 0 ] && micmute="mic muted" || micmute=""
vol=$(pactl get-sink-volume @DEFAULT_SINK@ | awk -F' / ' '{print $2}' | tr -d '%')
[ $(pactl get-sink-mute @DEFAULT_SINK@ | awk -F': ' '{print $2}') = yes ] || [ "$vol" -eq 0 ] && printf "${micmute} audio muted" || printf "$micmute"
fi

65
_gui/_scripts/selector-audio Executable file
View file

@ -0,0 +1,65 @@
#!/bin/sh
div="---"
set_output() {
sel_sink=$(printf "$sinks\\n$div\\nback\\n$div\\nexit" | dmenu -l 20 -c -i -p "select output device")
case "$sel_sink" in
back) show_current ;;
exit) exit ;;
*) pactl set-default-sink $(pactl list sinks | grep -B 1 "$sel_sink" | awk -F': ' '/Name:/ {print $2}') ;;
esac
#kill -46 $(pidof dwmblocks)
show_current
}
set_input() {
sel_source=$(printf "$sources\\n$div\\nbluetooth profile\\n$div\\nback\\n$div\\nexit" | dmenu -l 20 -c -i -p "select input device")
case "$sel_source" in
back) show_current ;;
exit) exit ;;
bluetooth*) set_bt_profile ;;
*) pactl set-default-source "$(pactl list sources | grep -B 1 "$sel_source" | awk -F': ' '/Name:/ {print $2}')" ;;
esac
#kill -46 $(pidof dwmblocks)
show_current
}
set_bt_profile() {
bt_sink=$(pactl list cards | awk -F'"' '/device.name.*bluez/ {print $2}')
[ -z "${bt_sink}" ] &&
{ notify-send -t 2000 -u critical "ﳌ no headphones connected"; exit; }
profile_chosen=$(printf "profile mSBC\\nprofile LDAC\\n$div\\nback\\nexit" | dmenu -l 20 -c -i -p "select bluettoth profile")
case "$profile_chosen" in
back) show_current ;;
exit) exit ;;
profile*mSBC) pactl set-card-profile $bt_sink headset-head-unit-msbc
pactl set-default-source $(pactl list sources short | awk '/bluez_input/ {print $2}') ;;
profile*LDAC) pactl set-card-profile $bt_sink a2dp-sink-ldac ;;
*) show_current ;;
esac
pactl set-default
}
show_current() {
def_snk=$(pactl list | grep -A 1 "Name: $(pactl get-default-sink)\$" | awk -F': ' '/Description: / {print $2}')
def_src=$(pactl list | grep -A 1 "Name: $(pactl get-default-source)\$" | awk -F': ' '/Description: / {print $2}')
chosen=$(printf "output: $def_snk\\ninput: $def_src" | dmenu -l 20 -c -i -p "current audio devices")
if [ "$1" = "no_switch" ]; then
case "$chosen" in
*) notify-send -t 2000 -u critical "婢 no device to switch" ;;
esac
else
case "$chosen" in
output*) set_output ;;
input*) set_input ;;
esac
fi
}
sinks=$(pactl list sinks | awk -F': ' '/Description:/ {print $2}')
sources=$(pactl list sources | grep -v 'Monitor of ' | awk -F': ' '/Description:/ {print $2}')
[ "$(echo "$sinks" | wc -l)" -lt 2 ] &&
{ show_current no_switch; exit; }
show_current

299
_gui/_scripts/selector-bluetooth Executable file
View file

@ -0,0 +1,299 @@
#!/usr/bin/env bash
# __ _ _ _ _ _ _
# _ __ ___ / _(_) | |__ | |_ _ ___| |_ ___ ___ | |_| |__
# | '__/ _ \| |_| |_____| '_ \| | | | |/ _ \ __/ _ \ / _ \| __| '_ \
# | | | (_) | _| |_____| |_) | | |_| | __/ || (_) | (_) | |_| | | |
# |_| \___/|_| |_| |_.__/|_|\__,_|\___|\__\___/ \___/ \__|_| |_|
#
# Author: Nick Clyde (clydedroid)
#
# Constants
div="---"
goback="back"
# Checks if bluetooth controller is powered on
power_on() {
if bluetoothctl show | grep -q "Powered: yes"; then
return 0
else
return 1
fi
}
# Toggles power state
toggle_power() {
if power_on; then
bluetoothctl power off
show_menu
else
if rfkill list bluetooth | grep -q 'blocked: yes'; then
rfkill unblock bluetooth && sleep 3
fi
bluetoothctl power on
show_menu
fi
}
# Checks if controller is scanning for new devices
scan_on() {
if bluetoothctl show | grep -q "Discovering: yes"; then
echo "scan: on"
return 0
else
echo "scan: off"
return 1
fi
}
# Toggles scanning state
toggle_scan() {
if scan_on; then
kill $(pgrep -f "bluetoothctl scan on")
bluetoothctl scan off
show_menu
else
bluetoothctl scan on &
echo "scanning..."
sleep 5
show_menu
fi
}
# Checks if controller is able to pair to devices
pairable_on() {
if bluetoothctl show | grep -q "Pairable: yes"; then
echo "pairable: on"
return 0
else
echo "pairable: off"
return 1
fi
}
# Toggles pairable state
toggle_pairable() {
if pairable_on; then
bluetoothctl pairable off
show_menu
else
bluetoothctl pairable on
show_menu
fi
}
# Checks if controller is discoverable by other devices
discoverable_on() {
if bluetoothctl show | grep -q "Discoverable: yes"; then
echo "discoverable: on"
return 0
else
echo "discoverable: off"
return 1
fi
}
# Toggles discoverable state
toggle_discoverable() {
if discoverable_on; then
bluetoothctl discoverable off
show_menu
else
bluetoothctl discoverable on
show_menu
fi
}
# Checks if a device is connected
device_connected() {
device_info=$(bluetoothctl info "$1")
if echo "$device_info" | grep -q "Connected: yes"; then
return 0
else
return 1
fi
}
# Toggles device connection
toggle_connection() {
if device_connected $1; then
bluetoothctl disconnect $1
device_menu "$device"
else
bluetoothctl connect $1
device_menu "$device"
fi
}
# Checks if a device is paired
device_paired() {
device_info=$(bluetoothctl info "$1")
if echo "$device_info" | grep -q "Paired: yes"; then
echo "paired: yes"
return 0
else
echo "paired: no"
return 1
fi
}
# Toggles device paired state
toggle_paired() {
if device_paired $1; then
bluetoothctl remove $1
device_menu "$device"
else
bluetoothctl pair $1
device_menu "$device"
fi
}
# Checks if a device is trusted
device_trusted() {
device_info=$(bluetoothctl info "$1")
if echo "$device_info" | grep -q "Trusted: yes"; then
echo "trusted: yes"
return 0
else
echo "trusted: no"
return 1
fi
}
# Toggles device connection
toggle_trust() {
if device_trusted $1; then
bluetoothctl untrust $1
device_menu "$device"
else
bluetoothctl trust $1
device_menu "$device"
fi
}
# Prints a short string with the current bluetooth status
# Useful for status bars like polybar, etc.
print_status() {
if power_on; then
printf ''
mapfile -t paired_devices < <(bluetoothctl devices Paired | grep Device | cut -d ' ' -f 2)
counter=0
for device in "${paired_devices[@]}"; do
if device_connected $device; then
device_alias=$(bluetoothctl info $device | grep "Alias" | cut -d ' ' -f 2-)
if [ $counter -gt 0 ]; then
printf ", %s" "$device_alias"
else
printf " %s" "$device_alias"
fi
((counter++))
fi
done
printf "\n"
else
echo ""
fi
}
# A submenu for a specific device that allows connecting, pairing, and trusting
device_menu() {
device=$1
# Get device name and mac address
device_name=$(echo $device | cut -d ' ' -f 3-)
mac=$(echo $device | cut -d ' ' -f 2)
# Build options
if device_connected $mac; then
connected="connected: yes"
else
connected="connected: no"
fi
paired=$(device_paired $mac)
trusted=$(device_trusted $mac)
options="$connected\n$paired\n$trusted\n$div\n$goback\n$div\nexit"
chosen="$(echo -e "$options" | $rofi_command "$device_name")"
# Match chosen option to command
case $chosen in
"" | $div)
echo "no option chosen."
;;
$connected)
toggle_connection $mac
;;
$paired)
toggle_paired $mac
;;
$trusted)
toggle_trust $mac
;;
$goback)
show_menu
;;
esac
}
show_menu() {
# Get menu options
if power_on; then
power="power: on"
# Human-readable names of devices, one per line
# If scan is off, will only list paired devices
devices=$(bluetoothctl devices | grep Device | cut -d ' ' -f 3-)
# Get controller flags
scan=$(scan_on)
pairable=$(pairable_on)
discoverable=$(discoverable_on)
options="$devices\n$div\n$power\n$scan\n$pairable\n$discoverable\nexit"
else
power="power: off"
options="$power\nexit"
fi
chosen="$(echo -e "$options" | $rofi_command "bluetooth")"
# Match chosen option to command
case $chosen in
"" | $div)
echo "No option chosen."
;;
$power)
toggle_power
;;
$scan)
toggle_scan
;;
$discoverable)
toggle_discoverable
;;
$pairable)
toggle_pairable
;;
*)
device=$(bluetoothctl devices | grep "$chosen")
# Open a submenu if a device is selected
if [[ $device ]]; then device_menu "$device"; fi
;;
esac
}
# command to pipe into, can add any options here
rofi_command="dmenu -l 10 -c -i -p"
case "$1" in
--status)
print_status
;;
*)
show_menu
;;
esac

11
_gui/_scripts/selector-chars Executable file
View file

@ -0,0 +1,11 @@
#!/bin/sh
chosen=$(cut -d ';' -f1 $XDG_CONFIG_HOME/qtile/chars/* | dmenu -l 20 -i -p "select character to copy" | sed "s/ .*//")
[ -z "$chosen" ] && exit
if [ -n "$1" ]; then
xdotool type "$chosen"
else
printf "$chosen" | xclip -rmlastnl
notify-send -t 2000 "'$chosen' copied to clipboard" &
fi