Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Created December 28, 2018 13:46
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 Risto-Stevcev/d830c1d0bb3ac7ae2eeb1e1b530be16d to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/d830c1d0bb3ac7ae2eeb1e1b530be16d to your computer and use it in GitHub Desktop.
This script opens changed files from git into neovim
#!/bin/bash
# This script opens changed files from git into neovim
FOR_STATUS=
FOR_LOG=
COMMIT="HEAD"
open_in_vim () {
if [[ ! -z $FOR_LOG ]]; then
git show --pretty="" --name-only $COMMIT | xargs nvim -p
else
git status --porcelain | awk 'match ($1, "M") {print $2}' | xargs nvim -p
fi
}
usage () {
cat << EOF
Usage: $0 OPTIONS
This script opens changed files from git into neovim.
OPTIONS:
-s Open currently modified tracked files
-l Open changed files from a commit
-c Specify which commit to use for -l (defaults to HEAD)
EOF
}
while getopts "hslc:" OPTION
do
case $OPTION in
h) usage; exit
;;
s) FOR_STATUS=1
;;
l) FOR_LOG=1
;;
c) COMMIT=$OPTARG
;;
?) usage; exit
;;
esac
done
open_in_vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment