You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dotbare/scripts/fedit

73 lines
1.8 KiB
Plaintext

4 years ago
#!/usr/bin/env bash
4 years ago
#
# interactive menu to select file/commit to edit
#
# @params
# Globals
# ${mydir}: current directory of the script
# ${modified}: select modified file only
# ${commit}: rename commit
# ${selected_commit}: selected commit to edit
# ${selected_files}: selected file to edit
4 years ago
# Arguments
# -m: display modified file only
# -c: edit commit using interactive rebase
# -h: show helpe message and exit
4 years ago
set -e
set -f
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4 years ago
source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/git_query.sh
function usage() {
echo -e "Usage: dotbare fedit [-h] [-m] [-c] ...\n"
4 years ago
echo -e "List all tracked dotfiles and edit"
echo -e "also support commit message edit\n"
echo -e "optional arguments:"
4 years ago
echo -e " -h\tshow this help message and exit"
echo -e " -m\tonly display modified file"
echo -e " -c\tedit commit using interactive rebase instead"
4 years ago
}
modified=''
commit=''
while getopts ":hmc" opt; do
4 years ago
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
4 years ago
selected_commit=$(get_commit "Select a commit to rename")
[[ -z "${selected_commit}" ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" rebase -i "${selected_commit}"~
4 years ago
else
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
4 years ago
[[ -z "${selected_files}" ]] && exit 1
# shellcheck disable=SC2086
4 years ago
command "${EDITOR}" ${selected_files}
4 years ago
fi