bin: add wmenu subdir
This commit is contained in:
parent
84a35d9fb8
commit
76f3d5bd91
5 changed files with 346 additions and 0 deletions
10
.local/bin/wmenu/grimpick
Executable file
10
.local/bin/wmenu/grimpick
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
output="$(date '+%y%m%d-%H%M-%S').png"
|
||||||
|
|
||||||
|
case "$(printf "a selected area\\nfull screen\\na selected area (copy)\\nfull screen (copy)" | wmenu -l 4 -i -p "Screenshot which area?")" in
|
||||||
|
"a selected area") grim -g "$(slurp)" pic-selected-"${output}" ;;
|
||||||
|
"full screen") grim pic-full-"${output}" ;;
|
||||||
|
"a selected area (copy)") grim -g "$(slurp)" | wl-copy ;;
|
||||||
|
"full screen (copy)") grim - | wl-copy ;;
|
||||||
|
esac
|
5
.local/bin/wmenu/prompt
Executable file
5
.local/bin/wmenu/prompt
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# A wmenu binary prompt script.
|
||||||
|
|
||||||
|
[ "$(printf "No\\nYes" | wmenu -i -p "$1" )" = "Yes" ] && $2
|
12
.local/bin/wmenu/sysact
Executable file
12
.local/bin/wmenu/sysact
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
shut)
|
||||||
|
prompt "Shutdown computer?" "doas poweroff" ;;
|
||||||
|
reb)
|
||||||
|
prompt "Reboot computer?" "doas reboot" ;;
|
||||||
|
rest)
|
||||||
|
prompt "Leave dwl?" "kill -TERM $(pgrep -u $USER "\bdwl$")" ;;
|
||||||
|
lock)
|
||||||
|
dpms-off; swaylock -c 000000 ; mpc pause
|
||||||
|
esac
|
300
.local/bin/wmenu/wm-bluetooth
Executable file
300
.local/bin/wmenu/wm-bluetooth
Executable file
|
@ -0,0 +1,300 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
divider="---------"
|
||||||
|
goback="Back"
|
||||||
|
|
||||||
|
# Checks if bluetooth controller is powered on
|
||||||
|
power_on() {
|
||||||
|
if bluetoothctl show | grep -F -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 -F -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 -F -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 -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 -F -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 -F -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 -F -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 -F -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 -F -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 paired-devices | grep -F Device | cut -d ' ' -f 2)
|
||||||
|
counter=0
|
||||||
|
|
||||||
|
for device in "${paired_devices[@]}"; do
|
||||||
|
if device_connected "$device"; then
|
||||||
|
device_alias="$(bluetoothctl info "$device" | grep -F "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$divider\n$goback\nExit"
|
||||||
|
|
||||||
|
# Open wmenu menu, read chosen option
|
||||||
|
chosen="$(echo -e "$options" | run_wmenu "$device_name")"
|
||||||
|
|
||||||
|
# Match chosen option to command
|
||||||
|
case $chosen in
|
||||||
|
"" | "$divider")
|
||||||
|
echo "No option chosen."
|
||||||
|
;;
|
||||||
|
"$connected")
|
||||||
|
toggle_connection "$mac"
|
||||||
|
;;
|
||||||
|
"$paired")
|
||||||
|
toggle_paired "$mac"
|
||||||
|
;;
|
||||||
|
"$trusted")
|
||||||
|
toggle_trust "$mac"
|
||||||
|
;;
|
||||||
|
"$goback")
|
||||||
|
show_menu
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Opens a wmenu menu with current bluetooth status and options to connect
|
||||||
|
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 -F Device | cut -d ' ' -f 3-)
|
||||||
|
|
||||||
|
# Get controller flags
|
||||||
|
scan=$(scan_on)
|
||||||
|
pairable=$(pairable_on)
|
||||||
|
discoverable=$(discoverable_on)
|
||||||
|
|
||||||
|
# Options passed to wmenu
|
||||||
|
options="$devices\n$divider\n$power\n$scan\n$pairable\n$discoverable\nExit"
|
||||||
|
else
|
||||||
|
power="Power: off"
|
||||||
|
options="$power\nExit"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Open wmenu menu, read chosen option
|
||||||
|
chosen="$(echo -e "$options" | run_wmenu "Bluetooth")"
|
||||||
|
|
||||||
|
# Match chosen option to command
|
||||||
|
case $chosen in
|
||||||
|
"" | "$divider")
|
||||||
|
echo "No option chosen."
|
||||||
|
;;
|
||||||
|
"$power")
|
||||||
|
toggle_power
|
||||||
|
;;
|
||||||
|
"$scan")
|
||||||
|
toggle_scan
|
||||||
|
;;
|
||||||
|
"$discoverable")
|
||||||
|
toggle_discoverable
|
||||||
|
;;
|
||||||
|
"$pairable")
|
||||||
|
toggle_pairable
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
device=$(bluetoothctl devices | grep -F "$chosen")
|
||||||
|
# Open a submenu if a device is selected
|
||||||
|
if [[ $device ]]; then device_menu "$device"; fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
original_args=("$@")
|
||||||
|
|
||||||
|
# wmenu command to pipe into. Extra arguments to wmenu-bluetooth are passed through to wmenu. This
|
||||||
|
# allows the user to set fonts, sizes, colours, etc.
|
||||||
|
run_wmenu() {
|
||||||
|
wmenu "${original_args[@]}" -i -p "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
--status)
|
||||||
|
print_status
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
show_menu
|
||||||
|
;;
|
||||||
|
esac
|
19
.local/bin/wmenu/wm-handler
Executable file
19
.local/bin/wmenu/wm-handler
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Feed this script a link and it will give dmenu
|
||||||
|
# some choice programs to use to open it.
|
||||||
|
feed="${1:-$(printf "%s" | wmenu -p 'Paste URL or file path')}"
|
||||||
|
|
||||||
|
case "$(printf "yt-dlp\\nyt-dlp (audio)\\nyt-dlp (music)\\ncurl\\nmpv (audio)\\nmpv (float)\\nmpv (loop)\\nzathura\\nsxiv\\nnvim\\nbrowser" | wmenu -i -p "Handle it with?")" in
|
||||||
|
"yt-dlp") qndl "$feed" >/dev/null 2>&1 ;;
|
||||||
|
"yt-dlp (audio)") qndl "$feed" 'yt-dlp -f bestaudio/best -icx --embed-metadata' >/dev/null 2>&1 ;;
|
||||||
|
"yt-dlp (music)") qndl "$feed" 'yt-dlp -f bestaudio/best -icx --embed-metadata --no-playlist --audio-format mp3 -o $XDG_MUSIC_DIR/%(title)s.%(ext)s' >/dev/null 2>&1 ;;
|
||||||
|
"curl") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;;
|
||||||
|
"mpv (audio)") setsid -f "$TERMINAL" -e mpv --quiet --no-video "$feed" >/dev/null 2>&1 ;;
|
||||||
|
"mpv (float)") setsid -f mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$feed" >/dev/null 2>&1 ;;
|
||||||
|
"mpv (loop)") setsid -f mpv -quiet --loop "$feed" >/dev/null 2>&1 ;;
|
||||||
|
zathura) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
|
||||||
|
sxiv) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
|
||||||
|
vim) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;;
|
||||||
|
browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1
|
||||||
|
esac
|
Loading…
Reference in a new issue