Consistency of dmenu scripts.

This commit is contained in:
Bartek Stalewski 2021-08-24 23:35:49 +02:00
parent 299f43a491
commit a3aff0e7e8
3 changed files with 29 additions and 29 deletions

View File

@ -15,7 +15,7 @@ set_input() {
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 ] &&
{ notify-send "🔊 Only one sink detected."; exit; }
{ notify-send "🔊 Nothing to switch to."; exit; }
chosen=$(printf "output\\ninput" | dmenu -i -p "select type")
case "$chosen" in

View File

@ -17,8 +17,8 @@
# Arch repositories: rofi, bluez-utils (contains bluetoothctl)
# Constants
divider="---------"
goback="Back"
divider="----------"
goback="back"
# Checks if bluetooth controller is powered on
power_on() {
@ -46,10 +46,10 @@ toggle_power() {
# Checks if controller is scanning for new devices
scan_on() {
if bluetoothctl show | grep -q "Discovering: yes"; then
echo "Scan: on"
echo "scan: on"
return 0
else
echo "Scan: off"
echo "scan: off"
return 1
fi
}
@ -62,7 +62,7 @@ toggle_scan() {
show_menu
else
bluetoothctl scan on &
echo "Scanning..."
echo "scanning..."
sleep 5
show_menu
fi
@ -71,10 +71,10 @@ toggle_scan() {
# Checks if controller is able to pair to devices
pairable_on() {
if bluetoothctl show | grep -q "Pairable: yes"; then
echo "Pairable: on"
echo "pairable: on"
return 0
else
echo "Pairable: off"
echo "pairable: off"
return 1
fi
}
@ -93,10 +93,10 @@ toggle_pairable() {
# Checks if controller is discoverable by other devices
discoverable_on() {
if bluetoothctl show | grep -q "Discoverable: yes"; then
echo "Discoverable: on"
echo "discoverable: on"
return 0
else
echo "Discoverable: off"
echo "discoverable: off"
return 1
fi
}
@ -137,10 +137,10 @@ toggle_connection() {
device_paired() {
device_info=$(bluetoothctl info "$1")
if echo "$device_info" | grep -q "Paired: yes"; then
echo "Paired: yes"
echo "paired: yes"
return 0
else
echo "Paired: no"
echo "paired: no"
return 1
fi
}
@ -160,10 +160,10 @@ toggle_paired() {
device_trusted() {
device_info=$(bluetoothctl info "$1")
if echo "$device_info" | grep -q "Trusted: yes"; then
echo "Trusted: yes"
echo "trusted: yes"
return 0
else
echo "Trusted: no"
echo "trusted: no"
return 1
fi
}
@ -217,13 +217,13 @@ device_menu() {
# Build options
if device_connected $mac; then
connected="Connected: yes"
connected="connected: yes"
else
connected="Connected: no"
connected="connected: no"
fi
paired=$(device_paired $mac)
trusted=$(device_trusted $mac)
options="$connected\n$paired\n$trusted\n$divider\n$goback\nExit"
options="$connected\n$paired\n$trusted\n$divider\n$goback\nexit"
# Open rofi menu, read chosen option
chosen="$(echo -e "$options" | $rofi_command "$device_name")"
@ -231,7 +231,7 @@ device_menu() {
# Match chosen option to command
case $chosen in
"" | $divider)
echo "No option chosen."
echo "no option chosen."
;;
$connected)
toggle_connection $mac
@ -252,7 +252,7 @@ device_menu() {
show_menu() {
# Get menu options
if power_on; then
power="Power: on"
power="power: on"
# Human-readable names of devices, one per line
# If scan is off, will only list paired devices
@ -264,14 +264,14 @@ show_menu() {
discoverable=$(discoverable_on)
# Options passed to rofi
options="$devices\n$divider\n$power\n$scan\n$pairable\n$discoverable\nExit"
options="$devices\n$divider\n$power\n$scan\n$pairable\n$discoverable\nexit"
else
power="Power: off"
options="$power\nExit"
power="power: off"
options="$power\nexit"
fi
# Open rofi menu, read chosen option
chosen="$(echo -e "$options" | $rofi_command "Bluetooth:")"
chosen="$(echo -e "$options" | $rofi_command "bluetooth")"
# Match chosen option to command
case $chosen in

View File

@ -1,9 +1,9 @@
#!/bin/sh
twoscreen() {
mirror=$(printf "no\\nyes" | dmenu -l 20 -i -p "Mirror displays?")
mirror=$(printf "no\\nyes" | dmenu -l 20 -i -p "mirror?")
if [ "$mirror" = "yes" ]; then
external=$(echo "$screens" | dmenu -l 20 -i -p "Optimize resolution for:")
external=$(echo "$screens" | dmenu -l 20 -i -p "optimize resolution for")
internal=$(echo "$screens" | grep -v "$external")
res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \
tail -n 1 | awk '{print $1}')
@ -19,9 +19,9 @@ twoscreen() {
--output "$internal" --auto --same-as "$external" \
--scale "$scale_x"x"$scale_y"
else
primary=$(echo "$screens" | dmenu -l 20 -i -p "Select primary display:")
primary=$(echo "$screens" | dmenu -l 20 -i -p "primary")
secondary=$(echo "$screens" | grep -v "$primary")
direction=$(printf "left\\nright" | dmenu -l 20 -i -p "What side of $primary should $secondary be on?")
direction=$(printf "left\\nright" | dmenu -l 20 -i -p "what side of $primary should $secondary be on?")
xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
fi
}
@ -48,10 +48,10 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
# If there's only one screen
[ "$(echo "$screens" | wc -l)" -lt 2 ] &&
{ onescreen "$screens"; postrun; notify-send "💻 Only one screen detected."; exit ;}
{ onescreen "$screens"; postrun; notify-send "💻 Nothing to switch to."; exit ;}
# Get user choice including both and manual selection:
chosen=$(printf -- "home-1\\nhome-2\\n----\\n%s\\n----\\nmulti" "$screens" | dmenu -l 20 -i -p "Select display:") &&
chosen=$(printf -- "home-1\\nhome-2\\n----\\n%s\\n----\\nmulti" "$screens" | dmenu -l 20 -i -p "display") &&
case "$chosen" in
"home-1") home 0 ;;
"home-2") home 1 ;;