-
-
Save shmup/b80e238df123510939543ddd67f93f6d to your computer and use it in GitHub Desktop.
open all currently (and previously) modified files in vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# http://ix.io/2zhL/sh | |
# vr is "vim resume" | |
# open all currently (and previously) modified files in vim | |
# tell me‡ if it doesn't work for you, please | |
function help { | |
cat << EOF | |
usage: vr [--dry-run|-d][--debug|-z][--help|-h] <n> | |
vr - open all currently modified files | |
vr 2 - open all currently modified files + all modified in last 2 commits | |
EOF | |
} | |
if git rev-parse --git-dir > /dev/null 2>&1; then | |
# change to the root for sake of opening file paths | |
cd "$(git rev-parse --show-toplevel)" || exit 0 | |
DRY=0; NUM=0; DEBUG=0 | |
IGNORES='.svg\|.png\|.jpg' | |
# list all currently modified files, staged or unstaged | |
LIST="$(git status --short | cut -c 4-)" | |
while [ $# -gt 0 ] | |
do | |
case $1 in | |
-h|--help) help && exit 0;; | |
-d|--dry-run) DRY=1;; | |
-z|--debug) DEBUG=1;; | |
''|*[0-9]*) NUM=$1;; | |
(--) shift; break;; | |
(-*|*) help && exit 1 | |
esac | |
shift # shift so we can consume the next arg | |
done | |
if [[ $NUM -gt 0 ]]; then | |
# append all files modified since X commits | |
LIST="${LIST}\n$(git diff-tree --no-commit-id --name-only -r HEAD~"${NUM:-1}" HEAD)" | |
fi | |
if [[ $DEBUG -eq 1 ]]; then | |
file_count=$(echo "$LIST" | wc -l) | |
printf "\x1B[1;33mDRY: %s\n" "$DRY" | |
printf "NUM: %s\n" "$NUM" | |
printf "FILES: %s\n" "$file_count" | |
printf "IGNORES: %s\n\n" "$IGNORES" | |
tput sgr0 | |
fi | |
if [[ $DRY -eq 1 ]]; then | |
echo -e "$LIST" && exit 0 | |
fi | |
echo -n "$LIST" | grep -v $IGNORES | xargs -o vim | |
else | |
echo "not in a git repo" | |
fi | |
#‡‡‡ pissss@pm.me ‡‡‡# |
Author
shmup
commented
Sep 30, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment