Different check if it's accessed by CLI
Add support when STDIN, STDOUT and STDERR aren't set.
Use PWD environment variable instead of getcdw().