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}') sinks=$(pactl list sinks | awk -F':' '/Description:/ {print $2}')
sources=$(pactl list sources | grep -v 'Monitor of ' | awk -F':' '/Description:/ {print $2}') sources=$(pactl list sources | grep -v 'Monitor of ' | awk -F':' '/Description:/ {print $2}')
[ "$(echo "$sinks" | wc -l)" -lt 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") chosen=$(printf "output\\ninput" | dmenu -i -p "select type")
case "$chosen" in case "$chosen" in

View File

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

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
twoscreen() { 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 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") internal=$(echo "$screens" | grep -v "$external")
res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \
tail -n 1 | awk '{print $1}') tail -n 1 | awk '{print $1}')
@ -19,9 +19,9 @@ twoscreen() {
--output "$internal" --auto --same-as "$external" \ --output "$internal" --auto --same-as "$external" \
--scale "$scale_x"x"$scale_y" --scale "$scale_x"x"$scale_y"
else 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") 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 xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
fi fi
} }
@ -48,10 +48,10 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
# If there's only one screen # If there's only one screen
[ "$(echo "$screens" | wc -l)" -lt 2 ] && [ "$(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: # 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 case "$chosen" in
"home-1") home 0 ;; "home-1") home 0 ;;
"home-2") home 1 ;; "home-2") home 1 ;;