individual file backup

pull/3/head
kevin zhuang 4 years ago
parent 89632b7e55
commit 0cd614a9e4

@ -68,19 +68,27 @@ function get_branch() {
# let user select a dotbare tracked file interactively
# Arguments:
# $1: the helper message to display in the fzf header
# $2: if exist, don't do multi selection, do single
# $2: print option, values (full|raw)
# $3: if exist, don't do multi selection, do single
# Outputs:
# the selected file path
# e.g.$HOME/.config/nvim/init.vim
#######################################
function get_git_file() {
local header="${1:-select tracked file}"
set_fzf_multi "$2"
local print_opt="${2:-full}"
set_fzf_multi "$3"
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
ls-files --full-name --directory "${DOTBARE_TREE}" \
| fzf --header="${header}" \
--preview "head -50 ${DOTBARE_TREE}/{}" \
| awk -v home="${DOTBARE_TREE}" '{print home "/" $0}'
| awk -v home="${DOTBARE_TREE}" -v print_opt="${print_opt}" '{
if (print_opt == "full") {
print home "/" $0
} else {
print $0
}
}'
}
#######################################

@ -17,9 +17,10 @@ source "${mydir}"/../helper/git_query.sh
function usage() {
echo -e "Usage: dotbare fbackup [-h] ...\n"
echo -e "Backup all tracked files to ${DOTBARE_BACKUP}\n"
echo -e "Backup files to ${DOTBARE_BACKUP}"
echo -e "This is useful when untracking files or migrating on new machines\n"
echo -e "optional arguments:"
echo -e " -h\t\tshow this help message and exit"
echo -e " -h\tshow this help message and exit"
}
#######################################
@ -36,10 +37,31 @@ function dotbare_backup() {
done <<< "${selected_files}"
}
[[ ! -d "${DOTBARE_BACKUP}" ]] && mkdir -p "${DOTBARE_BACKUP}"
individual_file=""
while getopts ":hs" opt; do
case "$opt" in
s)
individual_file='true'
;;
h)
usage
exit 0
;;
*)
echo "Invalid option: ${OPTARG}" >&2
usage
exit 0
;;
esac
done
cd "${DOTBARE_TREE}"
all_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
ls-files --full-name --directory "${DOTBARE_TREE}")
dotbare_backup "${all_files}"
if [[ -n "${individual_file}" ]]; then
selected_files=$(get_git_file "select files to backup" "raw")
else
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
ls-files --full-name --directory "${DOTBARE_TREE}")
fi
dotbare_backup "${selected_files}"

Loading…
Cancel
Save