2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-17 21:25:32 +00:00
dotbare/scripts/fstat
2020-05-19 18:01:01 +10:00

65 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# interactive git status menu
# allow staging ustaging actions
#
# @params
# Globals
# ${mydir}: current directory of where the script is running
# ${selected_files}: selected file to stage or unstage
# ${stage_file}: determine if current operation should be staging file or unstage
# Arguments
# -h: show help message and exit
set -e
set -f
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/git_query.sh
function usage() {
echo -e "Usage: dotbare fstat [-h] ...\n"
echo -e "Display interactive git status menu"
echo -e "Stage, unstage, interactively\n"
echo -e "optional arguments:"
echo -e " -h\t\tshow this help message and exit"
}
while getopts ":h" opt; do
case "$opt" in
h)
usage
exit 0
;;
*)
echo "Invalid option: ${OPTARG}" >&2
usage
exit 1
;;
esac
done
while :; do
selected_files=$(get_modified_file "select a file" "all" "raw")
[[ -z "${selected_files}" ]] && break
# check if current operation should stage file or unstage file
stage_file=$(echo "${selected_files}" | awk '{
if ($0 ~ /^[A-Za-z][A-Za-z].*$/) {
print "stage"
} else if ($0 ~ /^[ \t].*$/) {
print "stage"
}
}')
selected_files=$(echo "${selected_files}" | awk -v home="${DOTBARE_TREE}" '{
print home "/" $2
}')
if [[ -z "${stage_file}" ]]; then
# shellcheck disable=SC2086
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset --quiet HEAD ${selected_files}
else
# shellcheck disable=SC2086
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" add ${selected_files}
fi
done