From 0dfc76bd1a1f176cc21a70c8846d2590f166c5a8 Mon Sep 17 00:00:00 2001 From: dig Date: Sat, 2 Mar 2019 21:12:33 +0100 Subject: [PATCH] Added shtpl installer, path variables --- shtpl/exemple/foo/other.shtpl | 15 +++++++++++++++ shtpl/exemple/templates-path.shtpl | 20 ++++++++++++++++++++ shtpl/install | 6 ++++++ shtpl/shtpl | 17 ++++++++++++++--- shtpl/{ => tests}/test.sh | 0 shtpl/{ => tests}/test.shtpl | 0 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100755 shtpl/exemple/foo/other.shtpl create mode 100755 shtpl/exemple/templates-path.shtpl create mode 100755 shtpl/install rename shtpl/{ => tests}/test.sh (100%) rename shtpl/{ => tests}/test.shtpl (100%) diff --git a/shtpl/exemple/foo/other.shtpl b/shtpl/exemple/foo/other.shtpl new file mode 100755 index 0000000..ec6f4be --- /dev/null +++ b/shtpl/exemple/foo/other.shtpl @@ -0,0 +1,15 @@ +#!/usr/bin/env shtpl +SHTPL path: +$__shtpl_path__ +SHTPL dir: +$__shtpl_dir__ + +Current template path: +$__tpl_path__ +Current template dir: +$__tpl_dir__ +Current template filename: +$__tpl_name__ + +Current working dir: +$(pwd) diff --git a/shtpl/exemple/templates-path.shtpl b/shtpl/exemple/templates-path.shtpl new file mode 100755 index 0000000..0279037 --- /dev/null +++ b/shtpl/exemple/templates-path.shtpl @@ -0,0 +1,20 @@ +#!/usr/bin/env shtpl +SHTPL path: +$__shtpl_path__ +SHTPL dir: +$__shtpl_dir__ + +Current template path: +$__tpl_path__ +Current template dir: +$__tpl_dir__ +Current template filename: +$__tpl_name__ + +Current working dir: +$(pwd) + +Sub template +------------ + +$($__tpl_dir__/shtpl/B.shtpl) diff --git a/shtpl/install b/shtpl/install new file mode 100755 index 0000000..3142476 --- /dev/null +++ b/shtpl/install @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +from=$(pwd)/$(dirname "$0") +to=/usr/local/bin + +cp $from/shtpl $to/shtpl diff --git a/shtpl/shtpl b/shtpl/shtpl index 48a7270..d79168c 100755 --- a/shtpl/shtpl +++ b/shtpl/shtpl @@ -1,11 +1,22 @@ #!/bin/bash + +# Utils + +__shtpl_path__=$(realpath $0) +__shtpl_dir__=$(dirname $0) +__tpl_path__=$(realpath $1) +__tpl_name__=$(basename $__tpl_path__) +__tpl_dir__=$(dirname $__tpl_path__) + + +# Execution + eval "echo \"$(cat $1 | sed ' +# Suppress hashbang 1{ /#\!.*shtpl/ d } +# Excape quotes s/"/\\"/g ')\"" -#eval "echo \"$(perl -p -e 's/"/\\"/g' $1)\"" - - diff --git a/shtpl/test.sh b/shtpl/tests/test.sh similarity index 100% rename from shtpl/test.sh rename to shtpl/tests/test.sh diff --git a/shtpl/test.shtpl b/shtpl/tests/test.shtpl similarity index 100% rename from shtpl/test.shtpl rename to shtpl/tests/test.shtpl