delete stash through fzf

pull/3/head
kevin zhuang 4 years ago
parent 81f07da96f
commit 5a7159846e

@ -15,8 +15,9 @@
#######################################
function get_confirmation() {
local confirm
local message="${1:-Confirm?}"
while [ "${confirm}" != 'y' ] && [ "${confirm}" != 'n' ]; do
read -r -p "$1(y/n): " confirm
read -r -p "${message}(y/n): " confirm
done
echo "${confirm}"
}

@ -30,11 +30,17 @@ function usage() {
}
stash_file=""
delete_stash=""
while getopts ":hf" opt; do
while getopts ":hdf" opt; do
case "$opt" in
f)
stash_file='true'
break
;;
d)
delete_stash='true'
break
;;
h)
usage
@ -49,11 +55,22 @@ while getopts ":hf" opt; do
done
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}
selected_file=$(get_modified_file "select files to add to a stash")
[[ -z "${selected_file}" ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" stash -- ${selected_file}
elif [[ -n "${delete_stash}" ]]; then
selected_stash=$(get_stash "select stash to delete")
[[ -z "${selected_stash}" ]] && exit 1
while IFS= read -r line; do
echo "(dryrun) Drop ${line}"
done <<< "${selected_stash}"
confirm=$(get_confirmation)
[[ "${confirm}" != 'y' ]] && exit 1
while IFS= read -r line; do
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" stash drop "${line}"
done <<< "${selected_stash}"
else
selected_stash=$(get_stash "select stash to apply")
selected_stash=$(get_stash "select stash to apply" "true")
[[ -z "${selected_stash}" ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" stash apply "${selected_stash}"
fi

Loading…
Cancel
Save