2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-17 21:25:32 +00:00
dotbare/scripts/fstat
2020-04-24 16:21:41 +10:00

49 lines
1.4 KiB
Bash
Executable File

#!/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
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 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