diff --git a/dotbare b/dotbare index f573a83..3041b3b 100755 --- a/dotbare +++ b/dotbare @@ -12,9 +12,6 @@ # option flags: # check sub commands for available option flags -mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${mydir}"/helper/set_variable.sh - function usage() { echo -e "Usage: dotbare [-h] [-v] [COMMANDS] [OPTIONS] ... @@ -43,64 +40,69 @@ Available commands: } function list_dotbare_commands() { - find "${mydir}"/scripts/* -type f -print0 \ - | xargs -I __ -0 basename __ \ - | fzf --no-multi --header='Available commands' --preview="${mydir}/dotbare {} -h" \ - | xargs -I __ "${mydir}"/dotbare __ -h + find "${mydir}"/scripts/ -type f -print0 | + xargs -I __ -0 basename __ | + fzf --no-multi --header='Available commands' --preview="${mydir}/dotbare {} -h" | + xargs -I __ "${mydir}"/dotbare __ -h } function execute_dotbare() { - [[ "$#" -eq 0 ]] \ - && list_dotbare_commands \ - && exit 0 + [[ "$#" -eq 0 ]] && + list_dotbare_commands && + exit 0 if [[ -x "${mydir}/scripts/$1" ]]; then exec "${mydir}/scripts/$1" "${@:2}" fi } +mydir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${mydir}"/helper/set_variable.sh + # if no argument, display all possible actions if [[ "$#" -eq 0 ]]; then list_dotbare_commands exit 0 fi -[[ "$*" == 'add --all' ]] && \ - echo 'If you intend to stage all modified file, run dotbare add -u' && \ - echo "dotbare disabled add --all option as this will stage every single file in ${DOTBARE_TREE}" && \ - exit 1 - case "$1" in - --help|-h) - usage - exit 0 - ;; - -v|--version) - echo "Current dotbare version: ${DOTBARE_VERSION}" - exit 0 - ;; - -g|--git) - if git rev-parse --is-inside-work-tree &>/dev/null; then - DOTBARE_TREE=$(git rev-parse --show-toplevel) - DOTBARE_DIR="${DOTBARE_TREE}/.git" - shift - case "$1" in - fbackup|finit|fupgrade) - echo "dotbare $1 is not supported when using dotbare as a generic fuzzy git tool" >&2 - exit 1 - ;; - *) - execute_dotbare "$@" - ;; - esac - else - echo "Not in a git directory" >&2 +add) + if [[ "$2" == '--all' ]]; then + echo 'If you intend to stage all modified file, run dotbare add -u' + echo "dotbare disabled add --all option as this will stage every single file in ${DOTBARE_TREE}" + exit 1 + fi + ;; +-h | --help) + usage + exit 0 + ;; +-v | --version) + echo "Current dotbare version: ${DOTBARE_VERSION}" + exit 0 + ;; +-g | --git) + if git rev-parse --is-inside-work-tree &>/dev/null; then + DOTBARE_TREE=$(git rev-parse --show-toplevel) + DOTBARE_DIR="${DOTBARE_TREE}/.git" + shift + case "$1" in + fbackup | finit | fupgrade) + echo "dotbare $1 is not supported when using dotbare as a generic fuzzy git tool" >&2 exit 1 - fi - ;; - *) - execute_dotbare "$@" - ;; + ;; + *) + execute_dotbare "$@" + ;; + esac + else + echo "Not in a git directory" >&2 + exit 1 + fi + ;; +*) + execute_dotbare "$@" + ;; esac git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" "$@"