Skip to content

Instantly share code, notes, and snippets.

@drewbrokke
Created June 17, 2022 18:46
Show Gist options
  • Save drewbrokke/7324f9b267741f2c609dacbff3d87ee5 to your computer and use it in GitHub Desktop.
Save drewbrokke/7324f9b267741f2c609dacbff3d87ee5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# openFiles // opens all files between current branch and master
# openFiles branchName // opens all files between "branchName" and master
# openFiles commitHash // opens all files between "commitHash" and master
# openFiles commitHash1 commitHash2 // opens all files between "commitHash1" and "commitHash2"
function openFiles() {
HASH1="${1}"
if [ -z "${HASH1}" ]; then
HASH1="$(git branch --show-current)"
fi
HASH2="${2-master}"
HASH_RANGE="${HASH1}^..${HASH1}"
if [ "${HASH2}" ]; then
if git merge-base --is-ancestor "${HASH1}" "${HASH2}"; then
HASH_RANGE="${HASH1}^..${HASH2}"
else
HASH_RANGE="${HASH2}^..${HASH1}"
fi
fi
echo "Opening files in the range: ${HASH_RANGE}"
GIT_TOPLEVEL="$(git rev-parse --show-toplevel)"
for file in $(git diff "${HASH_RANGE}" --name-only | head -n "${OSUB_FILE_LIMIT:-50}"); do
echo "Opening: $file"
subl "${GIT_TOPLEVEL}/$file" 2>/dev/null || echo "Could not open file: $file"
done
}
openFiles "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment