add yaml module, refactor path and helpers for isAbsPath
parent
c8940fb4ea
commit
3a5d3eba1c
|
@ -22,6 +22,8 @@ adirname() {
|
||||||
echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )"
|
echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chmod_dirs() {
|
chmod_dirs() {
|
||||||
# passed entire path
|
# passed entire path
|
||||||
local usesudo
|
local usesudo
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# get full absolute bath from a current or parent path
|
||||||
function abs-path {
|
function abs-path {
|
||||||
local target="$1"
|
local target="$1"
|
||||||
if [ "$target" == "." ]; then
|
if [ "$target" == "." ]; then
|
||||||
|
@ -9,3 +11,13 @@ function abs-path {
|
||||||
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAbsPath() {
|
||||||
|
if [[ "${1:0:1}" == / || "${1:0:2}" == ~[/a-z] ]]
|
||||||
|
then
|
||||||
|
echo "true"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# echo loading yaml module
|
||||||
|
# https://gist.github.com/pkuczynski/8665367
|
||||||
|
# read yaml file, second argument (if any) is added prefix
|
||||||
|
parse_yaml() {
|
||||||
|
local prefix=$2
|
||||||
|
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
|
||||||
|
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
|
||||||
|
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
||||||
|
awk -F$fs '{
|
||||||
|
indent = length($1)/2;
|
||||||
|
vname[indent] = $2;
|
||||||
|
for (i in vname) {if (i > indent) {delete vname[i]}}
|
||||||
|
if (length($3) > 0) {
|
||||||
|
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
||||||
|
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
Reference in New Issue