You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dotbare/dotbare

77 lines
3.0 KiB
Plaintext

4 years ago
#!/usr/bin/env bash
#
# Main entry script for dotbare, used to route command to appropriate scripts
#
# @params
# Globals
# ${mydir}: string, directory of the executing script, used for sourcing helpers
# Arguments
# action_command: sub commands dotbare should run
# General git command: log, status etc
# dotbare specific commands: fadd | frm | fpop | freset | fcheckout | help etc
# option flags:
# check sub commands for available option flags
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${mydir}"/helper/set_variable.sh
4 years ago
function usage() {
echo -e "Usage: dotbare [-h] [-v] [COMMANDS] [OPTIONS] ...\n"
echo -e "Interactively manage dotfiles with the help of fzf and git bare repo"
echo -e "To see all dotbare specific COMMANDS, run dotbare without any arguments\n"
echo -e "dotbare is just a wrapper around git hence all git commands will function"
echo -e "normally, just replace git with dotbare (e.g. dotbare commit -m 'message')."
echo -e "dotbare added couple useful scripts starting with 'f' prefix to help you"
echo -e "manage your interact with your git bare repo a little easier with the help of fzf\n"
echo -e "optional arguments:"
echo -e " -h, --help\t\tshow this help message and exit"
echo -e " -v, --version\t\tshow dotbare current version"
echo -e "Available commands:"
echo -e " Any git commands, treat dotbare as git"
echo -e " fadd \t\tstage modified file interactively"
echo -e " freset \t\tunstage file or reset commit interactively"
echo -e " funtrack \t\tuntrack file interactively"
echo -e " fstash \t\tmanage stash interactively"
echo -e " fcheckout \t\tcheckout branch/files/commits interactively"
echo -e " fstat \t\tstage/unstage interactively"
echo -e " fedit \t\tselect files/commits and edit interactively"
echo -e " flog \t\tmanage commits interactively"
echo -e " fbackup \t\tperform backup for tracked dotfiles"
echo -e " fupgrade \t\tupdate dotbare to the latest version"
echo -e " finit \t\tinitialise/migrate dotbare"
}
# if no argument, display all possible actions
if [[ "$#" -eq 0 ]]; then
find "${mydir}"/scripts/* -type f -print0 \
| xargs -I __ -0 basename __ \
| fzf --no-multi --header='Available commands' --preview="dotbare {} -h" \
| xargs -I __ dotbare __ -h
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)
4 years ago
cd "${mydir}" || exit
dotbare_version=$(git describe --tags "$(git rev-list --tags --max-count=1)")
printf "Current dotbare version: %s\n" "${dotbare_version}"
exit 0
;;
*)
if [[ -x "${mydir}/scripts/$1" ]]; then
exec "${mydir}/scripts/$1" "${@:2}"
fi
;;
esac
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" "$@"