From 488e40604e6fd9064a8ec0c6d97145592bd2bde0 Mon Sep 17 00:00:00 2001 From: Marko Bauhardt Date: Thu, 17 Oct 2013 17:11:00 +0200 Subject: [PATCH 01/12] version 0.1 from current upstream project https://github.com/mbauhardt/oh-my-zsh-bootstrap --- plugins/oh-my-zsh-bootstrap/README.md | 7 + plugins/oh-my-zsh-bootstrap/lib/download.zsh | 22 +++ plugins/oh-my-zsh-bootstrap/lib/map.zsh | 40 ++++++ .../oh-my-zsh-bootstrap/lib/repository.zsh | 125 ++++++++++++++++++ .../oh-my-zsh-bootstrap.plugin.zsh | 21 +++ 5 files changed, 215 insertions(+) create mode 100644 plugins/oh-my-zsh-bootstrap/README.md create mode 100644 plugins/oh-my-zsh-bootstrap/lib/download.zsh create mode 100644 plugins/oh-my-zsh-bootstrap/lib/map.zsh create mode 100644 plugins/oh-my-zsh-bootstrap/lib/repository.zsh create mode 100644 plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh diff --git a/plugins/oh-my-zsh-bootstrap/README.md b/plugins/oh-my-zsh-bootstrap/README.md new file mode 100644 index 000000000..62c916406 --- /dev/null +++ b/plugins/oh-my-zsh-bootstrap/README.md @@ -0,0 +1,7 @@ +# Oh My Zsh Bootstrap + +_Oh My Zsh Bootstrap_ is a plugin for [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) + +See current upstream project https://github.com/mbauhardt/oh-my-zsh-bootstrap for more information. + + diff --git a/plugins/oh-my-zsh-bootstrap/lib/download.zsh b/plugins/oh-my-zsh-bootstrap/lib/download.zsh new file mode 100644 index 000000000..b068964f8 --- /dev/null +++ b/plugins/oh-my-zsh-bootstrap/lib/download.zsh @@ -0,0 +1,22 @@ +_clone_git() { + local url=$1 + local folder=$2 + if [[ ! -d "$folder" ]]; then + git clone $url $folder + fi +} + +_download_plugin() { + [[ "$#" != 2 ]] && return 1 + local url=$1; local name=$2; + _clone_git $url $ZSH_CUSTOM/plugins/$name + _map_put plugins $name enabled +} + +_download_theme() { + [[ "$#" != 2 ]] && return 1 + local url=$1; local theme=$2; + _clone_git $url $ZSH_CUSTOM/themes/$theme + ln -s $ZSH_CUSTOM/themes/$theme/$theme.zsh-theme $ZSH_CUSTOM/$theme.zsh-theme + _map_put themes theme $theme +} diff --git a/plugins/oh-my-zsh-bootstrap/lib/map.zsh b/plugins/oh-my-zsh-bootstrap/lib/map.zsh new file mode 100644 index 000000000..ae36c4574 --- /dev/null +++ b/plugins/oh-my-zsh-bootstrap/lib/map.zsh @@ -0,0 +1,40 @@ +mapdir=$ZSH_BOOTSTRAP/data + +_map_init() { + mkdir -p $mapdir +} + +_map_put() { + [[ "$#" != 3 ]] && return 1 + mapname=$1; key=$2; value=$3 + [[ -d "${mapdir}/${mapname}" ]] || mkdir "${mapdir}/${mapname}" + echo $value >"${mapdir}/${mapname}/${key}" +} + +_map_get() { + [[ "$#" != 2 ]] && return 1 + mapname=$1; key=$2 + cat "${mapdir}/${mapname}/${key}" +} + +_map_keys() { + [[ "$#" != 1 ]] && return 1 + mapname=$1 + for key ($mapdir/$mapname/*); do + basename $key + done +} + +_map_exists() { + [[ "$#" != 2 ]] && return 1 + mapname=$1; key=$2 + [[ -f "${mapdir}/${mapname}/${key}" ]] && return 0 +} + +_map_remove() { + [[ "$#" != 2 ]] && return 1 + mapname=$1; key=$2 + rm "${mapdir}/${mapname}/${key}" +} +_map_init + diff --git a/plugins/oh-my-zsh-bootstrap/lib/repository.zsh b/plugins/oh-my-zsh-bootstrap/lib/repository.zsh new file mode 100644 index 000000000..78b245c8c --- /dev/null +++ b/plugins/oh-my-zsh-bootstrap/lib/repository.zsh @@ -0,0 +1,125 @@ +_init_theme() { + _map_exists themes theme + [[ $? -ne 0 ]] && _map_put themes theme robbyrussell +} + +_pre_enable_plugins() { + for plugin ($plugins); do + _map_put plugins $plugin pre_enabled + done +} + +_list_plugins() { + for plugin ($ZSH/plugins/* $ZSH_CUSTOM/plugins/*(N)); do + local plugin_name=$(basename $plugin) + local enabled=disabled + _map_exists plugins $plugin_name + if [[ $? -eq 0 ]]; then + enabled=$(_map_get plugins $plugin_name) + fi + if [[ $enabled = "pre_enabled" || $enabled = "enabled" ]]; then + printf "%-30s \033[0;32m%-10s\033[0m\n" $plugin_name $enabled + else + printf "%-30s \033[0;30m%-10s\033[0m\n" $plugin_name $enabled + fi + done +} + +_list_themes() { + for theme ($ZSH/themes/*zsh-theme $ZSH_CUSTOM/*zsh-theme(N)); do + local theme_name=$(basename $theme | awk -F '.' '{print $1}') + local selected_theme=$(_map_get themes theme) + if [[ $selected_theme = $theme_name ]]; then + printf "%-30s \033[0;32m%-10s\033[0m\n" $theme_name enabled + else + printf "%-30s \033[0;30m%-10s\033[0m\n" $theme_name disabled + fi + done +} + +_list_pre_enabled_enabled_plugins() { + for plugin ($(_map_keys plugins)); do + local enabled=$(_map_get plugins $plugin) + if [[ $enabled = "enabled" ]]; then + printf "%s " $plugin + fi + done +} + +_list_enabled_plugins() { + for plugin ($(_map_keys plugins)); do + local enabled=$(_map_get plugins $plugin) + if [[ $enabled = "pre_enabled" || $enabled = "enabled" ]]; then + printf "%-30s \033[0;32m%-10s\033[0m\n" $plugin $enabled + fi + done +} + +_enable_plugin() { + [[ "$#" != 1 ]] && return 1 + local plugin=$1 + _map_exists plugins $plugin + if [[ $? -ne 0 ]]; then + _map_put plugins $plugin enabled + fi +} + +_enable_theme() { + [[ "$#" != 1 ]] && return 1 + local theme=$1 + _map_put themes theme $theme +} + +_disable_plugin() { + [[ "$#" != 1 ]] && return 1 + local plugin=$1 + local enabled=$(_map_get plugins $plugin) + [[ $enabled = "enabled" ]] && _map_remove plugins $plugin +} + +_populate_enabled_plugins() { + for plugin ($(_list_pre_enabled_enabled_plugins)); do + if [[ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]]; then + fpath=($ZSH/plugins/$plugin $fpath) + source $ZSH/plugins/$plugin/$plugin.plugin.zsh + elif [[ -f $ZSH/plugins/$plugin/_$plugin ]]; then + fpath=($ZSH/plugins/$plugin $fpath) + elif [[ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]]; then + fpath=($ZSH_CUSTOM/plugins/$plugin $fpath) + source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh + elif [[ -f $ZSH_CUSTOM/plugins/$plugin/_$plugin ]]; then + fpath=($ZSH_CUSTOM/plugins/$plugin $fpath) + fi + done +} + +_populate_enabled_theme() { + ZSH_THEME=$(_map_get themes theme) +} + +_update_plugin() { + [[ "$#" != 1 ]] && return 1 + local plugin=$1 + if [[ -d $ZSH_CUSTOM/plugins/$plugin ]]; then + pushd $ZSH_CUSTOM/plugins/$plugin > /dev/null + git pull + popd > /dev/null + fi +} + +_update_theme() { + [[ "$#" != 1 ]] && return 1 + local theme=$1 + if [[ -d $ZSH_CUSTOM/themes/$theme ]]; then + pushd $ZSH_CUSTOM/themes/$theme > /dev/null + git pull + popd > /dev/null + fi +} + + + +_pre_enable_plugins +_populate_enabled_plugins +_init_theme +_populate_enabled_theme \ No newline at end of file diff --git a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh new file mode 100644 index 000000000..520d65d70 --- /dev/null +++ b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh @@ -0,0 +1,21 @@ +_load_bootstrap() { + export ZSH_BOOTSTRAP=$1 + source $ZSH_BOOTSTRAP/lib/map.zsh + source $ZSH_BOOTSTRAP/lib/repository.zsh + source $ZSH_BOOTSTRAP/lib/download.zsh +} + +[[ -f $ZSH_CUSTOM/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH_CUSTOM/plugins/oh-my-zsh-bootstrap +[[ -f $ZSH/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH/plugins/oh-my-zsh-bootstrap + + +alias list_plugins="_list_plugins|less" +alias list_themes="_list_themes|less" +alias download_and_enable_plugin="_download_plugin" +alias download_and_enable_theme="_download_theme" +alias list_enabled_plugins="_list_enabled_plugins" +alias enable_plugin="_enable_plugin" +alias enable_theme="_enable_theme" +alias disable_plugin="_disable_plugin" +alias update_plugin="_udpate_plugin" +alias update_theme="_update_theme" \ No newline at end of file From 1cbc4949ac2861e68f89a0afbc9187d3931da037 Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 20:02:25 +0200 Subject: [PATCH 02/12] bundle the plugin into the omz function --- .../oh-my-zsh-bootstrap.plugin.zsh | 85 ++++++++++++++++--- 1 file changed, 75 insertions(+), 10 deletions(-) diff --git a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh index 520d65d70..a0b5f3858 100644 --- a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh +++ b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh @@ -8,14 +8,79 @@ _load_bootstrap() { [[ -f $ZSH_CUSTOM/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH_CUSTOM/plugins/oh-my-zsh-bootstrap [[ -f $ZSH/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH/plugins/oh-my-zsh-bootstrap +usage='Usage: omz { plugin | theme } []' +usage_p='Usage: omz plugin [] +Commands: + ls\tlist available plugins + on \tenable a plugin + off \tdisable a plugin + up \tupdate a plugin + get \tdownload and enable a plugin' +usage_t='Usage: omz theme [] +Commands: + ls\tlist available themes + set \tset a theme + up \tupdate a theme + get \tdownload and enable a theme' + +omz () { + case "$1" in + (plugin) + case "$2" in + (ls) + _list_plugins|less + ;; + (on) + _enable_plugin "$3" + ;; + (off) + _disable_plugin "$3" + ;; + (up) + _update_plugin "$3" + ;; + (get) + _download_plugin "$3" "$4" + ;; + (-h|--help|help) + echo $usage_p + ;; + (*) + echo $usage_p + return 10 + ;; + esac + ;; + (theme) + case "$2" in + (ls) + _list_themes|less + ;; + (set) + _enable_theme "$3" + ;; + (up) + _update_theme "$3" + ;; + (get) + _download_theme "$3" "$4" + ;; + (-h|--help|help) + echo $usage_t + ;; + (*) + echo $usage_t + return 20 + ;; + esac + ;; + (-h|--help|help) + echo $usage + ;; + (*) + echo $usage + return 1 + ;; + esac +} -alias list_plugins="_list_plugins|less" -alias list_themes="_list_themes|less" -alias download_and_enable_plugin="_download_plugin" -alias download_and_enable_theme="_download_theme" -alias list_enabled_plugins="_list_enabled_plugins" -alias enable_plugin="_enable_plugin" -alias enable_theme="_enable_theme" -alias disable_plugin="_disable_plugin" -alias update_plugin="_udpate_plugin" -alias update_theme="_update_theme" \ No newline at end of file From 3ba05d9c3582cd06de127efe3a6f68bf3378975e Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 20:23:42 +0200 Subject: [PATCH 03/12] added completion to omz function --- plugins/oh-my-zsh-bootstrap/_omz | 146 ++++++++++++++++++ .../oh-my-zsh-bootstrap.plugin.zsh | 1 + 2 files changed, 147 insertions(+) create mode 100644 plugins/oh-my-zsh-bootstrap/_omz diff --git a/plugins/oh-my-zsh-bootstrap/_omz b/plugins/oh-my-zsh-bootstrap/_omz new file mode 100644 index 000000000..9df513d39 --- /dev/null +++ b/plugins/oh-my-zsh-bootstrap/_omz @@ -0,0 +1,146 @@ +#compdef omz + +# Completion for the omz-plugin command +# Author: github.com/ncanceill + +_omz () { + local curcontext=$curcontext state line + declare -A opt_args + _arguments -C \ + ':command:->command' \ + '*::options:->options' && ret=0 + case $state in + (command) + declare -a commands + commands=( + 'plugin:manage plugins' + 'theme:manage themes' + ) + _describe -t commands 'command' commands && ret=0 + ;; + (options) + case $line[1] in + (plugin) + _omz-plugin && ret=0 + ;; + (theme) + _omz-theme && ret=0 + ;; + esac + ;; + esac + return ret +} + +_omz-plugin () { + local curcontext=$curcontext state line + declare -A opt_args + _arguments -C \ + ':command:->command' \ + '*::options:->options' && ret=0 + case $state in + (command) + declare -a commands + commands=( + 'ls:list available plugins' + 'on:enable a plugin' + 'off:disable a plugin' + 'up:update a plugin' + 'get:download and enable a plugin' + ) + _describe -t commands 'sub-command' commands && ret=0 + ;; + (options) + case $line[1] in + (on) + _plugins_off && ret=0 + ;; + (off) + _plugins_on && ret=0 + ;; + (up) + _plugins && ret=0 + ;; + esac + ;; + esac + return ret +} + +_plugins () { + declare -a plugins + plugins=() + for plugin ($ZSH/plugins/* $ZSH_CUSTOM/plugins/*(N)); do + plugins+=$plugin:t:r + done + _describe -t plugins 'plugin' plugins && return 0 +} + +_plugins_on () { + declare -a plugins_on + plugins_on=() + for plugin ($ZSH/plugins/* $ZSH_CUSTOM/plugins/*(N)); do + local plugin_name=$plugin:t:r + _map_exists plugins $plugin_name + if [[ $? -eq 0 ]]; then + plugins_on+=$plugin_name + fi + done + _describe -t plugins_on 'plugin' plugins_on && return 0 +} + +_plugins_off () { + declare -a plugins_off + plugins_off=() + for plugin ($ZSH/plugins/* $ZSH_CUSTOM/plugins/*(N)); do + local plugin_name=$plugin:t:r + _map_exists plugins $plugin_name + if [[ $? -ne 0 ]]; then + plugins_off+=$plugin_name + fi + done + _describe -t plugins_off 'plugin' plugins_off && return 0 +} + +_omz-theme () { + local curcontext=$curcontext state line + declare -A opt_args + _arguments -C \ + ':command:->command' \ + '*::options:->options' && ret=0 + case $state in + (command) + declare -a commands + commands=( + 'ls:list available themes' + 'set:set a theme' + 'up:update a theme' + 'get:download and enable a theme' + ) + _describe -t commands 'sub-command' commands && ret=0 + ;; + (options) + case $line[1] in + (set) + _arguments \ + ':theme:_themes' && ret=0 + ;; + (up) + _arguments \ + ':theme:_themes' && ret=0 + ;; + esac + ;; + esac + return ret +} + +_themes () { + declare -a themes + themes=() + for theme ($ZSH/themes/*zsh-theme $ZSH_CUSTOM/*zsh-theme(N)); do + themes+=$theme:t:r + done + _describe -t themes 'theme' themes && return 0 +} + diff --git a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh index a0b5f3858..64940d635 100644 --- a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh +++ b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh @@ -84,3 +84,4 @@ omz () { esac } +compdef _omz omz From 509e42b4229f0840fb178dc8cc66dec0a2530b7c Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 20:41:42 +0200 Subject: [PATCH 04/12] really enable (hardly possible to really disable) --- plugins/oh-my-zsh-bootstrap/lib/repository.zsh | 12 ++++++++++-- .../oh-my-zsh-bootstrap.plugin.zsh | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/oh-my-zsh-bootstrap/lib/repository.zsh b/plugins/oh-my-zsh-bootstrap/lib/repository.zsh index 78b245c8c..b486f8fb0 100644 --- a/plugins/oh-my-zsh-bootstrap/lib/repository.zsh +++ b/plugins/oh-my-zsh-bootstrap/lib/repository.zsh @@ -78,7 +78,7 @@ _disable_plugin() { } _populate_enabled_plugins() { - for plugin ($(_list_pre_enabled_enabled_plugins)); do + for plugin ($@); do if [[ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]]; then fpath=($ZSH/plugins/$plugin $fpath) source $ZSH/plugins/$plugin/$plugin.plugin.zsh @@ -95,6 +95,14 @@ _populate_enabled_plugins() { _populate_enabled_theme() { ZSH_THEME=$(_map_get themes theme) + # Reload theme (copied from oh-my-zsh.sh) + if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then + source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" + elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then + source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" + else + source "$ZSH/themes/$ZSH_THEME.zsh-theme" + fi } _update_plugin() { @@ -122,4 +130,4 @@ _update_theme() { _pre_enable_plugins _populate_enabled_plugins _init_theme -_populate_enabled_theme \ No newline at end of file +_populate_enabled_theme $(_list_pre_enabled_enabled_plugins) diff --git a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh index 64940d635..b193c0374 100644 --- a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh +++ b/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh @@ -31,7 +31,7 @@ omz () { _list_plugins|less ;; (on) - _enable_plugin "$3" + _enable_plugin "$3"&&_populate_enabled_plugins "$3" ;; (off) _disable_plugin "$3" @@ -40,7 +40,7 @@ omz () { _update_plugin "$3" ;; (get) - _download_plugin "$3" "$4" + _download_plugin "$3" "$4"&&_populate_enabled_plugins "$4" ;; (-h|--help|help) echo $usage_p @@ -57,13 +57,13 @@ omz () { _list_themes|less ;; (set) - _enable_theme "$3" + _enable_theme "$3"&&_populate_enabled_theme ;; (up) _update_theme "$3" ;; (get) - _download_theme "$3" "$4" + _download_theme "$3" "$4"&&_populate_enabled_theme ;; (-h|--help|help) echo $usage_t From d67d3d4d0cd4c91aa6d3b00baca6c2b2e47c3126 Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 21:31:31 +0200 Subject: [PATCH 05/12] pre-enable theme from .zshrc --- plugins/oh-my-zsh-bootstrap/lib/repository.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/oh-my-zsh-bootstrap/lib/repository.zsh b/plugins/oh-my-zsh-bootstrap/lib/repository.zsh index b486f8fb0..8b0a1c849 100644 --- a/plugins/oh-my-zsh-bootstrap/lib/repository.zsh +++ b/plugins/oh-my-zsh-bootstrap/lib/repository.zsh @@ -1,6 +1,6 @@ _init_theme() { _map_exists themes theme - [[ $? -ne 0 ]] && _map_put themes theme robbyrussell + [[ $? -ne 0 ]] && _map_put themes theme $ZSH_THEME } _pre_enable_plugins() { From 5c97e28d56d7c32a71ea74e437bacf7462efc2d5 Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 22:26:47 +0200 Subject: [PATCH 06/12] use a shorter plugin name --- plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/README.md | 0 plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/_omz | 0 plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/lib/download.zsh | 0 plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/lib/map.zsh | 0 plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/lib/repository.zsh | 0 .../omz-bootstrap.plugin.zsh} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/README.md (100%) rename plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/_omz (100%) rename plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/lib/download.zsh (100%) rename plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/lib/map.zsh (100%) rename plugins/{oh-my-zsh-bootstrap => omz-bootstrap}/lib/repository.zsh (100%) rename plugins/{oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh => omz-bootstrap/omz-bootstrap.plugin.zsh} (100%) diff --git a/plugins/oh-my-zsh-bootstrap/README.md b/plugins/omz-bootstrap/README.md similarity index 100% rename from plugins/oh-my-zsh-bootstrap/README.md rename to plugins/omz-bootstrap/README.md diff --git a/plugins/oh-my-zsh-bootstrap/_omz b/plugins/omz-bootstrap/_omz similarity index 100% rename from plugins/oh-my-zsh-bootstrap/_omz rename to plugins/omz-bootstrap/_omz diff --git a/plugins/oh-my-zsh-bootstrap/lib/download.zsh b/plugins/omz-bootstrap/lib/download.zsh similarity index 100% rename from plugins/oh-my-zsh-bootstrap/lib/download.zsh rename to plugins/omz-bootstrap/lib/download.zsh diff --git a/plugins/oh-my-zsh-bootstrap/lib/map.zsh b/plugins/omz-bootstrap/lib/map.zsh similarity index 100% rename from plugins/oh-my-zsh-bootstrap/lib/map.zsh rename to plugins/omz-bootstrap/lib/map.zsh diff --git a/plugins/oh-my-zsh-bootstrap/lib/repository.zsh b/plugins/omz-bootstrap/lib/repository.zsh similarity index 100% rename from plugins/oh-my-zsh-bootstrap/lib/repository.zsh rename to plugins/omz-bootstrap/lib/repository.zsh diff --git a/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh b/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh similarity index 100% rename from plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh rename to plugins/omz-bootstrap/omz-bootstrap.plugin.zsh From 0476d320bf5148fdeaf50167f161481ed42663f3 Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 22:30:46 +0200 Subject: [PATCH 07/12] updated readme --- plugins/omz-bootstrap/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/omz-bootstrap/README.md b/plugins/omz-bootstrap/README.md index 62c916406..e6f698646 100644 --- a/plugins/omz-bootstrap/README.md +++ b/plugins/omz-bootstrap/README.md @@ -1,7 +1,8 @@ # Oh My Zsh Bootstrap -_Oh My Zsh Bootstrap_ is a plugin for [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) +_Oh My Zsh Bootstrap_ is a plugin for [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh). Enable it by adding `omz-bootstrap` to your plugins. -See current upstream project https://github.com/mbauhardt/oh-my-zsh-bootstrap for more information. +It is inspired by [mbauhardt's project](https://github.com/mbauhardt/oh-my-zsh-bootstrap). +It provides the `omz` function, which helps you manage your themes and plugins. From 5d47931522a4fb0280e06f41cefe7a781fc012e4 Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 23:48:29 +0200 Subject: [PATCH 08/12] updated plugin name --- plugins/omz-bootstrap/omz-bootstrap.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh b/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh index b193c0374..8f1af723e 100644 --- a/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh +++ b/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh @@ -5,8 +5,8 @@ _load_bootstrap() { source $ZSH_BOOTSTRAP/lib/download.zsh } -[[ -f $ZSH_CUSTOM/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH_CUSTOM/plugins/oh-my-zsh-bootstrap -[[ -f $ZSH/plugins/oh-my-zsh-bootstrap/oh-my-zsh-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH/plugins/oh-my-zsh-bootstrap +[[ -f $ZSH_CUSTOM/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH_CUSTOM/plugins/omz-bootstrap +[[ -f $ZSH/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH/plugins/omz-bootstrap usage='Usage: omz { plugin | theme } []' usage_p='Usage: omz plugin [] From ee16c11d15fc1301f5785de3c3a6e438d5f78823 Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 23:49:36 +0200 Subject: [PATCH 09/12] send tabs into space --- plugins/omz-bootstrap/_omz | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/omz-bootstrap/_omz b/plugins/omz-bootstrap/_omz index 9df513d39..8014f664c 100644 --- a/plugins/omz-bootstrap/_omz +++ b/plugins/omz-bootstrap/_omz @@ -45,8 +45,8 @@ _omz-plugin () { 'ls:list available plugins' 'on:enable a plugin' 'off:disable a plugin' - 'up:update a plugin' - 'get:download and enable a plugin' + 'up:update a plugin' + 'get:download and enable a plugin' ) _describe -t commands 'sub-command' commands && ret=0 ;; @@ -114,8 +114,8 @@ _omz-theme () { commands=( 'ls:list available themes' 'set:set a theme' - 'up:update a theme' - 'get:download and enable a theme' + 'up:update a theme' + 'get:download and enable a theme' ) _describe -t commands 'sub-command' commands && ret=0 ;; From a3a0526e92b3ac7448ad4934ec6f0a662e5ca625 Mon Sep 17 00:00:00 2001 From: ncanceill Date: Sat, 5 Apr 2014 23:51:23 +0200 Subject: [PATCH 10/12] add myself as maintainer --- plugins/omz-bootstrap/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/omz-bootstrap/README.md b/plugins/omz-bootstrap/README.md index e6f698646..776997ec1 100644 --- a/plugins/omz-bootstrap/README.md +++ b/plugins/omz-bootstrap/README.md @@ -1,5 +1,7 @@ # Oh My Zsh Bootstrap +**Maintainer:** [**@ncanceill**](https://github.com/ncanceill) + _Oh My Zsh Bootstrap_ is a plugin for [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh). Enable it by adding `omz-bootstrap` to your plugins. It is inspired by [mbauhardt's project](https://github.com/mbauhardt/oh-my-zsh-bootstrap). From 393eed5e67d10131a8f12199c0b416412c7a9acf Mon Sep 17 00:00:00 2001 From: ncanceill Date: Tue, 15 Apr 2014 15:25:07 +0200 Subject: [PATCH 11/12] use cache dir for maps --- plugins/omz-bootstrap/lib/map.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/omz-bootstrap/lib/map.zsh b/plugins/omz-bootstrap/lib/map.zsh index ae36c4574..4ab1e8e23 100644 --- a/plugins/omz-bootstrap/lib/map.zsh +++ b/plugins/omz-bootstrap/lib/map.zsh @@ -1,4 +1,4 @@ -mapdir=$ZSH_BOOTSTRAP/data +mapdir=$ZSH/cache/omz-bootstrap _map_init() { mkdir -p $mapdir From f74c8b2941b550759aa9e589bb979bf5875351a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 8 Jun 2014 13:08:40 +0200 Subject: [PATCH 12/12] Change parameter checks and other style fixes This commits contains the following modifications: - Change parameter checks from number of parameters (`$#`) to content length of each parameter ( `-z "$1"` ). A command called with an empty string in the first parameter *still* receives one parameter (`$# = 1`), while checking the string length will work either way. - Change commands that may be aliased to use the builtin / non-modified command, using the 'command' prefix (e.g. `git` -> `command git`). - Changed the initialization sequence of the plugin, from using a function to being inline in the script. It also uses the $0 parameter which is set when the script is sourced, and it contains the script filepath. Example: with command `source test.sh` -> in test.sh, `$0` will be 'test.sh'. - Various style fixes, including missing space and some comments. --- plugins/omz-bootstrap/_omz | 1 + plugins/omz-bootstrap/lib/download.zsh | 15 +++--- plugins/omz-bootstrap/lib/map.zsh | 30 ++++++------ plugins/omz-bootstrap/lib/repository.zsh | 27 ++++++----- .../omz-bootstrap/omz-bootstrap.plugin.zsh | 46 +++++++++---------- 5 files changed, 57 insertions(+), 62 deletions(-) diff --git a/plugins/omz-bootstrap/_omz b/plugins/omz-bootstrap/_omz index 8014f664c..883332ce9 100644 --- a/plugins/omz-bootstrap/_omz +++ b/plugins/omz-bootstrap/_omz @@ -144,3 +144,4 @@ _themes () { _describe -t themes 'theme' themes && return 0 } +_omz diff --git a/plugins/omz-bootstrap/lib/download.zsh b/plugins/omz-bootstrap/lib/download.zsh index b068964f8..c463d1b9a 100644 --- a/plugins/omz-bootstrap/lib/download.zsh +++ b/plugins/omz-bootstrap/lib/download.zsh @@ -1,22 +1,21 @@ _clone_git() { - local url=$1 - local folder=$2 + local url=$1; local folder=$2 if [[ ! -d "$folder" ]]; then - git clone $url $folder + command git clone $url $folder fi } _download_plugin() { - [[ "$#" != 2 ]] && return 1 - local url=$1; local name=$2; + [[ -z "$1" || -z "$2" ]] && return 1 + local url=$1; local name=$2 _clone_git $url $ZSH_CUSTOM/plugins/$name _map_put plugins $name enabled } _download_theme() { - [[ "$#" != 2 ]] && return 1 - local url=$1; local theme=$2; + [[ -z "$1" || -z "$2" ]] && return 1 + local url=$1; local theme=$2 _clone_git $url $ZSH_CUSTOM/themes/$theme - ln -s $ZSH_CUSTOM/themes/$theme/$theme.zsh-theme $ZSH_CUSTOM/$theme.zsh-theme + command ln -s $ZSH_CUSTOM/themes/$theme/$theme.zsh-theme $ZSH_CUSTOM/$theme.zsh-theme _map_put themes theme $theme } diff --git a/plugins/omz-bootstrap/lib/map.zsh b/plugins/omz-bootstrap/lib/map.zsh index 4ab1e8e23..c5d295781 100644 --- a/plugins/omz-bootstrap/lib/map.zsh +++ b/plugins/omz-bootstrap/lib/map.zsh @@ -1,40 +1,40 @@ -mapdir=$ZSH/cache/omz-bootstrap +mapdir="$ZSH/cache/omz-bootstrap" _map_init() { - mkdir -p $mapdir + command mkdir -p "$mapdir" } _map_put() { - [[ "$#" != 3 ]] && return 1 - mapname=$1; key=$2; value=$3 + [[ -z "$1" || -z "$2" || -z "$3" ]] && return 1 + local mapname=$1; local key=$2; local value=$3 [[ -d "${mapdir}/${mapname}" ]] || mkdir "${mapdir}/${mapname}" - echo $value >"${mapdir}/${mapname}/${key}" + echo $value > "${mapdir}/${mapname}/${key}" } _map_get() { - [[ "$#" != 2 ]] && return 1 - mapname=$1; key=$2 + [[ -z "$1" || -z "$2" ]] && return 1 + local mapname=$1; local key=$2 cat "${mapdir}/${mapname}/${key}" } _map_keys() { - [[ "$#" != 1 ]] && return 1 - mapname=$1 + [[ -z "$1" ]] && return 1 + local mapname=$1 for key ($mapdir/$mapname/*); do basename $key done } _map_exists() { - [[ "$#" != 2 ]] && return 1 - mapname=$1; key=$2 + [[ -z "$1" || -z "$2" ]] && return 1 + local mapname=$1; local key=$2 [[ -f "${mapdir}/${mapname}/${key}" ]] && return 0 } _map_remove() { - [[ "$#" != 2 ]] && return 1 - mapname=$1; key=$2 - rm "${mapdir}/${mapname}/${key}" + [[ -z "$1" || -z "$2" ]] && return 1 + local mapname=$1; local key=$2 + command rm "${mapdir}/${mapname}/${key}" } -_map_init +_map_init diff --git a/plugins/omz-bootstrap/lib/repository.zsh b/plugins/omz-bootstrap/lib/repository.zsh index 8b0a1c849..1fbbcd33b 100644 --- a/plugins/omz-bootstrap/lib/repository.zsh +++ b/plugins/omz-bootstrap/lib/repository.zsh @@ -21,7 +21,7 @@ _list_plugins() { printf "%-30s \033[0;32m%-10s\033[0m\n" $plugin_name $enabled else printf "%-30s \033[0;30m%-10s\033[0m\n" $plugin_name $enabled - fi + fi done } @@ -56,7 +56,7 @@ _list_enabled_plugins() { } _enable_plugin() { - [[ "$#" != 1 ]] && return 1 + [[ -z "$1" ]] && return 1 local plugin=$1 _map_exists plugins $plugin if [[ $? -ne 0 ]]; then @@ -65,13 +65,13 @@ _enable_plugin() { } _enable_theme() { - [[ "$#" != 1 ]] && return 1 + [[ -z "$1" ]] && return 1 local theme=$1 _map_put themes theme $theme } _disable_plugin() { - [[ "$#" != 1 ]] && return 1 + [[ -z "$1" ]] && return 1 local plugin=$1 local enabled=$(_map_get plugins $plugin) [[ $enabled = "enabled" ]] && _map_remove plugins $plugin @@ -106,27 +106,26 @@ _populate_enabled_theme() { } _update_plugin() { - [[ "$#" != 1 ]] && return 1 + [[ -z "$1" ]] && return 1 local plugin=$1 if [[ -d $ZSH_CUSTOM/plugins/$plugin ]]; then - pushd $ZSH_CUSTOM/plugins/$plugin > /dev/null - git pull - popd > /dev/null + command pushd $ZSH_CUSTOM/plugins/$plugin > /dev/null + command git pull + command popd > /dev/null fi } _update_theme() { - [[ "$#" != 1 ]] && return 1 + [[ -z "$1" ]] && return 1 local theme=$1 if [[ -d $ZSH_CUSTOM/themes/$theme ]]; then - pushd $ZSH_CUSTOM/themes/$theme > /dev/null - git pull - popd > /dev/null + command pushd $ZSH_CUSTOM/themes/$theme > /dev/null + command git pull + command popd > /dev/null fi } - - +# initialize repository _pre_enable_plugins _populate_enabled_plugins _init_theme diff --git a/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh b/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh index 8f1af723e..7b623e0e8 100644 --- a/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh +++ b/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh @@ -1,37 +1,34 @@ -_load_bootstrap() { - export ZSH_BOOTSTRAP=$1 - source $ZSH_BOOTSTRAP/lib/map.zsh - source $ZSH_BOOTSTRAP/lib/repository.zsh - source $ZSH_BOOTSTRAP/lib/download.zsh -} +DIR="$(dirname "$0")" +source "$DIR/lib/map.zsh" +source "$DIR/lib/repository.zsh" +source "$DIR/lib/download.zsh" +unset DIR -[[ -f $ZSH_CUSTOM/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH_CUSTOM/plugins/omz-bootstrap -[[ -f $ZSH/plugins/omz-bootstrap/omz-bootstrap.plugin.zsh ]] && _load_bootstrap $ZSH/plugins/omz-bootstrap usage='Usage: omz { plugin | theme } []' usage_p='Usage: omz plugin [] Commands: - ls\tlist available plugins - on \tenable a plugin - off \tdisable a plugin - up \tupdate a plugin - get \tdownload and enable a plugin' + ls list available plugins + on enable a plugin + off disable a plugin + up update a plugin + get download and enable a plugin' usage_t='Usage: omz theme [] Commands: - ls\tlist available themes - set \tset a theme - up \tupdate a theme - get \tdownload and enable a theme' + ls list available themes + set set a theme + up update a theme + get download and enable a theme' omz () { case "$1" in (plugin) case "$2" in (ls) - _list_plugins|less + _list_plugins | less ;; (on) - _enable_plugin "$3"&&_populate_enabled_plugins "$3" + _enable_plugin "$3" && _populate_enabled_plugins "$3" ;; (off) _disable_plugin "$3" @@ -40,7 +37,7 @@ omz () { _update_plugin "$3" ;; (get) - _download_plugin "$3" "$4"&&_populate_enabled_plugins "$4" + _download_plugin "$3" "$4" && _populate_enabled_plugins "$4" ;; (-h|--help|help) echo $usage_p @@ -54,16 +51,16 @@ omz () { (theme) case "$2" in (ls) - _list_themes|less + _list_themes | less ;; (set) - _enable_theme "$3"&&_populate_enabled_theme + _enable_theme "$3" && _populate_enabled_theme ;; (up) _update_theme "$3" ;; (get) - _download_theme "$3" "$4"&&_populate_enabled_theme + _download_theme "$3" "$4" && _populate_enabled_theme ;; (-h|--help|help) echo $usage_t @@ -72,7 +69,7 @@ omz () { echo $usage_t return 20 ;; - esac + esac ;; (-h|--help|help) echo $usage @@ -84,4 +81,3 @@ omz () { esac } -compdef _omz omz