-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add functions/each: apply a function on each of the arguments
- Loading branch information
1 parent
8ed1984
commit 98862c9
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# Apply a function on each of the arguments | ||
# | ||
# $ each cmd arg1 arg2 | ||
# equivalent to | ||
# $ cmd arg1 | ||
# $ cmd arg2 | ||
# | ||
# -- is used to mark end of options | ||
# | ||
# $ each cnd opt -- arg1 arg2 | ||
# equivalent to | ||
# $ cmd opt arg1 | ||
# $ cmd opt arg2 | ||
# | ||
# For further usage, please consider zargs command | ||
# | ||
# Add the following line for auto-completion: | ||
# _comps[each]=_precommand | ||
|
||
local -i iargs=${@[(ie)--]} ecmd=1 | ||
local args= | ||
if (( $iargs > $# )); then | ||
iargs=1 | ||
else | ||
ecmd=iargs-1 | ||
if (( $iargs > 2 )); then | ||
args="${(q)${@[2,$ecmd]}}" | ||
fi | ||
fi | ||
|
||
for f in $@[$iargs+1,-1]; do | ||
eval "$1 $args ${(q)f}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters