2020-05-11 01:56:27 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-04-06 05:07:59 +00:00
|
|
|
#
|
|
|
|
# Stage the selected file to git bare repo
|
|
|
|
#
|
|
|
|
# @params
|
|
|
|
# Globals
|
2020-04-07 06:51:07 +00:00
|
|
|
# ${mydir}: string, current directory of the executing script
|
2020-05-15 08:50:26 +00:00
|
|
|
# ${stage_type}: modified, new file, or directory to stage
|
|
|
|
# ${selected_files}: user selected files to stage
|
2020-04-24 07:26:45 +00:00
|
|
|
# Arguments
|
|
|
|
# -h: show help message
|
|
|
|
# -f: select a file in PWD to stage
|
|
|
|
# -d: select a directory in PWD to stage
|
2020-04-06 05:07:59 +00:00
|
|
|
|
2020-04-10 05:05:33 +00:00
|
|
|
set -e
|
2020-04-17 07:55:22 +00:00
|
|
|
set -f
|
2020-04-10 05:05:33 +00:00
|
|
|
|
2020-05-13 07:30:54 +00:00
|
|
|
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2020-04-14 07:17:42 +00:00
|
|
|
source "${mydir}"/../helper/search_file.sh
|
|
|
|
source "${mydir}"/../helper/set_variable.sh
|
2020-04-16 05:43:33 +00:00
|
|
|
source "${mydir}"/../helper/git_query.sh
|
2020-04-07 04:45:58 +00:00
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo -e "Usage: dotbare fadd [-h] [-f] [-d] ...\n"
|
|
|
|
echo -e "Stage the selected file to the dotfile gitbare repo"
|
|
|
|
echo -e "Press escape to stop staging file\n"
|
|
|
|
echo -e "optional arguments:"
|
2020-05-10 22:52:06 +00:00
|
|
|
echo -e " -h\tshow this help message and exit"
|
|
|
|
echo -e " -f\tselect a file in current directory and stage it"
|
|
|
|
echo -e " -d\tselect a entire folder to stage"
|
2020-04-07 04:45:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 07:26:45 +00:00
|
|
|
#######################################
|
|
|
|
# stage file
|
|
|
|
# Arguments:
|
|
|
|
# $1: files to stage
|
|
|
|
#######################################
|
2020-04-06 05:07:59 +00:00
|
|
|
function stage_file() {
|
|
|
|
local file=$1
|
2020-05-15 08:50:26 +00:00
|
|
|
if [[ -z "${file}" ]]; then
|
2020-05-13 00:39:10 +00:00
|
|
|
exit 1
|
2020-04-06 05:07:59 +00:00
|
|
|
else
|
2020-04-17 07:55:22 +00:00
|
|
|
# shellcheck disable=SC2086
|
2020-04-17 06:50:56 +00:00
|
|
|
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" add ${file}
|
2020-04-06 05:07:59 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-15 08:50:26 +00:00
|
|
|
stage_type="modified"
|
2020-04-06 05:07:59 +00:00
|
|
|
|
|
|
|
while getopts ":fhd" opt
|
|
|
|
do
|
|
|
|
case "$opt" in
|
|
|
|
f)
|
2020-05-15 08:50:26 +00:00
|
|
|
stage_type="file"
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
stage_type="dir"
|
2020-04-06 05:07:59 +00:00
|
|
|
;;
|
|
|
|
h)
|
2020-04-07 04:45:58 +00:00
|
|
|
usage
|
2020-04-06 05:07:59 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid option: ${OPTARG}" >&2
|
2020-04-07 04:45:58 +00:00
|
|
|
usage
|
2020-04-06 05:07:59 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-05-15 08:50:26 +00:00
|
|
|
if [[ "${stage_type}" == "file" ]]; then
|
|
|
|
selected_files=$(search_file 'f' | tr '\n' ' ')
|
|
|
|
elif [[ "${stage_type}" == "dir" ]]; then
|
|
|
|
selected_files=$(search_file 'd' | tr '\n' ' ')
|
2020-04-06 05:07:59 +00:00
|
|
|
else
|
2020-04-21 04:50:51 +00:00
|
|
|
selected_files=$(get_modified_file 'select files to stage' "unstaged" | tr '\n' ' ')
|
2020-04-06 05:07:59 +00:00
|
|
|
fi
|
2020-05-15 08:50:26 +00:00
|
|
|
stage_file "${selected_files}"
|