From d8126dc9e642ecae4c7c2969f8f1f0a533459d3f Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 12 Feb 2020 11:24:16 -0600 Subject: [PATCH] Cleaner dir changes --- bin/vdiff | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/vdiff b/bin/vdiff index 91f9ef3..ea269a0 100755 --- a/bin/vdiff +++ b/bin/vdiff @@ -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 k :tabnext | nnoremap j :tabprev" 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