Util : Add _twice.

This commit is contained in:
Dmitry Voronin 2024-03-31 00:56:22 +03:00
parent 091c9e7276
commit 081a2e517a
2 changed files with 17 additions and 5 deletions

View file

@ -132,7 +132,22 @@ function _bell() {
echo -e '\a'
}
# Get users.
function _get_users() {
local users=("voronind" "dasha")
echo ${users[@]}
}
# Force the command to be called twice within the specified period in seconds. Used primarily in important keyboard shortcuts like poweroff.
# Usage: _twice <PERIOD> <COMMAND>
function _twice() {
local IFS=$'\n'
local file="/tmp/.twice"
local period=${1}
local command="${@:2}"
[[ "$(cat ${file} 2> /dev/null)" = "${command}" ]] && ${command}
echo "${command}" > "${file}"
sleep ${period}
rm "${file}" 2> /dev/null
}

View file

@ -18,8 +18,8 @@ floating_modifier $mod normal
bindsym $mod+Shift+c reload
# Exit sway (logs you out of your Wayland session).
bindsym $mod+z exec 'swaylock -F -c 000000 -k --font "SF Pro Display Medium" --font-size 14'
bindsym $mod+Shift+z exec 'swaymsg exit'
bindsym $mod+z exec '_twice 1 swaylock -F -c 000000 -k --font "SF Pro Display Medium" --font-size 14'
bindsym $mod+Shift+z exec '_twice 1 swaymsg exit'
# Show last notification.
bindsym $mod+n exec makoctl restore
@ -33,6 +33,3 @@ bindsym XF86MonBrightnessUp exec light -A 10
bindsym XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +1%'
bindsym XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -1%'
bindsym XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle'
# Lock screen
bindsym $mod+z exec 'swaylock -k -c 000000'