2020-04-24 06:21:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# interactive menu to select file/commit to edit
|
|
|
|
#
|
|
|
|
# @params
|
|
|
|
# Globals
|
|
|
|
# None
|
|
|
|
# Arguments
|
|
|
|
# None
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -f
|
|
|
|
|
|
|
|
mydir="${0%/*}"
|
|
|
|
source "${mydir}"/../helper/set_variable.sh
|
|
|
|
source "${mydir}"/../helper/git_query.sh
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo -e "Usage: dotbare fedit [-h] ...\n"
|
|
|
|
echo -e "List all tracked dotfiles and edit"
|
|
|
|
echo -e "also support commit message edit\n"
|
|
|
|
echo -e "optional arguments:"
|
|
|
|
echo -e " -h\t\tshow this help message and exit"
|
|
|
|
echo -e " -m\t\tonly display modified file"
|
|
|
|
echo -e " -c\t\tedit commit message instead"
|
|
|
|
}
|
|
|
|
|
|
|
|
modified=''
|
|
|
|
commit=''
|
|
|
|
|
|
|
|
while getopts ":hmc" opt; do
|
|
|
|
case "$opt" in
|
|
|
|
m)
|
|
|
|
modified='true'
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
commit='true'
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid option: ${OPTARG}" >&2
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -n "${commit}" ]]; then
|
|
|
|
echo "commit"
|
|
|
|
else
|
2020-04-24 06:26:15 +00:00
|
|
|
if [[ -n "${modified}" ]]; then
|
|
|
|
selected_files=$(get_modified_file "Select tracked files to edit")
|
|
|
|
else
|
|
|
|
selected_files=$(get_git_file "Select tracked files to edit")
|
|
|
|
fi
|
2020-04-24 06:24:29 +00:00
|
|
|
[[ -z "${selected_files}" ]] && exit 0
|
|
|
|
command "${EDITOR}" ${selected_files}
|
2020-04-24 06:21:41 +00:00
|
|
|
fi
|