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/scripts/fstat

65 lines
1.6 KiB
Bash

#!/bin/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="${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"
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 true; 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