set up commits viewer

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

@ -21,9 +21,14 @@ function usage() {
echo -e " -h\t\tshow this help message and exit" echo -e " -h\t\tshow this help message and exit"
} }
while getopts ":h" opt search_commits=""
while getopts ":hc" opt
do do
case "$opt" in case "$opt" in
c)
search_commits="1"
;;
h) h)
usage usage
exit 0 exit 0
@ -36,11 +41,18 @@ do
esac esac
done done
if [[ -n "${search_commits}" ]]; then
selected_commites=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" log --oneline --color=always --decorate=short | \
fzf --header='select which commit to reset' --preview "echo {} | awk '{print \$1}' | \
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} show --color=always __")
else
selected_files=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" diff --name-status --cached | \ 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}' | \ 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}/__" | \ 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}') awk -v home="${DOTBARE_TREE}" '{print home "/" $2}')
[[ -z "${selected_files}" ]] && exit 0 [[ -z "${selected_files}" ]] && exit 0
while IFS= read -r line; do while IFS= read -r line; do
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset HEAD "${line}" /usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset HEAD "${line}" 1>/dev/null
echo "${line} unstaged successfully"
done <<< "${selected_files}" done <<< "${selected_files}"
fi

Loading…
Cancel
Save