aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-06-16 18:33:27 +0200
committerPhilip Wittamore <philip@wittamore.com>2025-06-16 18:33:27 +0200
commitce2d80f5c5104c31950a30eac0a6a86ba71c3163 (patch)
tree48417c3b848ae7f3808fbb1d43bb521a8115960f
parent00e2a2f919bb26ca1493ca2842dd7af1791ae587 (diff)
downloadscripts-ce2d80f5c5104c31950a30eac0a6a86ba71c3163.tar.gz
scripts-ce2d80f5c5104c31950a30eac0a6a86ba71c3163.tar.bz2
scripts-ce2d80f5c5104c31950a30eac0a6a86ba71c3163.zip
update
-rwxr-xr-xdmenu-audio6
-rwxr-xr-xdmenu-bluetooth412
-rwxr-xr-xdmenu-calendar9
-rwxr-xr-xdmenu-connect61
-rwxr-xr-xdmenu-emoji5
-rwxr-xr-xdmenu-musicpick6
-rwxr-xr-xdmenu-playmusic23
-rwxr-xr-xdmenu-power14
-rwxr-xr-xdmenu-settings9
-rwxr-xr-xdmenu-system11
10 files changed, 544 insertions, 12 deletions
diff --git a/dmenu-audio b/dmenu-audio
index 85bed40..ab3dc82 100755
--- a/dmenu-audio
+++ b/dmenu-audio
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
-choices=" Connect BT headset\n󰂲 Disconnect BT headset\n󰓃 Select Output\n󰍬 Select Input\n󰝚 Playlists\n󰐎 Pause/Play Music\n Radio\n✘ Exit"
+choices=" Connect BT headset\n󰂲 Disconnect BT headset\n󰓃 Select Output\n󰍬 Select Input\n󰝚 Playlists\n󰐎 Pause/Play Music\n📻 Radio\n✘ Exit"
-result=$(echo -e $choices | dmenu -bw 4 -c -i -l 8 -p "Audio")
+result=$(echo -e $choices | dmenu -bw 4 -c -i -z 500 -l 8 -p "Audio")
case $result in
@@ -52,7 +52,7 @@ case $result in
exit 0
;;
- " Radio")
+ "📻 Radio")
st -e pyradio
exit 0
;;
diff --git a/dmenu-bluetooth b/dmenu-bluetooth
new file mode 100755
index 0000000..c1a2f2c
--- /dev/null
+++ b/dmenu-bluetooth
@@ -0,0 +1,412 @@
+#!/usr/bin/env bash
+# _ _ _ _ _ _
+# __| |_ __ ___ ___ _ __ _ _ | |__ | |_ _ ___| |_ ___ ___ | |_ | |__
+# / _` | '_ ` _ \ / _ \ '_ \| | | |_____| '_ \| | | | |/ _ \ __/ _ \ / _ \| __|| '_ \
+# | (_| | | | | | | __/ | | | |_| |_____| |_) | | |_| | __/ || (_) | (_) | |_ | | | |
+# \__,_|_| |_| |_|\___|_| |_|\__,_| |_.__/|_|\__,_|\___|\__\___/ \___/ \__||_| |_|
+#
+# Author: Nick Clyde (clydedroid)
+# dmenu support by: Layerex
+# Original script: https://github.com/nickclyde/rofi-bluetooth
+#
+# A script that generates a dmenu menu that uses bluetoothctl to
+# connect to bluetooth devices and display status info.
+#
+# Inspired by networkmanager-dmenu (https://github.com/firecat53/networkmanager-dmenu)
+# Thanks to x70b1 (https://github.com/polybar/polybar-scripts/tree/master/polybar-scripts/system-bluetooth-bluetoothctl)
+#
+# Depends on:
+# Arch repositories: dmenu, bluez-utils (contains bluetoothctl)
+
+# Constants
+divider="---------"
+goback="Back"
+exit="Exit"
+connected_icon=""
+
+# 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 "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() {
+ if bluetoothctl info "$1" | 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() {
+ if bluetoothctl info "$1" | 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() {
+ if bluetoothctl info "$1" | 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\n$exit"
+
+ # Open dmenu menu, read chosen option
+ chosen="$(echo -e "$options" | run_dmenu "$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 dmenu 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
+ if [[ -n "$connected_icon" ]]; then
+ devices="$(bluetoothctl devices | grep -F Device | while read -r device; do
+ device_name="$(echo "$device" | cut -d ' ' -f 3-)"
+ mac="$(echo "$device" | cut -d ' ' -f 2)"
+ icon=""
+
+ if device_connected "$mac" && [[ -n $connected_icon ]]; then
+ icon=" $connected_icon"
+ fi
+
+ echo "$device_name${icon}"
+ done)"
+ else
+ devices="$(bluetoothctl devices | grep -F Device | cut -d ' ' -f 3-)"
+ fi
+
+ # Get controller flags
+ scan="$(scan_on)"
+ pairable="$(pairable_on)"
+ discoverable="$(discoverable_on)"
+
+ # Options passed to dmenu
+ [[ -n $devices ]] && devices_part="$devices\n$divider\n"
+ options="$devices_part$power\n$scan\n$pairable\n$discoverable\n$exit"
+ else
+ power="Power: off"
+ options="$power\n$exit"
+ fi
+
+ # Open dmenu menu, read chosen option
+ chosen="$(echo -e "$options" | run_dmenu "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
+ ;;
+ *)
+ if [[ -n "$connected_icon" ]]; then
+ chosen="${chosen%% ${connected_icon}}"
+ fi
+ device="$(bluetoothctl devices | grep -F "$chosen")"
+ # Open a submenu if a device is selected
+ if [[ -n "$device" ]]; then device_menu "$device"; fi
+ ;;
+ esac
+}
+
+# dmenu command to pipe into. Extra arguments to dmenu-bluetooth are passed through to dmenu. This
+# allows the user to set fonts, sizes, colours, etc.
+DMENU_BLUETOOTH_LAUNCHER="${DMENU_BLUETOOTH_LAUNCHER:-dmenu}"
+run_dmenu() {
+ case "$DMENU_BLUETOOTH_LAUNCHER" in
+ rofi)
+ DMENU_BLUETOOTH_LAUNCHER="rofi -dmenu"
+ ;;
+ fuzzel)
+ DMENU_BLUETOOTH_LAUNCHER="fuzzel --dmenu"
+ ;;
+ esac
+ $DMENU_BLUETOOTH_LAUNCHER -i -c -bw 4 -z 500 -l 10 -p "$DMENU_BLUETOOTH_PROMPT" "${dmenu_args[@]}"
+}
+
+print_help() {
+ echo "usage: $0 [--help] [--status] [--connected-icon [ICON]] [PROMPT] DMENU_ARGS..."
+ echo ""
+ echo "A script that generates a dmenu menu that uses bluetoothctl to connect to bluetooth devices and display status info."
+ echo ""
+ echo "positional arguments:"
+ echo " PROMPT dmenu prompt"
+ echo " DMENU_ARGS... arguments passed to dmenu"
+ echo ""
+ echo "options:"
+ echo "--help show this help message and exit"
+ echo "--status print a short string about current bluetooth status and exit"
+ echo "--connected-icon [ICON] add icon on device list next to connected devices"
+ echo ""
+ echo "environment variables:"
+ echo " DMENU_BLUETOOTH_PROMPT dmenu prompt"
+ echo " DMENU_BLUETOOTH_LAUNCHER command to use instead of 'dmenu'"
+ echo ""
+ echo "Positional arguments have to be placed after all other arguments."
+ echo "A PROMPT positional argument will be interpreted as part of DMENU_ARGS if it starts with '-'. It won't be parsed if the DMENU_BLUETOOTH_PROMPT environment variable is set."
+ echo "Use the DMENU_BLUETOOTH_LAUNCHER environment variable to use launchers other than dmenu. Rofi, fuzzel, and any dmenu-compatible launchers are supported."
+}
+
+command_present() {
+ command -v "$1" >/dev/null 2>&1
+}
+
+error() {
+ echo "$1. $2." >&2
+ command_present notify-send && notify-send "$1" "$2."
+}
+
+# Check if bluetooth daemon is running. Start it if possible.
+if command_present systemctl; then
+ systemctl is-active --quiet bluetooth
+ case $? in
+ 3)
+ error "Bluetooth daemon is not running" "Start it to use this script"
+ systemctl start bluetooth || exit 3
+ ;;
+ 4)
+ error "Bluetooth daemon is not present" "On Arch Linux install bluez and bluez-utils packages"
+ exit 4
+ ;;
+ esac
+fi
+
+dmenu_args=("$@")
+case "$1" in
+ --help)
+ print_help
+ exit
+ ;;
+ --status)
+ print_status
+ exit
+ ;;
+ --connected-icon)
+ if [[ "$2" == "--" ]]; then
+ connected_icon=""
+ else
+ connected_icon="$2"
+ fi
+ dmenu_args=("${dmenu_args[@]:2}")
+ ;;
+esac
+case "${dmenu_args[0]}" in
+ -*)
+ ;;
+ *)
+ if [[ -z "$DMENU_BLUETOOTH_PROMPT" ]]; then
+ DMENU_BLUETOOTH_PROMPT="${dmenu_args[0]}"
+ dmenu_args=("${dmenu_args[@]:1}")
+ fi
+ ;;
+esac
+
+show_menu
diff --git a/dmenu-calendar b/dmenu-calendar
new file mode 100755
index 0000000..9bad4ea
--- /dev/null
+++ b/dmenu-calendar
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+
+# Start
+DAY=$(date +'%e')
+
+dunstify 'Calendar' "$(cal | sed -e "s/$DAY\b/<u>$DAY<\/u>/g")"
+
+exit 0
diff --git a/dmenu-connect b/dmenu-connect
new file mode 100755
index 0000000..64194f9
--- /dev/null
+++ b/dmenu-connect
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+
+# generic connection manager
+
+# Bluetooth headset on Thinkpad X220
+# bt controller 60:D8:19:AE:22:77 is the default
+# bt controller 48:51:B7:EB:7B:B5 is removed in udev
+
+headset="E8:07:BF:3C:5F:65"
+microphone="alsa_input.usb-MUSIC-BOOST_USB_Microphone_MB-306-00.mono-fallback"
+
+choices="Connect BT Headset\nDisconnect BT Headset\nConnect USB Micro\nConnect rnnoise filter\nExit menu"
+
+selected=$(echo -e $choices | dmenu -c -i -z 500 -l 5 -p "Connector")
+
+#echo $selected
+
+case $selected in
+
+ "Connect BT Headset")
+ bluetoothctl connect $headset &> /dev/null
+ sleep 1
+ defsink=$(pactl get-default-sink)
+ dunstify -t 5000 -a "BT Headset" -u low -i media-removable-symbolic \
+ -h string:x-dunst-stack-tag:bt-headset "Default sink = $defsink"
+ ;;
+
+ "Disconnect BT Headset")
+ bluetoothctl disconnect $headset &> /dev/null
+ sleep 1
+ defsink=$(pactl get-default-sink)
+ dunstify -t 5000 -a "BT Headset" -u low -i media-removable-symbolic \
+ -h string:x-dunst-stack-tag:bt-headset "Default sink = $defsink"
+ ;;
+
+ "Connect USB Micro")
+ pactl set-default-source $microphone &> /dev/null
+ sleep 1
+ defsource=$(pactl get-default-source)
+ dunstify -t 5000 -a "Microphone" -u low -i media-removable-symbolic \
+ -h string:x-dunst-stack-tag:usb-microphone "Default source = $defsource"
+ ;;
+
+ "Connect rnnoise filter")
+ pactl set-default-source "rnnoise_source" &> /dev/null
+ sleep 1
+ defsource=$(pactl get-default-source)
+ dunstify -t 5000 -a "Microphone" -u low -i media-removable-symbolic \
+ -h string:x-dunst-stack-tag:usb-microphone "Default source = $defsource"
+ ;;
+
+ "Exit menu")
+ exit 0
+ ;;
+
+ *)
+ ;;
+esac
+
+
+
diff --git a/dmenu-emoji b/dmenu-emoji
new file mode 100755
index 0000000..536a355
--- /dev/null
+++ b/dmenu-emoji
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+grep -v "#" $HOME/.local/bin/emoji_list | dmenu -i -z 800 -bw 4 -c -l 20 | awk '{print $1}' | tr -d '\n' | xclip -selection clipboard
+
+pgrep -x dunst >/dev/null && notify-send "$(xclip -o -selection clipboard) Copied!"
diff --git a/dmenu-musicpick b/dmenu-musicpick
new file mode 100755
index 0000000..f960ca4
--- /dev/null
+++ b/dmenu-musicpick
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+# relative path to mpd's music directory *must* be used. absolute path will not be read by mpd.
+cd ~/Music
+
+file="$(mpc listall | dmenu -i -l 1)" || exit 0
+notify-send "Playing $file" && mpc insert "$file" && mpc next >/dev/null
diff --git a/dmenu-playmusic b/dmenu-playmusic
new file mode 100755
index 0000000..38031a3
--- /dev/null
+++ b/dmenu-playmusic
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+music_path="$HOME/Music"
+
+cd $music_path
+
+music_file="$(find *.m3u -maxdepth 0 -type f | sort)\nExit"
+
+result=$(echo -e "$music_file" | dmenu -bw 4 -c -i -z 500 -l 5 -p 'Play Music')
+
+case $result in
+ "Exit")
+ cd $HOME
+ exit 0
+ ;;
+ *)
+ [ -z $result ] || mpv --playlist="$HOME/Music/$result"
+ echo $result
+ cd $HOME
+ exit 0
+ ;;
+esac
+
diff --git a/dmenu-power b/dmenu-power
index 0dbab39..74a4a42 100755
--- a/dmenu-power
+++ b/dmenu-power
@@ -1,11 +1,17 @@
#!/bin/sh
-choice=$(echo -e " Shutdown\n Reboot\n Logout\n Lock\n Theme\n✘ Exit" | dmenu -bw 4 -c -l 6 -p "Power: ")
+choice=$(echo -e "\
+ Logout\n\
+ Lock\n\
+ Shutdown\n\
+ Reboot\n\
+✘ Exit" | dmenu -bw 4 -c -z 500 -l 6 -p "Power: ")
+
case "$choice" in
- " Shutdown") shutdown -h now ;;
- " Reboot") reboot ;;
" Logout") pkill -u $USER ;;
- " Lock") slock;;
+ " Lock") slock;;
+ " Shutdown") sudo /sbin/poweroff ;;
+ " Reboot") sudo /sbin/reboot ;;
" Exit") exit 0 ;;
*) exit 1;;
esac
diff --git a/dmenu-settings b/dmenu-settings
new file mode 100755
index 0000000..027dba3
--- /dev/null
+++ b/dmenu-settings
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+choice=$(echo -e " Theme\n󰞅 Emojis\n✘ Exit" | dmenu -bw 4 -c -z 500 -l 6 -p "Settings: ")
+case "$choice" in
+ " Theme") choose-theme;;
+ "󰞅 Emojis") dmenu-emoji;;
+ " Exit") exit 0 ;;
+ *) exit 1;;
+esac
diff --git a/dmenu-system b/dmenu-system
index f1b71ac..1ed4edb 100755
--- a/dmenu-system
+++ b/dmenu-system
@@ -1,10 +1,11 @@
#!/bin/sh
-choice=$(echo -e " Theme\n Bluetooth\n Network\n✘ Exit" | dmenu -bw 4 -c -l 6 -p "System: ")
+choice=$(echo -e " Settings\n Bluetooth\n Network\n󰖩 Wifi\n✘ Exit" | dmenu -bw 4 -c -z 500 -l 6 -p "System: ")
case "$choice" in
- " Theme") choose-theme;;
- " Bluetooth") bluetui;;
- " Network") st -e nmtui;;
- " Exit") exit 0 ;;
+ " Settings") dmenu-settings;;
+ " Bluetooth") dmenu-bluetooth;;
+ " Network") st -e nmtui;;
+ "󰖩 Wifi") st -e wavemon;;
+ " Exit") exit 0 ;;
*) exit 1;;
esac