add yaml module, refactor path and helpers for isAbsPath
parent
c8940fb4ea
commit
3a5d3eba1c
|
@ -1,10 +1,10 @@
|
|||
#!/bin/bash
|
||||
# must be json as a string, depends on jq
|
||||
get_prop_value () {
|
||||
local value
|
||||
# echo in $1 get $2
|
||||
value=$(echo $1 | jq -r .$2)
|
||||
echo $value
|
||||
local value
|
||||
# echo in $1 get $2
|
||||
value=$(echo $1 | jq -r .$2)
|
||||
echo $value
|
||||
}
|
||||
|
||||
is_array() {
|
||||
|
@ -13,20 +13,22 @@ is_array() {
|
|||
}
|
||||
|
||||
filename() {
|
||||
# passed entire path
|
||||
echo $(basename "$1" | rev | cut -f 2- -d '.' | rev)
|
||||
# passed entire path
|
||||
echo $(basename "$1" | rev | cut -f 2- -d '.' | rev)
|
||||
}
|
||||
|
||||
adirname() {
|
||||
# passed entire path
|
||||
echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )"
|
||||
# passed entire path
|
||||
echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )"
|
||||
}
|
||||
|
||||
|
||||
|
||||
chmod_dirs() {
|
||||
# passed entire path
|
||||
local usesudo
|
||||
[[ $1 == -s ]] && usesudo="sudo" && shift 2
|
||||
$usesudo find $1 -type f -exec chmod $2 {} +
|
||||
# passed entire path
|
||||
local usesudo
|
||||
[[ $1 == -s ]] && usesudo="sudo" && shift 2
|
||||
$usesudo find $1 -type f -exec chmod $2 {} +
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
# get full absolute bath from a current or parent path
|
||||
function abs-path {
|
||||
local target="$1"
|
||||
if [ "$target" == "." ]; then
|
||||
echo "$(pwd)"
|
||||
elif [ "$target" == ".." ]; then
|
||||
elif [ "$target" == ".." ]; then
|
||||
echo "$(dirname "$(pwd)")"
|
||||
else
|
||||
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
||||
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);
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
Loading…
Reference in New Issue