Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smart-lock.fish ci-status sponsors MIT-img

Automatically locks or unlocks the screen based on proximity to trusted devices (Wi-Fi, Bluetooth).

preview in right prompt (light mode) preview in right prompt (dark mode)

Installation

fisher install edouard-lopez/smart-lock.fish
💡 Requirements
Tool Purpose Cinnamon
(X11)
KDE/GNOME
(Wayland)
KDE/GNOME
(X11)
Other
(X11)
icons-in-terminal nicer icons
nmcli (via NetworkManager) request network status
bluetoothctl request Bluetooth status
loginctl control lock/unlock
xprintidle get/set idle time
xset get/set X server settings
cinnamon-screensaver-command control lock/unlock

For Debian/Ubuntu-based systems (X11):

apt install network-manager bluez xprintidle x11-xserver-utils

For Fedora/RHEL-based systems with KDE/GNOME (Wayland):

dnf install NetworkManager bluez #

For Fedora/RHEL-based systems with X11:

dnf install NetworkManager bluez xorg-x11-server-utils xprintidle

What to do after installation

  • 1️⃣✅ Configure the trusted devices and idle timeout variables ;
  • 2️⃣✅ Usage = run smart_lock_toggle periodically (e.g., via systemd timer or cron) ;
  • 3️⃣✅ Display the lock status in your prompt.

1️⃣✅ Configuration

Trusted Devices & Idle Timeout

Set environment variables to define trusted devices and idle timeout.

Variable Default Description
SMART_LOCK_BSSIDS - List of trusted Wi-Fi BSSIDs as MAC addresses
e.g. home Wi-Fi, office Wi-Fi
SMART_LOCK_DEVICES_MACS - List of trusted Bluetooth as MAC addresses
e.g. smartphone, mouse)
SMART_LOCK_AFTER 180 Idle timeout in seconds

Example configuration in config.fish:

set --universal --export SMART_LOCK_BSSIDS "AA:BB:CC:DD:EE:FF" "BB:CC:DD:EE:FF:AA" 
set --universal --export SMART_LOCK_DEVICES_MACS "CC:DD:EE:FF:AA:BB"
set --universal --export SMART_LOCK_AFTER 300

2️⃣✅ Usage = run periodically

You need to run smart_lock_toggle periodically to check the proximity of trusted devices to update SMART_LOCK_STATUS and trigger screen lock and unlock the screen accordingly.

systemd Timer (Recommended)

Systemd handles environment variables and logging better than cron.

Create systemd service and timer

Create a user-level systemd timer

mkdir -p ~/.config/systemd/user/

Edit ~/.config/systemd/user/smart-lock.service

[Unit]
Description=Smart Lock Toggle Service

[Service]
Type=oneshot
ExecStart=/usr/bin/fish -c 'source $__fish_config_dir/functions/smart_lock_toggle.fish && smart_lock_toggle'

Edit ~/.config/systemd/user/smart-lock.timer

[Unit]
Description=Smart Lock Toggle Timer

[Timer]
OnBootSec=1min
OnUnitActiveSec=1min
Unit=smart-lock.service

[Install]
WantedBy=timers.target

Enable and start the timer

systemctl --user enable --now smart-lock.timer

Crontab

If you prefer cron, use the following.

ℹ️ Note that you may need to set DISPLAY and DBUS_SESSION_BUS_ADDRESS manually if they are not picked up.

# give some context to cron jobs
DISPLAY=:0
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus 
# run every minute
* * * * * fish -c 'source $__fish_config_dir/functions/smart_lock_toggle.fish && smart_lock_toggle'

3️⃣✅ Finally Prompt

Add the following to your prompt to show lock status:

echo $SMART_LOCK_STATUS

ℹ️ If you didn't customize your fish_right_prompt.fish, you can use ours:

💡 Install our fish_right_prompt
  1. Backup existing fish_right_prompt.fish:

    cp $__fish_config_dir/functions/{,__backup_}fish_right_prompt.fish
  2. Replace with smart_lock's version:

    cp $__fish_config_dir/functions/{__smart_lock_,}fish_right_prompt.fish

Debugging

You can always run it manually with Fish debugging

set fish_trace 1
smart_lock_toggle
set --erase fish_trace

About

Automatically locks or unlocks the screen based on proximity to trusted devices devices and inactivity. Similar to Android's Smart Lock feature.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages