-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock.tmux
executable file
·50 lines (41 loc) · 1.45 KB
/
lock.tmux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
# for debug
#set -x
TMUX_LOCK_CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Get the absolute path to the users configuration file of TMux.
# This includes a prioritized search on different locations.
#
get_user_tmux_conf() {
# Define the different possible locations.
xdg_location="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
default_location="$HOME/.tmux.conf"
# Search for the correct configuration file by priority.
if [ -f "$xdg_location" ]; then
echo "$xdg_location"
else
echo "$default_location"
fi
}
tmux_conf_contents() {
user_config=$(get_user_tmux_conf)
cat /etc/tmux.conf "$user_config" 2>/dev/null
}
tmux_get_option() {
local option_value
option_value="$(tmux show-options -gqv "$1")"
[[ -n $option_value ]] || option_value="$2"
echo "$option_value"
}
tmux_get_env() {
local env_value
env_value="$(tmux show-environment -g "$1" 2>/dev/null | cut -d= -f2)"
[[ -n $env_value ]] || env_value="$2"
echo "$env_value"
}
main() {
tmux set-option -g lock-after-time "$(tmux_get_option '@lock-after-time' "$(tmux_get_option 'lock-after-time')")"
tmux set-option -g lock-command "LOCK_LOGIN_TIME=$(tmux_get_option '@lock-login-time' '60') \
$TMUX_LOCK_CURRENT_DIR/scripts/lock.sh $(tmux_get_option '@lock-command' "$(tmux_get_option 'lock-command')")"
tmux bind-key "$(tmux_get_option '@lock-key' 'M-l')" lock
}
main