From ce485f155cf2acaf1e9944a71ee09937f32fdf23 Mon Sep 17 00:00:00 2001 From: "Thomas D. Spear" Date: Mon, 27 Jan 2025 13:42:19 -0600 Subject: [PATCH] feat(direnv-p10k): Add a new plugin for direnv which specifically disables the precmd_functions hook for powerlevel10k theme users to avoid the instant prompt warning when starting a shell in a directory where a .envrc is both located and `direnv allow`ed Signed-off-by: Thomas D. Spear --- plugins/direnv-p10k/README.md | 17 +++++++++++++++++ plugins/direnv-p10k/direnv-p10k.plugin.zsh | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 plugins/direnv-p10k/README.md create mode 100644 plugins/direnv-p10k/direnv-p10k.plugin.zsh diff --git a/plugins/direnv-p10k/README.md b/plugins/direnv-p10k/README.md new file mode 100644 index 000000000..0ed2d0e98 --- /dev/null +++ b/plugins/direnv-p10k/README.md @@ -0,0 +1,17 @@ +# direnv plugin + +This plugin creates the [Direnv](https://direnv.net/) hook. + +This hook is tweaked to prevent issues with the powerlevel10k theme's instant prompt feature by not adding the direnv hook to precmd_functions + +To use it, add `direnv-p10k` to the plugins array in your zshrc file: + +```zsh +plugins=(... direnv-p10k) +``` + +## Requirements + +In order to make this work, you will need to have direnv installed. + +More info on the usage and install: https://github.com/direnv/direnv diff --git a/plugins/direnv-p10k/direnv-p10k.plugin.zsh b/plugins/direnv-p10k/direnv-p10k.plugin.zsh new file mode 100644 index 000000000..ec24b64fb --- /dev/null +++ b/plugins/direnv-p10k/direnv-p10k.plugin.zsh @@ -0,0 +1,15 @@ +# If direnv is not found, don't continue and print a warning +if (( ! $+commands[direnv] )); then + echo "Warning: direnv not found. Please install direnv and ensure it's in your PATH before using this plugin." + return +fi + +_direnv_hook() { + trap -- '' SIGINT; + eval "$(direnv export zsh)"; + trap - SIGINT; +} +typeset -ag chpwd_functions; +if [[ -z "${chpwd_functions[(r)_direnv_hook]+1}" ]]; then + chpwd_functions=( _direnv_hook ${chpwd_functions[@]} ) +fi