zsh-users
 help / color / Atom feed
* Don't append slash when auto completing a symbolic link pointing to a directory
@ 2020-05-28 20:04 Alan
  2020-05-28 20:53 ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Alan @ 2020-05-28 20:04 UTC (permalink / raw)
  To: zsh-users


[-- Attachment #1: Type: text/plain, Size: 645 bytes --]

Hi,

I'm switching from bash to zsh and prefer bash's default behavior of not
appending a slash when auto completing a symbolic link pointing to a
directory.

For example:
$ mkdir directory
$ ln -s directory symblink
$ ls sym<TAB>

At this point, in bash, you would get:
$ ls symblink

In zsh, I'm getting:
$ ls symblink/

Also, in bash, hitting a <TAB> when the full symbolic link is already
present would then append the slash to the symbolic link:
$ ls symblink<TAB>
$ 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.

Thanks for your help!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Don't append slash when auto completing a symbolic link pointing to a directory
  2020-05-28 20:04 Don't append slash when auto completing a symbolic link pointing to a directory Alan
@ 2020-05-28 20:53 ` Mikael Magnusson
  2020-05-28 21:56   ` Alan
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2020-05-28 20:53 UTC (permalink / raw)
  To: Alan; +Cc: zsh-users

On 5/28/20, Alan <8fvebtoeq87@gmail.com> wrote:
> Hi,
>
> I'm switching from bash to zsh and prefer bash's default behavior of not
> appending a slash when auto completing a symbolic link pointing to a
> directory.
>
> For example:
> $ mkdir directory
> $ ln -s directory symblink
> $ ls sym<TAB>
>
> At this point, in bash, you would get:
> $ ls symblink
>
> In zsh, I'm getting:
> $ ls symblink/
>
> Also, in bash, hitting a <TAB> when the full symbolic link is already
> present would then append the slash to the symbolic link:
> $ ls symblink<TAB>
> $ 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.

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.

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Don't append slash when auto completing a symbolic link pointing to a directory
  2020-05-28 20:53 ` Mikael Magnusson
@ 2020-05-28 21:56   ` Alan
  2020-05-29 22:54     ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Alan @ 2020-05-28 21:56 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users


[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]

Unfortunately, I have autoremoveslash disabled (i.e. 'unsetopt
autoremoveslash'), and prefer it that way for other things, so the trailing
slash isn't removed when pressing enter.


On Thu, May 28, 2020 at 4:53 PM Mikael Magnusson <mikachu@gmail.com> wrote:

> On 5/28/20, Alan <8fvebtoeq87@gmail.com> wrote:
> > Hi,
> >
> > I'm switching from bash to zsh and prefer bash's default behavior of not
> > appending a slash when auto completing a symbolic link pointing to a
> > directory.
> >
> > For example:
> > $ mkdir directory
> > $ ln -s directory symblink
> > $ ls sym<TAB>
> >
> > At this point, in bash, you would get:
> > $ ls symblink
> >
> > In zsh, I'm getting:
> > $ ls symblink/
> >
> > Also, in bash, hitting a <TAB> when the full symbolic link is already
> > present would then append the slash to the symbolic link:
> > $ ls symblink<TAB>
> > $ 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.
>
> 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.
>
> --
> Mikael Magnusson
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Don't append slash when auto completing a symbolic link pointing to a directory
  2020-05-28 21:56   ` Alan
@ 2020-05-29 22:54     ` Daniel Shahaf
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2020-05-29 22:54 UTC (permalink / raw)
  To: Alan; +Cc: zsh-users

Alan wrote on Thu, 28 May 2020 17:56 -0400:
> On Thu, May 28, 2020 at 4:53 PM Mikael Magnusson <mikachu@gmail.com> wrote:
> > On 5/28/20, Alan <8fvebtoeq87@gmail.com> wrote:  
> > > $ ls sym<TAB>
> > >
> > > At this point, in bash, you would get:
> > > $ ls symblink
> > >
> > > In zsh, I'm getting:
> > > $ ls symblink/
> > >
> > > Also, in bash, hitting a <TAB> when the full symbolic link is already
> > > present would then append the slash to the symbolic link:
> > > $ ls symblink<TAB>
> > > $ 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.  
> >
> > 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.
> >  
> 
> Unfortunately, I have autoremoveslash disabled (i.e. 'unsetopt
> autoremoveslash'), and prefer it that way for other things, so the trailing
> slash isn't removed when pressing enter.

It's possible to achieve this with a custom widget:

[[[
expand-or-complete()
{
	local old=$LBUFFER
	{
		zle .$WIDGET -- "$@"
	} always {
		[[ ${LBUFFER} == */ && $LBUFFER != ${old}/ && -L ${${(z)LBUFFER}[-1]%/} ]] && LBUFFER=${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 «expand-or-complete» widget (which
handles <TAB> presses — see `bindkey $'\t'`) with a function that, 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 «symlink<TAB>» complete to «symlink/».

You might want to add a «$old != $LBUFFER» and/or «$? -eq 0» 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-28 20:04 Don't append slash when auto completing a symbolic link pointing to a directory Alan
2020-05-28 20:53 ` Mikael Magnusson
2020-05-28 21:56   ` Alan
2020-05-29 22:54     ` Daniel Shahaf

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git