Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing wrong usage of last's command exit code and some cleaning... #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leogtzr
Copy link

@leogtzr leogtzr commented Sep 13, 2017

There was an error here:

git branch 2>/dev/null 1>&2
if [ $? -ne 0 ]; then
  echo Not a git repo!
  exit $?
fi

$? is reading the status of the last command, which is echo, so it will alwats be 0 ...

This is a good alternative:

git branch >/dev/null 2>&1
readonly RT_CODE=${?}
if ((RT_CODE != 0)); then
    echo "Not a git repo!"
    exit ${RT_CODE}
fi


# Find current directory relative to .git parent
full_path=$(pwd)
git_base_path=$(cd ./$(git rev-parse --show-cdup); pwd)
relative_path=${full_path#$git_base_path} # remove leading git_base_path from working directory

# If filename argument is present, append it
if [ "$1" ]; then
relative_path="$relative_path/$1"
if [[ ! -z "${1}" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do all shells have -z ?

open=$opener;
break;
fi
if command -v ${opener}; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the extra indentation here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants