Last active
April 7, 2016 19:05
-
-
Save RWJMurphy/58600ba58923a9d3c362a2d76001aa18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
function silent() { | |
"$@" >/dev/null 2>&1 | |
} | |
function command_exists() { | |
silent hash "$@" | |
} | |
function not() { | |
! "$@" | |
} | |
function map() { | |
declare -a basecmd cmd | |
declare -i substitution=0 | |
basecmd=("$@") | |
# TODO: make xargs or parallel work with funcs like `silent` :| | |
# if command_exists parallel; then | |
# parallel --keep-order "${basecmd[@]}" | |
# elif command_exists xargs; then | |
# # TODO: detect FreeBSD parallel option | |
# xargs -I{} "${basecmd[@]}" | |
# else | |
if [[ "${cmd[*]}" == "*{}*" ]]; then | |
substitution=1 | |
fi | |
while read line; do | |
if [ $substitution = 1 ]; then | |
cmd=("${basecmd[@]//{}/$line}") | |
else | |
cmd=("${basecmd[@]}" $line) | |
fi | |
"${cmd[@]}" && echo "$line" | |
done | |
# fi | |
} | |
function filter() { | |
map silent "$@" | |
} |
Author
RWJMurphy
commented
Apr 7, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment