Merge pull request #1037 from zsh-users/refactor-direnv

Refactoring direnv
This commit is contained in:
Shohei YOSHIDA 2023-09-05 08:43:28 +09:00 committed by GitHub
commit c23b29fff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 59 deletions

View File

@ -25,7 +25,7 @@
# Description # Description
# ----------- # -----------
# #
# Completion script for direnv (https://direnv.net/) # Completion script for direnv 2.32.3 (https://direnv.net/)
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Authors # Authors
@ -35,83 +35,86 @@
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
_commands=( (( $+functions[_direnv_commands] )) ||
'allow:Grants direnv permission to load the given .envrc or .env file.' _direnv_commands() {
'permit:Grants direnv permission to load the given .envrc or .env file.' local -a commands=(
'grant:Grants direnv permission to load the given .envrc or .env file.' 'allow:Grants direnv permission to load the given .envrc or .env file'
'block:Revokes the authorization of a given .envrc or .env file.' 'permit:Grants direnv permission to load the given .envrc or .env file'
'deny:Revokes the authorization of a given .envrc or .env file.' 'grant:Grants direnv permission to load the given .envrc or .env file'
'revoke:Revokes the authorization of a given .envrc or .env file.' 'block:Revokes the authorization of a given .envrc or .env file'
'edit:Opens PATH_TO_RC or the current .envrc or .env into an $EDITOR and allow the file to be loaded afterwards.' 'deny:Revokes the authorization of a given .envrc or .env file'
'revoke:Revokes the authorization of a given .envrc or .env file'
'edit:Opens PATH_TO_RC or the current .envrc or .env into an $EDITOR and allow the file to be loaded afterwards'
'exec:Executes a command after loading the first .envrc or .env found in DIR' 'exec:Executes a command after loading the first .envrc or .env found in DIR'
'fetchurl:Fetches a given URL into direnv''s CAS' "fetchurl:Fetches a given URL into direnv's CAS"
'help:shows this help' 'help:shows this help'
'hook:Used to setup the shell hook' 'hook:Used to setup the shell hook'
'prune:removes old allowed files' 'prune:removes old allowed files'
'reload:triggers an env reload' 'reload:triggers an env reload'
'status:prints some debug status information' 'status:prints some debug status information'
'stdlib:Displays the stdlib available in the .envrc execution context' 'stdlib:Displays the stdlib available in the .envrc execution context'
'version:prints the version or checks that direnv is older than VERSION_AT_LEAST.' 'version:prints the version or checks that direnv is older than VERSION_AT_LEAST'
) )
_direnv_commands() { _describe 'command' commands
_describe 'command' _commands
} }
_direnv() { _direnv() {
local state local curcontext="$curcontext" state line
typeset -A opt_args
local ret=1
_arguments \ _arguments -C \
'1: :_direnv_commands' \ '1: :_direnv_commands' \
'*:: :->command_args' '*:: :->command_args' && ret=0
case $state in case $state in
command_args) command_args)
case $words[1] in case $words[1] in
allow|permit|grant|block|deny|revoke|edit) (allow|permit|grant|block|deny|revoke|edit)
_arguments \ _arguments \
'1:PATH TO RC FILE:_files' \ '1:rc file:_files' \
&& ret=0
;; ;;
(exec)
exec)
_arguments \ _arguments \
'1:DIRECTORY:_files -/' \ '1:directory:_files -/' \
'2:COMMAND:_command_names' '2:command:_command_names' \
&& ret=0
;; ;;
(hook)
hook)
_arguments \ _arguments \
'1:SHELL:(bash zsh fish tcsh elvish)' '1:shell:(bash zsh fish tcsh elvish)' \
&& ret=0
;; ;;
(fetchurl)
fetchurl)
_arguments \ _arguments \
'1:URL:' \ '1:url:_urls' \
'2:INTEGRITY HASH:' '2:integrity hash' \
&& ret=0
;; ;;
(version)
prune|reload|status|stdlib)
_arguments
;;
version)
_arguments \ _arguments \
'1:VERSION:' '1:version at least' \
&& ret=0
;; ;;
(help)
help)
_arguments \ _arguments \
'1:SHOW PRIVATE:' '1:show private:(SHOW_PRIVATE)' \
&& ret=0
;; ;;
(prune|reload|status|stdlib)
*) # do not complete
_default ret=0
;;
(*)
_default && ret=0
;; ;;
esac esac
;; ;;
esac esac
return ret
} }
_direnv "$@" _direnv "$@"