Update powermenu to use hyprctl
This commit is contained in:
parent
0278f0a7bc
commit
121eebc2b2
|
@ -76,21 +76,21 @@ function check_launcher() {
|
|||
# Get array with unique elements and preferred launcher first
|
||||
# Note: uniq expects a sorted list, so we cannot use it
|
||||
i=1
|
||||
launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \
|
||||
| sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' '))
|
||||
launcher_list=("$(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \
|
||||
| sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')")
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse CLI arguments
|
||||
while getopts "hcp:" option; do
|
||||
case "${option}" in
|
||||
h) echo "${usage}"
|
||||
case "$option" in
|
||||
h) echo "$usage"
|
||||
exit 0
|
||||
;;
|
||||
c) enable_confirmation=true
|
||||
;;
|
||||
p) preferred_launcher="${OPTARG}"
|
||||
check_launcher "${preferred_launcher}"
|
||||
p) preferred_launcher="$OPTARG"
|
||||
check_launcher "$preferred_launcher"
|
||||
;;
|
||||
*) exit 1
|
||||
;;
|
||||
|
@ -117,8 +117,8 @@ menu=(
|
|||
[ Reboot]="systemctl reboot"
|
||||
[ Suspend]="systemctl suspend"
|
||||
[ Hibernate]="systemctl hibernate"
|
||||
[ Lock]="swaymsg exec swaylock"
|
||||
[ Logout]="swaymsg exit"
|
||||
[ Lock]="hyprctl dispatch exec swaylock"
|
||||
[ Logout]="hyprctl dispatch exit"
|
||||
[ Cancel]=""
|
||||
)
|
||||
|
||||
|
@ -133,53 +133,53 @@ rofi_colors=""
|
|||
|
||||
function prepare_launcher() {
|
||||
if [[ "$1" == "rofi" ]]; then
|
||||
rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \
|
||||
-hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}")
|
||||
rofi_colors=(-bc "$BORDER_COLOR" -bg "$BG_COLOR" -fg "$FG_COLOR" \
|
||||
-hlfg "$HLFG_COLOR" -hlbg "$HLBG_COLOR")
|
||||
launcher_exe="rofi"
|
||||
launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \
|
||||
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
|
||||
launcher_options=(-dmenu -i -lines "$menu_nrows" -p "$ROFI_TEXT" \
|
||||
"$rofi_colors" "${ROFI_OPTIONS[@]}")
|
||||
elif [[ "$1" == "zenity" ]]; then
|
||||
launcher_exe="zenity"
|
||||
launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \
|
||||
launcher_options=(--list --title="$ZENITY_TITLE" --text="$ZENITY_TEXT" \
|
||||
"${ZENITY_OPTIONS[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
for l in "${launcher_list[@]}"; do
|
||||
if command_exists "${l}" ; then
|
||||
prepare_launcher "${l}"
|
||||
if command_exists "$l" ; then
|
||||
prepare_launcher "$l"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# No launcher available
|
||||
if [[ -z "${launcher_exe}" ]]; then
|
||||
if [[ -z "$launcher_exe" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
launcher=(${launcher_exe} "${launcher_options[@]}")
|
||||
launcher=("$launcher_exe" "${launcher_options[@]}")
|
||||
selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")"
|
||||
|
||||
function ask_confirmation() {
|
||||
if [ "${launcher_exe}" == "rofi" ]; then
|
||||
if [ "$launcher_exe" == "rofi" ]; then
|
||||
confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \
|
||||
"${rofi_colors}" "${ROFI_OPTIONS[@]}")
|
||||
[ "${confirmed}" == "Yes" ] && confirmed=0
|
||||
elif [ "${launcher_exe}" == "zenity" ]; then
|
||||
"$rofi_colors" "${ROFI_OPTIONS[@]}")
|
||||
[ "$confirmed" == "Yes" ] && confirmed=0
|
||||
elif [ "$launcher_exe" == "zenity" ]; then
|
||||
zenity --question --text "Are you sure you want to ${selection,,}?"
|
||||
confirmed=$?
|
||||
fi
|
||||
|
||||
if [ "${confirmed}" == 0 ]; then
|
||||
${menu[${selection}]}
|
||||
if [ "$confirmed" == 0 ]; then
|
||||
"${menu[${selection}]}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $? -eq 0 && ! -z ${selection} ]]; then
|
||||
if [[ "${enable_confirmation}" = true && \
|
||||
${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then
|
||||
if [[ "$enable_confirmation" = true && \
|
||||
${menu_confirm} =~ (^|[[:space:]])"$selection"($|[[:space:]]) ]]; then
|
||||
ask_confirmation
|
||||
else
|
||||
${menu[${selection}]}
|
||||
"${menu[${selection}]}"
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue