From 9c02f7513df0e45f0852984a2d25572ff964868f Mon Sep 17 00:00:00 2001 From: nebirhos Date: Fri, 23 Mar 2012 22:37:53 +0100 Subject: [PATCH 1/7] Added omz script stub --- bin/omz | 40 ++++++++++++++++++++++++++++++++++++++++ oh-my-zsh.sh | 2 ++ 2 files changed, 42 insertions(+) create mode 100755 bin/omz diff --git a/bin/omz b/bin/omz new file mode 100755 index 000000000..32d58d0d5 --- /dev/null +++ b/bin/omz @@ -0,0 +1,40 @@ +#!/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/oh-my-zsh.sh b/oh-my-zsh.sh index 732a403b7..f3f9e49b0 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -74,3 +74,5 @@ else fi fi +# Add omz command line tool +export PATH="$ZSH/bin:$PATH" From 42d1ae029c26b41430638258f4d7520b3f84f139 Mon Sep 17 00:00:00 2001 From: nebirhos Date: Sat, 24 Mar 2012 03:00:42 +0100 Subject: [PATCH 2/7] Ask confirmation before uninstall --- tools/uninstall.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 8ff583322..9157651ad 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,3 +1,12 @@ +#!/bin/zsh + +### Better prompt the user! +echo -n "Are you sure to completely remove OH MY ZSH?" +read "a? [type 'yes' to continue] " +if [[ $a != "yes" ]]; then + return 0 +fi + echo "Removing ~/.oh-my-zsh" if [[ -d ~/.oh-my-zsh ]] then From b326820004d5c6b4280ded703f3bf0902fd005da Mon Sep 17 00:00:00 2001 From: nebirhos Date: Sat, 24 Mar 2012 05:14:54 +0100 Subject: [PATCH 3/7] omz tool to dynamically load plugins --- bin/omz | 40 ---------------------------------------- bin/omz.sh | 41 +++++++++++++++++++++++++++++++++++++++++ oh-my-zsh.sh | 3 ++- tools/_omz.sh | 38 ++++++++++++++++++++++++++++++++++++++ tools/omz-plugin.sh | 19 +++++++++++++++++++ 5 files changed, 100 insertions(+), 41 deletions(-) delete mode 100755 bin/omz create mode 100755 bin/omz.sh create mode 100644 tools/_omz.sh create mode 100755 tools/omz-plugin.sh 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 From d4ea17111e578acf79e13de13d411dad0600b87b Mon Sep 17 00:00:00 2001 From: nebirhos Date: Sun, 25 Mar 2012 17:24:26 +0200 Subject: [PATCH 4/7] Name fix --- bin/omz.sh | 6 +++--- tools/_omz.sh | 4 ++-- tools/uninstall.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/omz.sh b/bin/omz.sh index 1e438c767..d73ab95ac 100755 --- a/bin/omz.sh +++ b/bin/omz.sh @@ -1,11 +1,11 @@ #!/bin/zsh function omz_usage() { - echo "OH MY ZSH! command line tool. Available commands:" + 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 " upgrade Upgrade Oh My Zsh" + echo " uninstall Remove Oh My Zsh :(" echo " help Show this help" } diff --git a/tools/_omz.sh b/tools/_omz.sh index f8fdd1b80..af4a83de6 100644 --- a/tools/_omz.sh +++ b/tools/_omz.sh @@ -9,8 +9,8 @@ local -a _1st_arguments _1st_arguments=( 'plugin:Enable plugin' 'theme:Choose theme' - 'upgrade:Upgrade OH MY ZSH!' - 'uninstall:Remove OH MY ZSH! :(' + 'upgrade:Upgrade Oh My Zsh' + 'uninstall:Remove Oh My Zsh :(' ) local expl diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 9157651ad..1b6cbebe3 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,7 +1,7 @@ #!/bin/zsh ### Better prompt the user! -echo -n "Are you sure to completely remove OH MY ZSH?" +echo -n "Are you sure to completely remove Oh My Zsh?" read "a? [type 'yes' to continue] " if [[ $a != "yes" ]]; then return 0 From 2cf1adb25130cc8836597760d8be97ab24ca9203 Mon Sep 17 00:00:00 2001 From: nebirhos Date: Sun, 25 Mar 2012 18:50:09 +0200 Subject: [PATCH 5/7] * Colorized uninstall output * Plugin tool improved --- tools/omz-plugin.sh | 19 ------------------- tools/plugin.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ tools/uninstall.sh | 4 ++-- 3 files changed, 45 insertions(+), 21 deletions(-) delete mode 100755 tools/omz-plugin.sh create mode 100755 tools/plugin.sh mode change 100644 => 100755 tools/uninstall.sh diff --git a/tools/omz-plugin.sh b/tools/omz-plugin.sh deleted file mode 100755 index 65835aa68..000000000 --- a/tools/omz-plugin.sh +++ /dev/null @@ -1,19 +0,0 @@ -# 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 diff --git a/tools/plugin.sh b/tools/plugin.sh new file mode 100755 index 000000000..d1410afce --- /dev/null +++ b/tools/plugin.sh @@ -0,0 +1,43 @@ +#!/bin/zsh -x + +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" +} + + +while getopts ":lh" Option +do + case $Option in + l ) + ls $ZSH/plugins + return ;; + + * ) omz_plugin_usage + return 1 ;; + esac +done + + +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 "\033[0;32mPlugin $1 enabled" + return + else + echo "\033[1;31mPlugin $1 not found" + return 1 + fi +else + omz_plugin_usage; + return 1 +fi diff --git a/tools/uninstall.sh b/tools/uninstall.sh old mode 100644 new mode 100755 index 1b6cbebe3..e3f744f05 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,7 +1,7 @@ #!/bin/zsh ### Better prompt the user! -echo -n "Are you sure to completely remove Oh My Zsh?" +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 @@ -26,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." From 7cc12f64d95c9a19f7853bac15d6a99bc14bf795 Mon Sep 17 00:00:00 2001 From: nebirhos Date: Sun, 25 Mar 2012 18:51:48 +0200 Subject: [PATCH 6/7] omz bin simplified --- bin/omz.sh | 41 +++++++++++++++++------------------------ tools/_omz.sh | 4 ++-- tools/upgrade.sh | 0 3 files changed, 19 insertions(+), 26 deletions(-) mode change 100644 => 100755 tools/upgrade.sh diff --git a/bin/omz.sh b/bin/omz.sh index d73ab95ac..4a4d2f4ec 100755 --- a/bin/omz.sh +++ b/bin/omz.sh @@ -2,40 +2,33 @@ 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" + 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" } COMMAND=$1 case $COMMAND in - plugin ) + plugin ) # we need source to enable autocompletion 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 + source $ZSH/tools/$COMMAND.sh $@ ;; * ) - omz_usage + shift 1 + + if [ -x $ZSH/tools/$COMMAND.sh ]; then + zsh $ZSH/tools/$COMMAND.sh $@ + else + omz_usage + fi ;; + '' | help ) + omz_usage ;; + esac diff --git a/tools/_omz.sh b/tools/_omz.sh index af4a83de6..e3909c8ab 100644 --- a/tools/_omz.sh +++ b/tools/_omz.sh @@ -7,8 +7,8 @@ _omz_all_plugins() { local -a _1st_arguments _1st_arguments=( - 'plugin:Enable plugin' - 'theme:Choose theme' + 'plugin:Manage plugins' + 'theme_chooser:Preview themes' 'upgrade:Upgrade Oh My Zsh' 'uninstall:Remove Oh My Zsh :(' ) diff --git a/tools/upgrade.sh b/tools/upgrade.sh old mode 100644 new mode 100755 From 172008ee26c1a8ae3beb81ffdb1245f738d6ac6c Mon Sep 17 00:00:00 2001 From: nebirhos Date: Mon, 26 Mar 2012 23:13:47 +0200 Subject: [PATCH 7/7] Scoped var and function name when sourcing --- bin/omz.sh | 25 ++++++++++++++----------- tools/plugin.sh | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/bin/omz.sh b/bin/omz.sh index 4a4d2f4ec..2ecf81a51 100755 --- a/bin/omz.sh +++ b/bin/omz.sh @@ -9,26 +9,29 @@ function omz_usage() { echo " help Show this help" } -COMMAND=$1 -case $COMMAND in +OMZ_COMMAND=$1 +case $OMZ_COMMAND in - plugin ) # we need source to enable autocompletion + '' | help ) + omz_usage + ;; + + plugin ) shift 1 - source $ZSH/tools/$COMMAND.sh $@ + source $ZSH/tools/$OMZ_COMMAND.sh $@ ;; * ) shift 1 - - if [ -x $ZSH/tools/$COMMAND.sh ]; then - zsh $ZSH/tools/$COMMAND.sh $@ + if [ -x $ZSH/tools/$OMZ_COMMAND.sh ]; then + zsh $ZSH/tools/$OMZ_COMMAND.sh $@ else omz_usage fi ;; - - '' | help ) - omz_usage ;; - esac + +# Clean global vars +unfunction omz_usage +unset OMZ_COMMAND diff --git a/tools/plugin.sh b/tools/plugin.sh index d1410afce..bedfb86ca 100755 --- a/tools/plugin.sh +++ b/tools/plugin.sh @@ -1,4 +1,4 @@ -#!/bin/zsh -x +#!/bin/zsh function omz_plugin_usage() { echo "Usage: omz plugin [options] [plugin]" @@ -9,35 +9,48 @@ function omz_plugin_usage() { 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 +} -while getopts ":lh" Option + +OPTIND=0 +while getopts "lh" OMZ_OPTION do - case $Option in - l ) - ls $ZSH/plugins + case $OMZ_OPTION in + l ) ls $ZSH/plugins + omz_plugin_exit_clean return ;; * ) omz_plugin_usage - return 1 ;; + omz_plugin_exit_clean + return ;; + esac done - if [ -n "$1" ]; then - PLUGIN="$ZSH/plugins/$1" + OMZ_PLUGIN="$ZSH/plugins/$1" - if [ -d $PLUGIN ]; then - fpath=($PLUGIN $fpath) - source $PLUGIN/*.plugin.zsh + 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" - return else echo "\033[1;31mPlugin $1 not found" - return 1 fi else - omz_plugin_usage; - return 1 + omz_plugin_usage fi + +# Clean global vars +omz_plugin_exit_clean +return