diff options
-rwxr-xr-x | conf | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -37,12 +37,12 @@ PROGRAM_NAME=${0} MODE="normal" function err { - echo "${1}" >&2 + echo -e "${1}" >&2 exit 1 } function warn { - echo "${1}" >&2 + echo -e "${1}" >&2 } function echo_if_test { @@ -52,15 +52,17 @@ function echo_if_test { } function add { + [ $# -lt 1 ] && grep ")\ #a" "${PROGRAM_NAME}" | sed -e 's/^[[:space:]]*//' -e 's:) \#a: :g'; return 0 + GROUP=${DEF_GROUP} for arg in "$@"; do [[ "$arg" == "-t" ]] && MODE="test" done - + while [ $# -gt 0 ]; do case ${1} in - -g) + -g) #a add next file to group GROUP="${2}" shift shift @@ -69,17 +71,21 @@ function add { GROUP="${1/-g/}" shift ;; - -t) + -t) #a do a test run shift ;; - *) + -h) #a print this help + grep ")\ #a" "${PROGRAM_NAME}" | sed -e 's/^[[:space:]]*//' -e 's:) \#a: :g' + return 0 + ;; + *) #a path to file [ ! -f "${1}" ] && err "${1} is not a file" [ -L "${1}" ] && err "${1} is a symlink" SRC="$(realpath "${1}")" shift DST="${CONF_HOME}/${GROUP}${SRC/${HOME}/${HOME_SUB}}" ## CHANGE echo_if_test "${SRC} -> ${DST}" - [ "${MODE}" != "test" ] && mkdir -p "$(dirname "${DST}")" && mv "${SRC}" "${DST}" && ln -s "${DST}" "${SRC}" + [ "${MODE}" != "test" ] && mkdir -p "$(dirname "${DST}")" && mv "${SRC}" "${DST}" && ln -s "${DST}" "${SRC}" esac done } @@ -131,6 +137,7 @@ function search { } function edit { + [ $# -ne 1 ] && err "Specify entry to edit:\n <basename>\n <group>\n <group>:<basename>" declare -A configs for group in "${CONF_HOME}"/*; do @@ -150,7 +157,7 @@ function edit { [ ${#matched[@]} -eq 1 ] && [ "${TERM}" == "dumb" ] && echo "${matched[0]}" && return 0 [ ${#matched[@]} -eq 1 ] && ${EDITOR} "${matched[0]}" && return 0 [ ${#matched[@]} -gt 1 ] && warn "Too many files, specify" && list -g "${1}" && return 1 - + matched=() for c in "${!configs[@]}"; do if [ "${c/*:/}" == "$1" ]; then @@ -168,7 +175,7 @@ function edit { ${EDITOR} "${configs[$c]}" && return 0 fi done - + echo "${1} - no match" return 1 } @@ -185,7 +192,7 @@ function printhelp { if [ $# -lt 1 ] then printhelp -fi +fi case ${1} in add | a) ## add a file @@ -205,6 +212,7 @@ case ${1} in edit "$@" ;; relink) ## relink managed files + shift relink "$@" ;; version | --version | -v | -V) |