Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: alias with a parameter



Grant Taylor wrote on Thu, Apr 08, 2021 at 20:55:37 -0600:
> On 4/7/21 7:25 PM, Daniel Shahaf wrote:
> > This will return non-zero when pushd succeeds.
> 
> You are correct.
> 
>    pd () {
>    	[ $# -eq 1 ] && pushd "${1}" && return 0
>    	[ $# -eq 0 ] && popd
>    }

This still discards pushd's exit code if it's *non*-zero.

Yet another variant:

pd() case $+1 in (0) popd;; (1) pushd "$1";; esac

Or if golfing:

pd()$# $1;0()popd;1()pushd $1




Messages sorted by: Reverse Date, Date, Thread, Author