Refactor all hardcoded path to a global variable - dossier - console collection manager DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit a87cfd2eb3afd656374608c40600ff9ede81666a DIR parent ea62d1528ab0c37f7bd1e1a6783a1d1a3fbecfbc HTML Author: Solene Rapenne <solene@perso.pw> Date: Tue, 24 Jul 2018 09:59:25 +0200 Refactor all hardcoded path to a global variable Diffstat: M cdb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) --- DIR diff --git a/cdb b/cdb @@ -1,11 +1,12 @@ #!/bin/sh -mkdir -p ~/.collections -test -f ~/.collections/current && . ~/.collections/current +REPOSITORY="${HOME}/.collections" +mkdir -p "$REPOSITORY" +test -f "${REPOSITORY}/current" && . "${REPOSITORY}/current" if [ -n "$CONTEXT" ] then - REPO="${HOME}/.collections/${CONTEXT}/" + REPO="${REPOSITORY}/${CONTEXT}/" cd "$REPO" test ! -d ".git" && git init else @@ -207,19 +208,19 @@ usage() { } switch() { - if [ ! -L "${HOME}/.collections/${1}" ] + if [ ! -L "${REPOSITORY}/${1}" ] then printf 'Collection %s is not registered\n' "${1}" exit 9 else printf 'Switching to collection %s\n' "${1}" - printf 'CONTEXT=%s\n' $1 > ~/.collections/current + printf 'CONTEXT=%s\n' $1 > "${REPOSITORY}/current" exit $? fi } collections() { - ls ~/.collections/ | grep -v 'current' | sed "s/^${CONTEXT}$/& */" + ls "${REPOSITORY}" | grep -v 'current' | sed "s/^${CONTEXT}$/& */" exit 0 } @@ -234,8 +235,8 @@ register() { then printf 'Aborting, the path of the collection must be an absolute path. %s is not valid\n' "${1}" fi - test -L "${HOME}/.collections/${2}" && rm "${HOME}/.collections/${2}" - ln -s "${1}" "${HOME}/.collections/${2}" + test -L "${REPOSITORY}/${2}" && rm "${REPOSITORY}/${2}" + ln -s "${1}" "${REPOSITORY}/${2}" exit 0 else printf 'Aborting, %s is not a directory\n' "${2}"