From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21745 invoked from network); 7 Apr 2021 07:06:52 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Apr 2021 07:06:52 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1617779212; b=Y0MveXtPQX//ZV/2uRg6ZDqeLu3e5tF/tyL7KZnWm6goinF7QSYLNu15T+8L8lc+WB0YgeyWrG J5h/34XHUrfOfpXP3oOgt2/cjnHiA2k5FvcHvH+Sd/eRJ8i8BXZ1y0/i2P30CaVYVXY4sATh8k Opd5ELfPrVOXC1kIOjC84N8GUu5u2hJD1pHQ4aWD5IusQYjvNXYAs45fMX9ciT/XbOkV8EsI1G lzInunpUi6t2CJ4a0JMqyPlf16OZ2Nrtqu7ohz+PLn9WSLqGyBL0XWOJu7E2zJXYInzf/VnXpb duR8Dhf4CYL1+jL/bzWNK52xyKrQNJ82zBjMojsNEsAEPA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1617779212; bh=xRhXqmZrpKf0FAqjB35GkzrhbreHxBmml4UISuvOS2U=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=EChdjIugf2BMOyutrryDuec+qTs/NJip3j7dcZM/p2j39/JxYI1UGnyfCrR4x7KyexwvdB2Qck moVb+/NCuzytPfn8RIhvczjtC6mLm5uH2+iDMOUjDNsya16eJbt/CuyejuZZ0VcSwTCjsSnB3/ nXYzvZGnU74JVnmEYwsFWDjyMuRH6YdwKllNuyfjY9L8VQk063+J/bH3Kn8xOjtIaz0wXwmiIO GUa2S5587YCZK+ld2TkKv3seAkfSdO4WthgMcbKMPaubr0c8++Jp9T1Lv6vI3ETfjFMdX+uk/L mIgCI7SDIO3FjMvm8Al9PlFop8LRvRAXVJ2ueArkFQXtFQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=6zsdl/fxT8kCWolLq875NcfHmaVbth4V6Rn9P1y7NOY=; b=j46VcxtgbvZeg56KPcqnLyOVX0 RZU6Knaq2JYIIwZs7FF4LlqxaGY40auEvtQfVBoGmyY4yx/67b1d0SI7LqZ9G0uHOYOxK04KAQOjz bgZz3Ri9gB6Hmd4pnqdLlgoaEbxud6nPA1TxyRB0IrFvAt2i5l89vLhdZMbSVVqXH+EUuYcGMmyRy MsoF2MznKeG43CMgClxGAalFMtzJg0twikaikAtzOx2HjB09PH23wxUW2/qWUg/QccBW5zamd1AB7 rRmCA4xskXgFmhq6NNHFXjXR4o+BShF2K8J6Kp8/DO63+q8XY4tkYoJXT4ysOFQa0m3ZtzCJT+56e zGNjuy6Q==; Received: from authenticated user by zero.zsh.org with local id 1lU2H1-0002Tf-FV; Wed, 07 Apr 2021 07:06:47 +0000 Authentication-Results: zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; dmarc=none header.from=chazelas.org; arc=none Received: from relay6-d.mail.gandi.net ([217.70.183.198]:49915) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1lU2Fc-0001rf-Uj; Wed, 07 Apr 2021 07:05:21 +0000 X-Originating-IP: 5.71.197.169 Received: from chazelas.org (0547c5a9.skybroadband.com [5.71.197.169]) (Authenticated sender: stephane@chazelas.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 85B4AC0003; Wed, 7 Apr 2021 07:05:19 +0000 (UTC) Date: Wed, 7 Apr 2021 08:05:18 +0100 From: Stephane Chazelas To: Grant Taylor Cc: zsh-users@zsh.org Subject: Re: alias with a parameter Message-ID: <20210407070518.szoet4rxbouwzelm@chazelas.org> Mail-Followup-To: Grant Taylor , zsh-users@zsh.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 26630 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: 2021-04-05 20:47:47 -0600, Grant Taylor: [...] > pd() { > [ -n "${1}" ] && pushd "${1}" || popd; > } > > It's using parameters on a function, just like you're trying to do. It > works a treat. > > Aside: Yes, I'm lazy and don't want to type pushd or popd. Instead, the pd > function determines which command to run based on if $1 is set or not. [...] That function would run popd when pushd fails. It's generally a bad idea to use this kind of a && b || c in place of proper if/then/else constructs. pd() { if [ "$#" -gt 0 ]; then pushd "$@" else popd fi } Or for the very lazy: pd()if (($#)){pushd "$@"} else {popd} -- Stephane