Skip to content

Instantly share code, notes, and snippets.

@shmup
Last active October 1, 2020 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shmup/b80e238df123510939543ddd67f93f6d to your computer and use it in GitHub Desktop.
Save shmup/b80e238df123510939543ddd67f93f6d to your computer and use it in GitHub Desktop.
open all currently (and previously) modified files in vim
#!/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 ‡‡‡#
@shmup
Copy link
Author

shmup commented Sep 30, 2020

[~/workspace/platform (pls-240/route-maps-frontend *)]$ vr -d
portal/js/components/pulsar_beta/routemaps/modal.js
portal/js/components/pulsar_beta/routemaps/state.js
portal/js/resource/routemaps/routemap.js

[~/workspace/platform (pls-240/route-maps-frontend *)]$ vr 2 -d
portal/js/components/pulsar_beta/routemaps/modal.js
portal/js/components/pulsar_beta/routemaps/state.js
portal/js/resource/routemaps/routemap.js
portal/js/components/pulsar_beta/routemaps/delete.js
portal/js/components/pulsar_beta/routemaps/errors.js
portal/js/components/pulsar_beta/routemaps/footer.js
portal/package.json

[~/workspace/platform (pls-240/route-maps-frontend *)]$ vr -h
usage: vr [--dry-run|-d][--help|-h] <n>
  vr - open all currently modified files
  vr 2 - open all currently modified files + all modified in last 2 commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment