mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-28 00:30:07 +00:00
fix(cli): allow omz
commands to be used in a script (#10645)
The commands `omz plugin {enable,disable}` and `omz theme set` automatically reload the zsh session on success. With this change, the CLI checks whether the commands are run in an interactive session before reloading the zsh session. This change also conditionally sets the completion function for `omz` so that it's not done in a non-interactive session.
This commit is contained in:
parent
4ee0cf3cb4
commit
e1a9d0ce3e
1 changed files with 10 additions and 13 deletions
23
lib/cli.zsh
23
lib/cli.zsh
|
@ -105,7 +105,10 @@ function _omz {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
compdef _omz omz
|
# If run from a script, do not set the completion function
|
||||||
|
if (( ${+functions[compdef]} )); then
|
||||||
|
compdef _omz omz
|
||||||
|
fi
|
||||||
|
|
||||||
## Utility functions
|
## Utility functions
|
||||||
|
|
||||||
|
@ -299,10 +302,8 @@ multi == 1 && length(\$0) > 0 {
|
||||||
# Restart the zsh session if there were no errors
|
# Restart the zsh session if there were no errors
|
||||||
_omz::log info "plugins disabled: ${(j:, :)dis_plugins}."
|
_omz::log info "plugins disabled: ${(j:, :)dis_plugins}."
|
||||||
|
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
# Only reload zsh if run in an interactive session
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
[[ ! -o interactive ]] || _omz::reload
|
||||||
# Check whether to run a login shell
|
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::plugin::enable {
|
function _omz::plugin::enable {
|
||||||
|
@ -375,10 +376,8 @@ multi == 1 && /^[^#]*\)/ {
|
||||||
# Restart the zsh session if there were no errors
|
# Restart the zsh session if there were no errors
|
||||||
_omz::log info "plugins enabled: ${(j:, :)add_plugins}."
|
_omz::log info "plugins enabled: ${(j:, :)add_plugins}."
|
||||||
|
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
# Only reload zsh if run in an interactive session
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
[[ ! -o interactive ]] || _omz::reload
|
||||||
# Check whether to run a login shell
|
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::plugin::info {
|
function _omz::plugin::info {
|
||||||
|
@ -731,10 +730,8 @@ EOF
|
||||||
# Restart the zsh session if there were no errors
|
# Restart the zsh session if there were no errors
|
||||||
_omz::log info "'$1' theme set correctly."
|
_omz::log info "'$1' theme set correctly."
|
||||||
|
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
# Only reload zsh if run in an interactive session
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
[[ ! -o interactive ]] || _omz::reload
|
||||||
# Check whether to run a login shell
|
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::theme::use {
|
function _omz::theme::use {
|
||||||
|
|
Loading…
Reference in a new issue