mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-20 03:02:29 +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
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue