2020-04-21 05:25:02 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# interactive git status menu
|
2020-04-21 06:07:23 +00:00
|
|
|
# allow staging ustaging actions
|
2020-04-21 05:25:02 +00:00
|
|
|
#
|
|
|
|
# @params
|
|
|
|
# Globals
|
2020-04-24 06:02:29 +00:00
|
|
|
# ${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
|
2020-05-07 02:08:07 +00:00
|
|
|
# Arguments
|
|
|
|
# -h: show help message and exit
|
2020-04-21 05:25:02 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
set -f
|
|
|
|
|
|
|
|
mydir="${0%/*}"
|
|
|
|
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"
|
2020-04-24 06:21:41 +00:00
|
|
|
echo -e "Stage, unstage, interactively\n"
|
2020-04-21 05:25:02 +00:00
|
|
|
echo -e "optional arguments:"
|
|
|
|
echo -e " -h\t\tshow this help message and exit"
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:08:07 +00:00
|
|
|
while getopts ":h" opt; do
|
|
|
|
case "$opt" in
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid option: ${OPTARG}" >&2
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-04-21 05:25:02 +00:00
|
|
|
while true; do
|
2020-04-21 06:42:00 +00:00
|
|
|
selected_files=$(get_modified_file "select a file" "all" "raw")
|
2020-04-21 05:25:02 +00:00
|
|
|
[[ -z "${selected_files}" ]] && break
|
2020-04-24 06:02:29 +00:00
|
|
|
# check if current operation should stage file or unstage file
|
2020-04-21 06:42:00 +00:00
|
|
|
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
|
2020-04-21 06:07:23 +00:00
|
|
|
# shellcheck disable=SC2086
|
2020-04-21 06:42:00 +00:00
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset --quiet HEAD ${selected_files}
|
2020-04-21 06:07:23 +00:00
|
|
|
else
|
|
|
|
# shellcheck disable=SC2086
|
2020-04-21 06:42:00 +00:00
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" add ${selected_files}
|
2020-04-21 06:07:23 +00:00
|
|
|
fi
|
2020-04-21 05:25:02 +00:00
|
|
|
done
|