mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-02 02:19:06 +01:00
omz tool to dynamically load plugins
This commit is contained in:
parent
42d1ae029c
commit
b326820004
5 changed files with 100 additions and 41 deletions
40
bin/omz
40
bin/omz
|
|
@ -1,40 +0,0 @@
|
||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
STATUS=0
|
|
||||||
|
|
||||||
function omz_usage() {
|
|
||||||
echo "OH MY ZSH! command line tool"
|
|
||||||
echo " theme choose your theme"
|
|
||||||
echo " upgrade upgrade OH MY ZSH"
|
|
||||||
echo " uninstall remove OH MY ZSH :("
|
|
||||||
echo " help show this help"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case $1 in
|
|
||||||
|
|
||||||
theme )
|
|
||||||
zsh $ZSH/tools/theme_chooser.sh
|
|
||||||
;;
|
|
||||||
|
|
||||||
upgrade )
|
|
||||||
zsh $ZSH/tools/upgrade.sh
|
|
||||||
;;
|
|
||||||
|
|
||||||
uninstall )
|
|
||||||
echo "Are you sure?"
|
|
||||||
zsh $ZSH/tools/uninstall.sh
|
|
||||||
;;
|
|
||||||
|
|
||||||
help )
|
|
||||||
omz_usage
|
|
||||||
;;
|
|
||||||
|
|
||||||
* )
|
|
||||||
omz_usage
|
|
||||||
STATUS=1
|
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
|
||||||
|
|
||||||
exit $STATUS
|
|
||||||
41
bin/omz.sh
Executable file
41
bin/omz.sh
Executable file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
function omz_usage() {
|
||||||
|
echo "OH MY ZSH! command line tool. Available commands:"
|
||||||
|
echo " plugin NAME Enable plugin specified by NAME"
|
||||||
|
echo " theme Choose theme"
|
||||||
|
echo " upgrade Upgrade OH MY ZSH!"
|
||||||
|
echo " uninstall Remove OH MY ZSH! :("
|
||||||
|
echo " help Show this help"
|
||||||
|
}
|
||||||
|
|
||||||
|
COMMAND=$1
|
||||||
|
|
||||||
|
case $COMMAND in
|
||||||
|
|
||||||
|
plugin )
|
||||||
|
shift 1
|
||||||
|
source $ZSH/tools/omz-plugin.sh $@
|
||||||
|
;;
|
||||||
|
|
||||||
|
theme )
|
||||||
|
zsh $ZSH/tools/theme_chooser.sh
|
||||||
|
;;
|
||||||
|
|
||||||
|
upgrade )
|
||||||
|
zsh $ZSH/tools/upgrade.sh
|
||||||
|
;;
|
||||||
|
|
||||||
|
uninstall )
|
||||||
|
zsh $ZSH/tools/uninstall.sh
|
||||||
|
;;
|
||||||
|
|
||||||
|
help )
|
||||||
|
omz_usage
|
||||||
|
;;
|
||||||
|
|
||||||
|
* )
|
||||||
|
omz_usage
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
@ -7,7 +7,7 @@ fi
|
||||||
# Initializes Oh My Zsh
|
# Initializes Oh My Zsh
|
||||||
|
|
||||||
# add a function path
|
# add a function path
|
||||||
fpath=($ZSH/functions $ZSH/completions $fpath)
|
fpath=($ZSH/tools $fpath)
|
||||||
|
|
||||||
# Load all of the config files in ~/oh-my-zsh that end in .zsh
|
# Load all of the config files in ~/oh-my-zsh that end in .zsh
|
||||||
# TIP: Add files you don't want in git to .gitignore
|
# TIP: Add files you don't want in git to .gitignore
|
||||||
|
|
@ -76,3 +76,4 @@ fi
|
||||||
|
|
||||||
# Add omz command line tool
|
# Add omz command line tool
|
||||||
export PATH="$ZSH/bin:$PATH"
|
export PATH="$ZSH/bin:$PATH"
|
||||||
|
alias omz="source omz.sh"
|
||||||
|
|
|
||||||
38
tools/_omz.sh
Normal file
38
tools/_omz.sh
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#compdef omz.sh
|
||||||
|
#autoload
|
||||||
|
|
||||||
|
_omz_all_plugins() {
|
||||||
|
plugins=(`ls $ZSH/plugins`)
|
||||||
|
}
|
||||||
|
|
||||||
|
local -a _1st_arguments
|
||||||
|
_1st_arguments=(
|
||||||
|
'plugin:Enable plugin'
|
||||||
|
'theme:Choose theme'
|
||||||
|
'upgrade:Upgrade OH MY ZSH!'
|
||||||
|
'uninstall:Remove OH MY ZSH! :('
|
||||||
|
)
|
||||||
|
|
||||||
|
local expl
|
||||||
|
local -a plugins all_plugins
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
'*:: :->subcmds' && return 0
|
||||||
|
|
||||||
|
if (( CURRENT == 1 )); then
|
||||||
|
_describe -t commands "omz.sh subcommand" _1st_arguments
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$words[1]" in
|
||||||
|
plugin )
|
||||||
|
_arguments \
|
||||||
|
'1: :->name' && return 0
|
||||||
|
|
||||||
|
if [[ "$state" == name ]]; then
|
||||||
|
_omz_all_plugins
|
||||||
|
_wanted plugins expl 'all plugins' compadd -a plugins
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
19
tools/omz-plugin.sh
Executable file
19
tools/omz-plugin.sh
Executable file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Load plugin passed as first arg
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
PLUGIN="$ZSH/plugins/$1"
|
||||||
|
|
||||||
|
if [ -d $PLUGIN ]; then
|
||||||
|
fpath=($PLUGIN $fpath)
|
||||||
|
source $PLUGIN/*.plugin.zsh
|
||||||
|
autoload -U compinit
|
||||||
|
compinit -i
|
||||||
|
echo "$1 enabled!"
|
||||||
|
else
|
||||||
|
echo "Plugin '$1' not found!"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Please specify a plugin"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue