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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29139 invoked from network); 29 May 2020 22:55:20 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 29 May 2020 22:55:20 -0000 Received: (qmail 4236 invoked by alias); 29 May 2020 22:54:59 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24887 Received: (qmail 8863 invoked by uid 1010); 29 May 2020 22:54:59 -0000 X-Qmail-Scanner-Diagnostics: from out3-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25821. spamassassin: 3.4.4. Clear:RC:0(66.111.4.27):SA:0(-2.6/5.0):. Processed in 0.800747 secs); 29 May 2020 22:54:59 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedruddvledgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkjghfofggtgfgsehtqh dttdertdejnecuhfhrohhmpeffrghnihgvlhcuufhhrghhrghfuceougdrshesuggrnhhi vghlrdhshhgrhhgrfhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpefhtdetfeehveeutd ehuddtieefgeettedtjedtffehudeiieejleetteekudetheenucfkphepjeelrddujeei rdefledrieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Date: Fri, 29 May 2020 22:54:21 +0000 From: Daniel Shahaf To: Alan <8fvebtoeq87@gmail.com> Cc: zsh-users@zsh.org Subject: Re: Don't append slash when auto completing a symbolic link pointing to a directory Message-ID: <20200529225421.4535d31a@tarpaulin.shahaf.local2> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Alan wrote on Thu, 28 May 2020 17:56 -0400: > On Thu, May 28, 2020 at 4:53 PM Mikael Magnusson wrot= e: > > On 5/28/20, Alan <8fvebtoeq87@gmail.com> wrote: =20 > > > $ ls sym > > > > > > At this point, in bash, you would get: > > > $ ls symblink > > > > > > In zsh, I'm getting: > > > $ ls symblink/ > > > > > > Also, in bash, hitting a when the full symbolic link is already > > > present would then append the slash to the symbolic link: > > > $ ls symblink > > > $ ls symblink/ > > > > > > Is there anyway to get this behavior with zsh? I looked through "man > > > zshoptions" this time and couldn't find anything specific to this. =20 > > > > If it makes you feel better, hitting enter will remove the / and just > > run "ls symblink". (Although this makes no difference to ls unless you > > also give -l). The / is just inserted temporarily in case you want to > > continue typing/completing things inside the directory, but a space, > > enter or movement etc will remove it again. This should be indicated > > by a bold/standout font. > > =20 >=20 > Unfortunately, I have autoremoveslash disabled (i.e. 'unsetopt > autoremoveslash'), and prefer it that way for other things, so the traili= ng > slash isn't removed when pressing enter. It's possible to achieve this with a custom widget: [[[ expand-or-complete() { local old=3D$LBUFFER { zle .$WIDGET -- "$@" } always { [[ ${LBUFFER} =3D=3D */ && $LBUFFER !=3D ${old}/ && -L ${${(z)LBUFFER}[-1= ]%/} ]] && LBUFFER=3D${LBUFFER%/} } } zle -N expand-or-complete ]]] I realize this isn't exactly an obvious solution. I suspect there's a simpler solution that I'm overlooking. In English, what it does is wrap the =C2=ABexpand-or-complete=C2=BB widget = (which handles presses=C2=A0=E2=80=94 see `bindkey $'\t'`) with a function t= hat, after the built-in widget does its thing, removes the slash if the word before the cursor is a symlink with slash appended. The second conjunct is to let =C2=ABsymlink=C2=BB complete to =C2=ABsymlink/=C2=BB. You might want to add a =C2=AB$old !=3D $LBUFFER=C2=BB and/or =C2=AB$? -eq = 0=C2=BB to the list of conditions so it doesn't remove the slash when trying to complete filenames in an empty directory. s/(z)/(zZ+c+)/ if you set the INTERACTIVE_COMMENTS option. Cheers, Daniel