diff --git a/bin/omz b/bin/omz deleted file mode 100755 index 32d58d0d5..000000000 --- a/bin/omz +++ /dev/null @@ -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 diff --git a/bin/omz.sh b/bin/omz.sh new file mode 100755 index 000000000..1e438c767 --- /dev/null +++ b/bin/omz.sh @@ -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 diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index f3f9e49b0..7f77cca1c 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -7,7 +7,7 @@ fi # Initializes Oh My Zsh # 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 # TIP: Add files you don't want in git to .gitignore @@ -76,3 +76,4 @@ fi # Add omz command line tool export PATH="$ZSH/bin:$PATH" +alias omz="source omz.sh" diff --git a/tools/_omz.sh b/tools/_omz.sh new file mode 100644 index 000000000..f8fdd1b80 --- /dev/null +++ b/tools/_omz.sh @@ -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 diff --git a/tools/omz-plugin.sh b/tools/omz-plugin.sh new file mode 100755 index 000000000..65835aa68 --- /dev/null +++ b/tools/omz-plugin.sh @@ -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