diff --git a/bin/omz.sh b/bin/omz.sh new file mode 100755 index 000000000..2ecf81a51 --- /dev/null +++ b/bin/omz.sh @@ -0,0 +1,37 @@ +#!/bin/zsh + +function omz_usage() { + echo "Oh My Zsh command line tool. Available commands:" + echo " plugin Manage plugins" + echo " theme_chooser Preview themes" + echo " upgrade Upgrade Oh My Zsh" + echo " uninstall Remove Oh My Zsh :(" + echo " help Show this help" +} + + +OMZ_COMMAND=$1 +case $OMZ_COMMAND in + + '' | help ) + omz_usage + ;; + + plugin ) + shift 1 + source $ZSH/tools/$OMZ_COMMAND.sh $@ + ;; + + * ) + shift 1 + if [ -x $ZSH/tools/$OMZ_COMMAND.sh ]; then + zsh $ZSH/tools/$OMZ_COMMAND.sh $@ + else + omz_usage + fi + ;; +esac + +# Clean global vars +unfunction omz_usage +unset OMZ_COMMAND diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 732a403b7..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 @@ -74,3 +74,6 @@ else fi 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..e3909c8ab --- /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:Manage plugins' + 'theme_chooser:Preview themes' + '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/plugin.sh b/tools/plugin.sh new file mode 100755 index 000000000..bedfb86ca --- /dev/null +++ b/tools/plugin.sh @@ -0,0 +1,56 @@ +#!/bin/zsh + +function omz_plugin_usage() { + echo "Usage: omz plugin [options] [plugin]" + echo "Enable [plugin] in current session" + echo + echo "Options" + echo " -l List available plugins" + echo " -h Show this help message" +} + +function omz_plugin_exit_clean() { + unset OMZ_OPTION + unset OMZ_PLUGIN + unfunction omz_plugin_usage + unfunction omz_plugin_exit_clean + return +} + + +OPTIND=0 +while getopts "lh" OMZ_OPTION +do + case $OMZ_OPTION in + l ) ls $ZSH/plugins + omz_plugin_exit_clean + return ;; + + * ) omz_plugin_usage + omz_plugin_exit_clean + return ;; + + esac +done + +if [ -n "$1" ]; then + OMZ_PLUGIN="$ZSH/plugins/$1" + + if [ -d $OMZ_PLUGIN ]; then + fpath=($OMZ_PLUGIN $fpath) + autoload -U compinit + compinit -i + if [ -e $OMZ_PLUGIN/$1.plugin.zsh ]; then + source $OMZ_PLUGIN/$1.plugin.zsh + fi + echo "\033[0;32mPlugin $1 enabled" + else + echo "\033[1;31mPlugin $1 not found" + fi +else + omz_plugin_usage +fi + +# Clean global vars +omz_plugin_exit_clean +return diff --git a/tools/uninstall.sh b/tools/uninstall.sh old mode 100644 new mode 100755 index 8ff583322..e3f744f05 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,3 +1,12 @@ +#!/bin/zsh + +### Better prompt the user! +echo -n "\033[0;33mAre you sure to completely remove Oh My Zsh?\033[0m" +read "a? [type 'yes' to continue] " +if [[ $a != "yes" ]]; then + return 0 +fi + echo "Removing ~/.oh-my-zsh" if [[ -d ~/.oh-my-zsh ]] then @@ -17,4 +26,4 @@ else source /etc/profile fi -echo "Thanks for trying out Oh My Zsh. It's been uninstalled." \ No newline at end of file +echo "Thanks for trying out Oh My Zsh. It's been uninstalled." diff --git a/tools/upgrade.sh b/tools/upgrade.sh old mode 100644 new mode 100755