ported from zsh