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:
Marc Cornellà 2014-06-08 13:08:40 +02:00
commit f74c8b2941
5 changed files with 57 additions and 62 deletions

View file

@ -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 } <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'
ls list available plugins
on <name> enable a plugin
off <name> disable a plugin
up <name> update a plugin
get <git-url> <name> download 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'
ls list available themes
set <name> set a theme
up <name> update a theme
get <git-url> <name> 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