StreakyCobra / gws

Colorful KISS helper for git workspaces
https://streakycobra.github.io/gws/
MIT License
235 stars 22 forks source link

Kill CDPATH to avoid unwanted output. #18

Closed TurboGit closed 9 years ago

TurboGit commented 9 years ago

This was breaking the git_check_untracked() function. In nb we add a cd "$1" which was sending the directory into the grep -c.

StreakyCobra commented 9 years ago

Hi,

Thanks for your interest and contribution!

I'm not sure to understand completely your message, maybe I have not enough context. I never used $CDPATH so I had to search a bit about what it is. I found this and I tried it.

I didn't see how it interferes with the grep -c because the only difference I noticed was the printing of the folder name when doing cd, and it will not match the ^?? pattern – except if you have a folder starting with ?? which is not usual.

Unsetting an environment variable inside the script will probably not break any configuration, so I'm ready to integrate it in the next release, but can you tell me more about the problem? I'm curious and maybe there is another more general way to solve it :smiley:

TurboGit commented 9 years ago

Easy:

export CDPATH=.

And from top level directory of GWS run the following commands.

cd src && "git status --porcelain" 2>/dev/null | grep -c "^??" /home/obry/dev/repositories/git/gws/src 0

As you see because CDPATH is set we have a first line display when moving into src.

And this breaks the next line:

[[ $nb -eq 0 ]] && return 0

As nb does contains the plus the 0.

CDPATH='' cd src && "git status --porcelain" 2>/dev/null | grep -c "^??" 0

And this is always better to kill CDPATH in script as it won't be used anyway.

StreakyCobra commented 9 years ago

cd src && "git status --porcelain" 2>/dev/null | grep -c "^??" /home/obry/dev/repositories/git/gws/src 0

I don't have the same output as you when I run this manually, the path is not displayed. I tried to find out why, and there is a difference here between bash and zsh. I forgot sometimes that I'm running zsh, and that gws is interpreted by bash, my bad.

And this is always better to kill CDPATH in script as it won't be used anyway.

This is a bug and indeed unsetting CDPATH seems to be a good practice. It will be in the next version. Thanks again :+1: