EivindArvesen/prm

[zsh] "source test" fails although it is sourced

weltoph opened this issue · 2 comments

Hey,

first of all, I really like prm as project manager. Unfortunately I ran into the following problem:
The test if prm.sh is executed or sourced, i.e.

# Test if prm is run in subshell or sourced
if [ "$(basename "${0//-/}")" = "prm.sh" ]; then
    return_error 1 "$(printf "$SOURCE")"
    exit
fi

evaluates in zsh to true, even if the script is sourced. I know far too less zsh things to tell you why, but my very basic investigation (I echoed $(basenamen "${0//-/}") ) showed that it evaluates to "prm.sh" on execution as well as sourcing the script. Unfortunately I didn't find for now a reliable zsh/bash-independent way of testing for this. By now prm just crashed because sourcing this file closes my shell because of "exit".

I try to find a proper solution on my own, but any help is appreciated since I am very unfamiliar with bash/zsh!

All the best,
Christoph

branch: master
commit: 97e7598

Okay further investigation led to the following stackoverflow answer:
http://stackoverflow.com/a/2684300
which worked for me in bash as well as zsh.

Thank you! That's nice to hear.

I've pushed a fix based on $BASH_SOURCE, which works with both bash and zsh on my computer.