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