2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-02 09:40:27 +00:00
dotbare/scripts/fstash

54 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-04-30 23:44:57 +00:00
#!/bin/bash
#
# stash operation using fzf
#
# @params
# Globals
# None
# Arguments
# None
set -e
set -f
mydir="${0%/*}"
source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/get_confirmation.sh
source "${mydir}"/../helper/git_query.sh
function usage() {
echo -e "Usage: dotbare fstash [-h] [-a] [-b] [-c] ...\n"
echo -e "save/apply stash using fzf\n"
echo -e "optional arguments:"
echo -e " -h\t\tshow this help message and exit"
}
stash_file=""
while getopts ":hf" opt; do
case "$opt" in
f)
stash_file='true'
;;
h)
usage
exit 0
;;
2020-05-01 02:33:00 +00:00
*)
echo "Invalid option: ${OPTARG}" >&2
usage
exit 1
;;
2020-04-30 23:44:57 +00:00
esac
done
2020-05-01 02:33:00 +00:00
if [[ -n "${stash_file}" ]]; then
selected_files=$(get_modified_file "select files to add to a stash")
[[ -z "${selected_files}" ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" stash -- ${selected_files}
else
selected_stash=$(get_stash "select stash to apply")
[[ -z "${selected_stash}" ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" stash apply "${selected_stash}"
fi