2020-05-02 22:55:34 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# git log interactive viewer
|
|
|
|
#
|
|
|
|
# @params
|
|
|
|
# Globals
|
|
|
|
# None
|
|
|
|
# Arguments
|
|
|
|
# None
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -f
|
|
|
|
|
|
|
|
mydir="${0%/*}"
|
|
|
|
source "${mydir}"/../helper/set_variable.sh
|
|
|
|
source "${mydir}"/../helper/git_query.sh
|
|
|
|
source "${mydir}"/../helper/get_confirmation.sh
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo -e "Usage: dotbare flog [-h] [-f] [-d] ...\n"
|
|
|
|
echo -e "Interactive log viewer with action menu"
|
|
|
|
echo -e "Action menu contains command including revert|reset|edit|checkout"
|
|
|
|
echo -e "optional arguments:"
|
|
|
|
echo -e " -h\t\tshow this help message and exit"
|
|
|
|
}
|
|
|
|
|
2020-05-02 23:16:18 +00:00
|
|
|
#######################################
|
|
|
|
# draw action menu for selected commit
|
|
|
|
# Arguments:
|
|
|
|
# $1: selected action, if selected, skip menu, return action
|
|
|
|
# Outputs:
|
|
|
|
# ${selected_action}: user selected action
|
|
|
|
#######################################
|
|
|
|
function draw_menu() {
|
|
|
|
local selected_action="$1"
|
|
|
|
if [[ -n "$selected_action" ]]; then
|
|
|
|
echo "${selected_action}"
|
|
|
|
else
|
|
|
|
menu="revert\nreset\nedit\ncheckout\nexit"
|
|
|
|
selected_action=$(echo -e "${menu}" | fzf --no-multi)
|
|
|
|
echo "${selected_action}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-02 22:55:34 +00:00
|
|
|
selected_action=""
|
|
|
|
|
|
|
|
while getopts ":hr" opt; do
|
|
|
|
case "$opt" in
|
|
|
|
r)
|
|
|
|
selected_action="revert"
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
R)
|
|
|
|
selected_action="reset"
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
e)
|
|
|
|
selected_action="edit"
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
selected_action="checkout"
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid option: ${OPTARG}" >&2
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2020-05-02 23:16:18 +00:00
|
|
|
|
|
|
|
while True; do
|
|
|
|
selected_commit=$(get_commit)
|
|
|
|
[[ -z "${selected_commit}" ]] && break
|
|
|
|
selected_action=$(draw_menu "${selected_action}")
|
|
|
|
[[ -z "${selected_action}" ]] && continue
|
|
|
|
[[ "${selected_action}" == 'exit' ]] && break
|
|
|
|
done
|