2020-04-06 05:07:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# 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-04-06 05:07:59 +00:00
|
|
|
# ${new_file}: new file path to stage
|
|
|
|
# ${new_folder}: new folder to stage
|
|
|
|
# ${stage_file}: changed file to stage
|
|
|
|
|
2020-04-10 05:05:33 +00:00
|
|
|
set -e
|
|
|
|
|
2020-04-07 05:29:09 +00:00
|
|
|
mydir="${0%/*}"
|
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:"
|
|
|
|
echo -e " -h\t\tshow this help message and exit"
|
|
|
|
echo -e " -f\t\tselect a file in current directory and stage it"
|
|
|
|
echo -e " -d\t\tselect a entire folder to stage"
|
|
|
|
}
|
|
|
|
|
2020-04-06 05:07:59 +00:00
|
|
|
function stage_file() {
|
|
|
|
local file=$1
|
|
|
|
if [[ -z "${file}" ]]
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
else
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
new_file=''
|
|
|
|
new_folder=''
|
|
|
|
|
|
|
|
while getopts ":fhd" opt
|
|
|
|
do
|
|
|
|
case "$opt" in
|
|
|
|
f)
|
2020-04-17 06:50:56 +00:00
|
|
|
new_file=$(search_file 'f' | tr '\n' ' ')
|
2020-04-06 05:07:59 +00:00
|
|
|
[[ -z "${new_file}" ]] && exit 1
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
h)
|
2020-04-07 04:45:58 +00:00
|
|
|
usage
|
2020-04-06 05:07:59 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
d)
|
2020-04-17 06:50:56 +00:00
|
|
|
new_folder=$(search_file 'd' | tr '\n' ' ')
|
2020-04-06 05:07:59 +00:00
|
|
|
[[ -z "${new_folder}" ]] && exit 1
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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
|
|
|
|
|
|
|
|
if [[ -n "${new_file}" ]]; then
|
2020-04-17 06:50:56 +00:00
|
|
|
stage_file "${new_file}"
|
2020-04-06 05:07:59 +00:00
|
|
|
elif [[ -n "${new_folder}" ]]; then
|
2020-04-17 06:50:56 +00:00
|
|
|
stage_file "${new_folder}"
|
2020-04-06 05:07:59 +00:00
|
|
|
else
|
2020-04-17 06:50:56 +00:00
|
|
|
selected_files=$(get_modified_file 'select files to stage' | tr '\n' ' ')
|
|
|
|
stage_file "${selected_files}"
|
2020-04-06 05:07:59 +00:00
|
|
|
fi
|