48 lines
618 B
Bash
Executable File
48 lines
618 B
Bash
Executable File
#!/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__)
|
|
|
|
|
|
# Broken, don't use!
|
|
pipe()
|
|
{
|
|
[[ ! -t 0 ]] && cat
|
|
}
|
|
|
|
user-input()
|
|
{
|
|
echo "$@ (ctrl-D): " 1>&2
|
|
res="$(sed '/^\04$/q')"
|
|
echo "$res"
|
|
}
|
|
|
|
lowerCase()
|
|
{
|
|
( [[ ! -z "$@" ]] && echo $@ || cat ) | awk '{print tolower($0)}'
|
|
}
|
|
|
|
slug()
|
|
{
|
|
( [[ ! -z "$@" ]] && echo $@ || cat ) | lowerCase | sed 's/[^a-zA-Z0-9-]/_/g'
|
|
}
|
|
|
|
|
|
|
|
# Execution
|
|
|
|
eval "echo \"$(cat $1 | sed '
|
|
# Suppress hashbang
|
|
1{ /#\!.*shtpl/ d }
|
|
# Excape quotes
|
|
s/"/\\"/g
|
|
')\""
|
|
|
|
|