Last active
April 29, 2024 17:04
-
-
Save rehhouari/a287b22b468fb295273b782297142bed to your computer and use it in GitHub Desktop.
Automatically lock Zellij when a certain command is executed
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
# Define an array of commands in ENV that will lock Zellij when ran | |
# export ZELLIJ_LOCK=("micro" "nano" "vim") | |
# Store the last command we ran, this is to be used in precmd() after it exists | |
command='' | |
# Run before a command is executed | |
function preexec() { | |
# Extract the command from the input string | |
local cmd=${1%% *} | |
command=$cmd | |
if [[ " ${ZELLIJ_LOCK[@]} " =~ " $cmd " ]]; then | |
zellij ac switch-mode locked | |
fi | |
} | |
# Run after a command exits | |
function precmd() { | |
if [[ " ${ZELLIJ_LOCK[@]} " =~ " $command " ]]; then | |
zellij ac switch-mode normal | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made it use env variable rather than local variable to allow more flexibility, for example defining
ZELLIJ_LOCK
inside another file like~/.zshenv