#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2018 Christopher Bratusek		#
#							#
#########################################################

# by downdiagonal

case ${1} in

	--help | -h | "")
		bashstyle-help -a "downdiagonal" -e "" -h "http://www.commandlinefu.com/"\
			-l "Public Domain" -n "map" -s "run a command on given files or directories" -v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
			-o "command:|command to map"\
			-o " -- :|end of command"\
			-o "files:|list of files or directories"
	;;

	* )
		if [ $# -lt 2 ] || [[ ! "$*" =~ [[:space:]]--[[:space:]] ]];then
			echo "Invalid syntax." >&2; exit 1
		fi

		until [[ $1 =~ -- ]]; do
			command="$command $1"; shift
		done

		command="$command ${1%:}"; shift
		for i in "$@"; do
			eval "${command//\\/\\\\} \"${i//\\/\\\\}\""
		done
	;;

esac
