Skip to content

Instantly share code, notes, and snippets.

@wayneeseguin
Forked from mpapis/template_.conf
Created May 30, 2011 14:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayneeseguin/998974 to your computer and use it in GitHub Desktop.
Save wayneeseguin/998974 to your computer and use it in GitHub Desktop.
templates on bdsm
a={{a}}
b={{b}}
c={{c}}
d={{d}}
e={{e}}
case $target in
template_a.conf)
replacements=(
a "b a"
d e
".*" ""
)
;;
*)
echo "no settings for $target"
;;
esac
#!/bin/bash
source "/usr/local/bdsm/modules/bash/core/initialize" # Load BDSM framework
modules templates
action=$1
shift
usage(){
echo "Usage:
$0 list #show available templates
$0 list all #show available templates with generated files
$0 list [template name] #show generated files for given template
$0 apply [target file name] #apply template on the given file
"
}
list_template() {
local template="$1"
local settings="$template.settings"
echo "Template: $template"
if [[ -f $settings ]]
then
echo "Template settings: $template.settings"
else
echo "Template settings are missing: $template.settings"
fi
if [[ "$2" == "generated" ]]
then
find ${template/_./_\*.} -not -name $template
fi
}
list_all() {
local template
for template in *_.*
do
list_template "$template" "$1"
done
}
apply(){
target="${1}"
template="${1/_*./_.}"
settings="${template}.settings"
. $settings
cp -f $template $target
seed_template $target "${replacements[@]}"
unset $replacements
}
less_diff(){
target="${1}"
target_new="${1}.new"
template="${1/_*./_.}"
settings="${template}.settings"
. $settings
cp -f $template $target_new
seed_template $target_new "${replacements[@]}"
diff -u $target $target_new | less
rm -rf $target_new
unset $replacements
}
case "$action" in
list)
case "x$1" in
xall)
list_all generated
;;
x)
list_all
;;
*)
list_template "$1" generated
;;
esac
;;
apply)
apply "$@"
;;
diff)
less_diff "$@"
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment