diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-10-31 17:23:15 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-10-31 17:23:15 -0200 |
commit | 82e6bce4ea8fc61e99f6eb32dc12c470b93dccd4 (patch) | |
tree | 4b81210f80e8a3e85a1d65b01beb67f92a727066 /share/templater/templater | |
parent | 8e83eb20f8841022cf9a221f2e8447cdba1f7270 (diff) | |
download | templater-82e6bce4ea8fc61e99f6eb32dc12c470b93dccd4.tar.gz templater-82e6bce4ea8fc61e99f6eb32dc12c470b93dccd4.tar.bz2 |
New module format
Diffstat (limited to 'share/templater/templater')
-rw-r--r-- | share/templater/templater/description | 1 | ||||
-rw-r--r-- | share/templater/templater/functions | 83 | ||||
-rwxr-xr-x | share/templater/templater/setup | 26 |
3 files changed, 110 insertions, 0 deletions
diff --git a/share/templater/templater/description b/share/templater/templater/description new file mode 100644 index 0000000..fb01518 --- /dev/null +++ b/share/templater/templater/description @@ -0,0 +1 @@ +Templater module skeleton diff --git a/share/templater/templater/functions b/share/templater/templater/functions new file mode 100644 index 0000000..af6be08 --- /dev/null +++ b/share/templater/templater/functions @@ -0,0 +1,83 @@ +#!/bin/bash +# +# Templater basic functions. +# + +# Initialize project +function __templater_init { + if [ ! -d "$PROJECT" ]; then + __templater_echo "Initializing $PROJECT..." + mkdir -p $PROJECT + fi +} + +# Read a parameter from user +function __templater_ask { + local input + local function="$1" + local default="n" + shift 2 + + read -rep "Setup $function? (defaults to $default): " input + + if [ "$input" == "y" ]; then + templater_$function + fi +} + +# Return list of implementations +function __templater_implementations { + # Do not sort this list: the order in which functions are present in the code is important + #grep "^function templater_" $PROGRAM | cut -d ' ' -f 2 | sed -e 's/templater_//' + ls $SHARE +} + +# Message +function __templater_echo { + #echo "" + echo "-> $*" +} + +# Checkout to develop branch if available +function __templater_checkout_develop { + if git branch --list develop | grep -q develop; then + git checkout develop + fi +} + +# Copy or append source file into destination +function __templater_copy_or_append { + local implementation="$1" + local file="$2" + + if [ -z "$file" ]; then + return + fi + + if [ ! -e "$file" ]; then + cp $SHARE/$implementation/files/$file . + elif ! grep -q -f $SHARE/$implementation/files/$file $file; then + cat $SHARE/$implementation/files/$file >> $file + fi +} + +# Read a parameter from user +function __templater_user_input { + local input + local param="$1" + local default="$2" + shift 2 + + if echo $param | grep -q 'passwd'; then + read -s -rep "$* (defaults to $default): " input + else + read -rep "$* (defaults to $default): " input + fi + + if [ -z "$input" ]; then + export $param="$default" + else + export $param="$input" + fi +} + diff --git a/share/templater/templater/setup b/share/templater/templater/setup new file mode 100755 index 0000000..ebc7cf4 --- /dev/null +++ b/share/templater/templater/setup @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Templater Module templater module. +# + +# Parameters +SHARE="$1" + +# Include basic functions +source $SHARE/templater/functions || exit 1 + +# Templater module +function templater_templater { + if [ ! -e "description" ]; then + __templater_echo "Setting Templater Module" + + touch setup description + chmod +x description + mkdir files + else + __templater_echo "Templater Module already set" + fi +} + +# Dispatch +templater_templater |