repo: actpub action: blob revision: path_from: self revision_from: refs/heads/master: path_to: revision_to:
blob of:
/ self
refs/heads/master:/self
#!/usr/bin/env bash
SELFDIR=~/.config/self
if [ "$1" = "" -o "$1" = "-h" -o "$1" = "--help" ];then
printf 'self <-l|--list>\n' >&2
printf 'self <-i|--init>\n' >&2
printf 'self <-d|--delete> PROPERTY\n' >&2
printf 'self <-g|--get> PROPERTY\n' >&2
printf 'self <-s|--set> PROPERTY VALUE\n' >&2
printf 'self <-s|--set> PROPERTY <<< VALUE\n' >&2
exit 0
fi
if [ "$1" = "-i" -o "$1" = "--init" ];then
if mkdir -p "${SELFDIR}";then
printf 'self directory has been made at %s\n' "${SELFDIR}" >&2
exit 0
else
printf 'self directory creation failed somehow.\n' >&2
exit 1
fi
fi
if [ ! -e "${SELFDIR}" ];then
printf 'self directory (%s) does not exist. use self --init\n' "${SELFDIR}" >&2
exit 1
fi
case "$1" in
-l|--list)
find "${SELFDIR}" -type f -print0 | xargs -n1 -r0 basename | uriunescape
;;
-d|--delete)
shift
property="$(uriescape "$1" | sed 's|/|%2f|g')"
file="${SELFDIR}/${property}"
rm "${file}"
;;
-g|--get)
shift
property="$(printf '%s' "$1")"
property_file="$(uriescape "$1" | sed 's|/|%2f|g')"
file="${SELFDIR}/${property_file}"
if [ ! "${property}" ];then
printf 'missing argument: property\n' >&2
exit 1
fi
if [ ! -e "${file}" ];then
printf 'self property "%s" not found\n' "$property" >&2
exit 1
fi
cat "$file"
;;
-s|--set)
shift
property="$(printf '%s' "$1")"
if [ ! "$property" ];then
printf 'missing argument: property\n' >&2
exit 1
fi
property_file="$(uriescape "$1" | sed 's|/|%2f|g')"
file="${SELFDIR}/${property_file}"
shift
if [ "$*" ];then
printf '%s\n' "$*" > "$file"
else
cat > "$file"
fi
;;
*)
exit 1
;;
esac