2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-16 00:12:47 +00:00
dotbare/scripts/fstat

65 lines
1.7 KiB
Plaintext
Raw Normal View History

2020-05-11 01:56:27 +00:00
#!/usr/bin/env bash
2020-04-21 05:25:02 +00:00
#
# 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
2020-05-13 07:30:54 +00:00
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2020-04-21 05:25:02 +00:00
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:"
2020-05-19 08:01:01 +00:00
echo -e " -h\t\tshow this help message and exit"
2020-04-21 05:25:02 +00:00
}
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-05-17 11:20:57 +00:00
while :; 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