Created
August 28, 2019 13:32
-
-
Save TobleMiner/102146969bc4568a66cd9a20dc0a8aff to your computer and use it in GitHub Desktop.
Simple bash functions for expanding/unexpanding a set of files
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
unexpand_files() { | |
( | |
set -e -o pipefail | |
first_only='--first-only' | |
args='' | |
OPTIND=1 | |
while getopts "at:" opt; do | |
case "$opt" in | |
a) args="$args -a"; first_only='';; | |
t) args="$args -t $OPTARG";; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
for file in $@; do | |
tmpfile="$(mktemp)" | |
unexpand $args $first_only "$file" > "$tmpfile" | |
cp "$tmpfile" "$file" | |
rm "$tmpfile" | |
done | |
) | |
} | |
expand_files() { | |
( | |
set -e -o pipefail | |
initial='-i' | |
args='' | |
OPTIND=1 | |
while getopts "at:" opt; do | |
case "$opt" in | |
a) args="$args -a"; initial='';; | |
t) args="$args -t $OPTARG";; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
for file in $@; do | |
tmpfile="$(mktemp)" | |
expand $args $initial "$file" > "$tmpfile" | |
cp "$tmpfile" "$file" | |
rm "$tmpfile" | |
done | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment