Skip to content

Instantly share code, notes, and snippets.

@xevz
Created January 19, 2010 01:29
Show Gist options
  • Save xevz/280566 to your computer and use it in GitHub Desktop.
Save xevz/280566 to your computer and use it in GitHub Desktop.
map function for zsh
# From http://www.reddit.com/r/linux/comments/akt3j/a_functional_programming_style_map_function_for/
# Modified to work in zsh.
function map() {
local command i rep
if [ $# -lt 2 ] || [[ ! "$@" =~ :[[:space:]] ]];then
echo "Invalid syntax." >&2; return 1
fi
until [[ $1 =~ : ]]; do
command="$command $1"; shift
done
command="$command ${1%:}"; shift
for i in "$@"; do
if [[ $command =~ \\{\\} ]];then
rep="${command//\{\}/\"$i\"}"
eval "${rep//\\/\\\\}"
else
eval "${command//\\/\\\\} \"${i//\\/\\\\}\""
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment