mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-27 03:05:39 +01:00
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.
This commit is contained in:
parent
393eed5e67
commit
f74c8b2941
5 changed files with 57 additions and 62 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue