mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
use a shorter plugin name
This commit is contained in:
parent
d67d3d4d0c
commit
5c97e28d56
6 changed files with 0 additions and 0 deletions
7
plugins/omz-bootstrap/README.md
Normal file
7
plugins/omz-bootstrap/README.md
Normal file
|
|
@ -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.
|
||||
|
||||
|
||||
146
plugins/omz-bootstrap/_omz
Normal file
146
plugins/omz-bootstrap/_omz
Normal file
|
|
@ -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
|
||||
}
|
||||
|
||||
22
plugins/omz-bootstrap/lib/download.zsh
Normal file
22
plugins/omz-bootstrap/lib/download.zsh
Normal file
|
|
@ -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
|
||||
}
|
||||
40
plugins/omz-bootstrap/lib/map.zsh
Normal file
40
plugins/omz-bootstrap/lib/map.zsh
Normal file
|
|
@ -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
|
||||
|
||||
133
plugins/omz-bootstrap/lib/repository.zsh
Normal file
133
plugins/omz-bootstrap/lib/repository.zsh
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
_init_theme() {
|
||||
_map_exists themes theme
|
||||
[[ $? -ne 0 ]] && _map_put themes theme $ZSH_THEME
|
||||
}
|
||||
|
||||
_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 ($@); 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)
|
||||
# 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() {
|
||||
[[ "$#" != 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 $(_list_pre_enabled_enabled_plugins)
|
||||
87
plugins/omz-bootstrap/omz-bootstrap.plugin.zsh
Normal file
87
plugins/omz-bootstrap/omz-bootstrap.plugin.zsh
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
_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
|
||||
|
||||
usage='Usage: omz { plugin | theme } <cmd> [<options>]'
|
||||
usage_p='Usage: omz plugin <cmd> [<options>]
|
||||
Commands:
|
||||
ls\tlist available plugins
|
||||
on <name>\tenable a plugin
|
||||
off <name>\tdisable a plugin
|
||||
up <name>\tupdate a plugin
|
||||
get <git-url> <name>\tdownload and enable a plugin'
|
||||
usage_t='Usage: omz theme <cmd> [<options>]
|
||||
Commands:
|
||||
ls\tlist available themes
|
||||
set <name>\tset a theme
|
||||
up <name>\tupdate a theme
|
||||
get <git-url> <name>\tdownload and enable a theme'
|
||||
|
||||
omz () {
|
||||
case "$1" in
|
||||
(plugin)
|
||||
case "$2" in
|
||||
(ls)
|
||||
_list_plugins|less
|
||||
;;
|
||||
(on)
|
||||
_enable_plugin "$3"&&_populate_enabled_plugins "$3"
|
||||
;;
|
||||
(off)
|
||||
_disable_plugin "$3"
|
||||
;;
|
||||
(up)
|
||||
_update_plugin "$3"
|
||||
;;
|
||||
(get)
|
||||
_download_plugin "$3" "$4"&&_populate_enabled_plugins "$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"&&_populate_enabled_theme
|
||||
;;
|
||||
(up)
|
||||
_update_theme "$3"
|
||||
;;
|
||||
(get)
|
||||
_download_theme "$3" "$4"&&_populate_enabled_theme
|
||||
;;
|
||||
(-h|--help|help)
|
||||
echo $usage_t
|
||||
;;
|
||||
(*)
|
||||
echo $usage_t
|
||||
return 20
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
(-h|--help|help)
|
||||
echo $usage
|
||||
;;
|
||||
(*)
|
||||
echo $usage
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
compdef _omz omz
|
||||
Loading…
Add table
Add a link
Reference in a new issue