Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ format by "shfmt" and refactory $1 #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 46 additions & 44 deletions dotbare
Original file line number Diff line number Diff line change
Expand Up @@ -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] ...

Expand Down Expand Up @@ -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}" "$@"