Last active
October 18, 2017 15:36
-
-
Save xenithorb/a7542d7458fbca00bfa5c5891cd3fb39 to your computer and use it in GitHub Desktop.
Add the missing autolock functionality back to keepass on Linux.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
AUTOLOCK_MIN=10 # Minutes to wait before locking keepass | |
LOCK_CMD='keepass --lock-all' | |
declare -A IDLE_TIME_COMMANDS | |
IDLE_TIME_COMMANDS=( | |
["KDE"]="qdbus org.kde.screensaver /ScreenSaver GetSessionIdleTime" | |
) | |
xautolock_cmd() { | |
if command -v xautolock > /dev/null; then | |
xautolock -time "$AUTOLOCK_MIN" -secure -locker "$LOCK_CMD" \ | |
-noclose -resetsaver -detectsleep | |
else | |
echo 'Please install `xautolock`' | |
fi | |
} | |
check_idle_loop() { | |
local is_idle time_command idle_time | |
eval time_command="\${IDLE_TIME_COMMANDS[$1]}" | |
until pkill -0 -f "KeePass.exe"; do | |
sleep 30 | |
done | |
while :; do | |
idle_time="$($time_command)" | |
if (( idle_time >= AUTOLOCK_MIN*60000 && is_idle == 0 )); then | |
${LOCK_CMD} && | |
is_idle=1 | |
elif (( idle_time < AUTOLOCK_MIN*60000 && is_idle == 1 )); then | |
is_idle=0 | |
fi | |
sleep 15 | |
done | |
} | |
case "${XDG_CURRENT_DESKTOP^^}" in | |
KDE*) check_idle_loop KDE;; | |
*) xautolock_cmd;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment