Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
executable file 24 lines (18 sloc) 762 Bytes
#!/usr/bin/env bash
# git-open-all: open all files changed in the current branch in the user's $EDITOR
set -eo pipefail
[[ -n "${EDITOR}" ]] || { >&2 echo "Refusing to continue without EDITOR."; exit; }
function __git_find_main_branch() {
mapfile -t branches < <(git branch --format='%(refname:short)')
for branch in "${branches[@]}"; do
[[ "${branch}" == "main" || "${branch}" == "master" ]] \
&& echo -n "${branch}" \
&& return
done
}
current=$(git rev-parse --abbrev-ref HEAD)
base=${1:-$(__git_find_main_branch)}
merge_base=$(git merge-base "${current}" "${base}")
# TODO: Instead of filtering renamed files, open their new path.
git diff -z --diff-filter "r" --name-only "${current}" "${merge_base}" \
| xargs -0 "${EDITOR}"