bash-utils/shtpl/shtpl

48 lines
618 B
Plaintext
Raw Normal View History

2018-10-09 16:54:38 +02:00
#!/bin/bash
2019-03-02 21:12:33 +01:00
# Utils
__shtpl_path__=$(realpath $0)
__shtpl_dir__=$(dirname $0)
__tpl_path__=$(realpath $1)
__tpl_name__=$(basename $__tpl_path__)
__tpl_dir__=$(dirname $__tpl_path__)
2019-07-26 13:03:48 +02:00
# 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'
}
2019-03-02 21:12:33 +01:00
# Execution
2018-10-09 16:54:38 +02:00
eval "echo \"$(cat $1 | sed '
2019-03-02 21:12:33 +01:00
# Suppress hashbang
2018-10-09 16:54:38 +02:00
1{ /#\!.*shtpl/ d }
2019-03-02 21:12:33 +01:00
# Excape quotes
2018-10-09 16:54:38 +02:00
s/"/\\"/g
')\""