Cleaner dir changes

This commit is contained in:
Daniel Flanagan 2020-02-12 11:24:16 -06:00
parent 88284235da
commit d8126dc9e6
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -1,7 +1,10 @@
#!/usr/bin/env bash
repo_root="$(git rev-parse --show-toplevel)"
pushd "$repo_root" &> /dev/null || ( echo "Repo doesn't exist!"; exit 2 )
if ! pushd "$repo_root" &> /dev/null; then
echo "Repo doesn't exist!"
exit 2
fi
td="$(mktemp -p "$pdir" -d "vdiff.XXXXXXXX")"
trap "rm -rf \"$td\"" EXIT
files="$(git diff --name-only "$@")"
@ -30,5 +33,7 @@ done
remaps="nnoremap <leader>k :tabnext<CR> | nnoremap <leader>j :tabprev<CR>"
nvim "${args[@]}" "$vcmd | tabnext | $remaps"
rm -rf "$td"
popd &> /dev/null || ( echo "Could not return to original directory" && exit 4 )
if ! popd &> /dev/null; then
echo "Could not return to original directory"
exit 4
fi