added freset

pull/3/head
kevin zhuang 4 years ago
parent a160508e0d
commit 69f1d98957

@ -37,6 +37,10 @@ case "$1" in
action_command='fpop'
shift
;;
freset)
action_command='freset'
shift
;;
help)
usage
exit 0

@ -74,10 +74,10 @@ elif [[ -n "${new_folder}" ]]; then
done <<< "${new_folder}"
else
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" diff --name-status | \
awk '{if ($1 == "D") {print "\033[31m" $1 " " $2} else {print "\033[33m" $1 " " $2}}' | \
fzf --multi --preview "echo {} | awk '{print \$2}' | \
xargs -I __ /usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" diff --color=always $HOME/__" | \
awk -v home=$HOME '{print home "/" $2}')
awk '{print "\033[31m" $1 " " $2}' | \
fzf --header='select files to stage' --multi --preview "echo {} | awk '{print \$2}' | \
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} diff --color=always ${DOTBARE_TREE}/__" | \
awk -v home="${DOTBARE_TREE}" '{print home "/" $2}')
while IFS= read -r line; do
stage_file "${line}"
done <<< "${selected_files}"

@ -0,0 +1,46 @@
#!/bin/bash
#
# unstage the selected staged file
# or reset the commit to certain point
#
# @params
# Globals
# ${mydir}: current directory of the script
# ${selected_files}: selected file to unstage
set -e
mydir="${0%/*}"
source "${mydir}"/../helper/set_variable
function usage() {
echo -e "Usage: dotbare freset [-h] [-f] [-d] ...\n"
echo -e "Reset/Unstage the selected staged file"
echo -e "Or reset the commit to certain point\n"
echo -e "optional arguments:"
echo -e " -h\t\tshow this help message and exit"
}
while getopts ":h" opt
do
case "$opt" in
h)
usage
exit 0
;;
*)
echo "Invalid option: ${OPTARG}" >&2
usage
exit 1
;;
esac
done
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" diff --name-status --cached | \
awk '{print "\033[32m" $1 " " $2}' | fzf --header='select files to unstage' --multi --preview "echo {} | awk '{print \$2}' | \
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} diff --staged --color=always ${DOTBARE_TREE}/__" | \
awk -v home="${DOTBARE_TREE}" '{print home "/" $2}')
[[ -z "${selected_files}" ]] && exit 0
while IFS= read -r line; do
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset HEAD "${line}"
done <<< "${selected_files}"
Loading…
Cancel
Save