Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash and zsh not completing filenames #385

Closed
Gerrit-K opened this issue Jun 17, 2020 · 28 comments
Closed

bash and zsh not completing filenames #385

Gerrit-K opened this issue Jun 17, 2020 · 28 comments
Labels
kind/bug Something isn't working

Comments

@Gerrit-K
Copy link

Expected behavior

When I type lsd --date='date' <TAB> the zsh completion lists all files in the current directory.

Actual behavior

When I type lsd --date='date' <TAB> the zsh completion inserts a dash instead. A consecutive <TAB> then lists all options (as a completion for -*).

@Gerrit-K Gerrit-K added the kind/bug Something isn't working label Jun 17, 2020
@zwpaper
Copy link
Member

zwpaper commented Dec 3, 2020

I have tried the lsd --date='date' <TAB> but it shows the files like this:

image

could you add:

  1. the version of lsd
  2. the version of zsh
  3. did you use some extensions like oh-my-zsh or something others

@zwpaper zwpaper added need-more-info and removed kind/bug Something isn't working labels Dec 3, 2020
@Gerrit-K
Copy link
Author

Gerrit-K commented Dec 3, 2020

I totally forgot about that issue and I'm currently unable to reproduce it. Back then I somehow had at least some completions (not sure if built-in or via zsh-completions), but right now I don't have any at all.

So the bug is kind of obsolete now, since the default zsh behaviour of suggesting directories and files (as stated in the "expected behavior" bug description) now kicks in instead of suggesting lsd options 😄

Ultimately I would like to have completions for the options, but only if I insert a dash and then hit tab, and otherwise have completions for the files.

But honestly at this point I don't really care much anymore 😉 I can live without the option completions as long as the file completions work as expected. Feel free to close this if you think it shouldn't be investigated any further.

@zwpaper
Copy link
Member

zwpaper commented Dec 4, 2020

clap which is lsd used as cli framework can auto-generate the completions, here is the crate and example:

https://github.com/clap-rs/clap/tree/master/clap_generate

the only question is when should we generate the completions, prebuilt and can be used by curl, subcommand to generation on the fly or something else.

@zwpaper zwpaper changed the title zsh completion breaks when --date is used generate shell completion, bash, zsh and fish Dec 4, 2020
@meain
Copy link
Member

meain commented Dec 7, 2020

I think subcommand would be better as that way it would be easier to keep in sync for the user.

@zwpaper
Copy link
Member

zwpaper commented Dec 8, 2020

but subcommand may be confused with the files args

@meain
Copy link
Member

meain commented Dec 8, 2020

Ahh, I see your point. Guess we could do a flag instead of a subcommand. I am not sure if this is a common pattern but I have seen eval $(lsd --gen-completions) like things. Dropping something like this in a .bashrc should let them load the completions for the specific version they will be using.

@meain
Copy link
Member

meain commented Feb 5, 2021

Hey, this is something that I forgot earlier. lsd actually ships with completions in the release. I forgot about it as this is not a feature that I was using a lot.

The issue is that lsd does not seem to be doing file name completions in bash and zsh. fish seems to work well though. Will look into what might be going on in the build script.

@meain meain changed the title generate shell completion, bash, zsh and fish bash and zsh not completing filenames Feb 5, 2021
@meain meain added kind/bug Something isn't working and removed kind/feature New feature request priority/4-nice-to-have labels Feb 5, 2021
@meain
Copy link
Member

meain commented Feb 5, 2021

Looks like this is related to clap-rs/clap#568.

@m147
Copy link

m147 commented Sep 2, 2021

It's been some time since last comments.
Any fixes for this?

@avnigo
Copy link

avnigo commented Mar 1, 2022

I can confirm I'm getting the same behavior when using the --date flag on the latest release (0.21.0) in vanilla zsh (v5.8): tab completion gets stuck on options instead of filenames.

Filename completion only breaks when the --date flag is used before the filenames. If it is used after filenames, then it's fine, but it I would imagine most people would add the flags in the first part of the command, such as when using aliases.

I've tried putting the date flag in the config file to see if that would help, but unfortunately it doesn't. I also thought that using a double dash -- would help separate the flags from the arguments, but it doesn't seem to help.

One quick fix that works would be to use a glob expansion on the filename pattern. Another quick fix is function wrapping lsd and adding the date flag at the end, but this feels a bit hacky:

alias ls='() { lsd -F "$@" --color=always --date="date" ; }

@meain
Copy link
Member

meain commented Mar 2, 2022

I have few more questions on this:

  • Which distro/package manager are you using
  • Does filename completion work when it is just lsd <TAB>
  • Is it just --date that is causing issues or any arg
  • Does it autocomplete filenames when doing lsd --date='date' ./<TAB>
  • What is the output of complete -p lsd or which _lsd

@avnigo
Copy link

avnigo commented Mar 2, 2022

Which distro/package manager are you using?

Does filename completion work when it is just lsd <TAB>?

  • bash: nothing on first <TAB>, second <TAB> returns options
  • zsh: yes (first <TAB> shows all filenames, second <TAB> cycles through)

Is it just --date that is causing issues or any arg?

  • It seems that the --depth flag has the same issue. If I'm not mistaken, those are the only two flags that take variable arguments, as opposed to predefined ones like the rest, so the problem might be there, as if it can't figure out when your variable ends.

Does it autocomplete filenames when doing lsd --date='date' ./<TAB>?

  • bash: yes, also for partial match of filename (e.g. lsd --date='date' no<TAB> matches file notes)
  • zsh: no, not even for a partial match

What is the output of complete -p lsd or which _lsd?

  • bash:
$ complete -p lsd
complete -o bashdefault -o default -F _lsd lsd
  • zsh:
% which _lsd
_lsd () {
	# undefined
	builtin autoload -XUz
}

@Gerrit-K
Copy link
Author

Gerrit-K commented Mar 2, 2022

(chiming in again, out of curiosity and because I was able to reproduce it again)
For me:

Which distro/package manager are you using

macOS, installed lsd via the prebuilt binary from the GitHub releases page. Taken the zsh completions from there as well (_lsd)

Does filename completion work when it is just lsd <TAB>

Yes

Is it just --date that is causing issues or any arg

Not only --date but also, for instance, --depth. Just an assumption, but maybe it affects all options that take an additional argument. In addition to that, I noticed that lsd <file/directory> <TAB> results in the same behavior (i.e.: it's suggesting lsd options instead of filenames and folders). Edit: seems to match the observations from @avnigo as well :)

Does it autocomplete filenames when doing lsd --date='date' ./<TAB>

Nope. No suggestions at all in that case (probably because it's trying to match ./ in one of the options)

What is the output of complete -p lsd or which _lsd

`which _lsd`
_lsd () {
        typeset -A opt_args
        typeset -a _arguments_options
        local ret=1
        if is-at-least 5.2
        then
                _arguments_options=(-s -S -C)
        else
                _arguments_options=(-s -C)
        fi
        local context curcontext="$curcontext" state line
        _arguments "${_arguments_options[@]}" '*--color=[When to use terminal colours]: :(always auto never)' '*--icon=[When to print the icons]: :(always auto never)' '*--icon-theme=[Whether to use fancy or unicode icons]: :(fancy unicode)' '--config-file=[Provide a custom lsd configuration file]' '*--depth=[Stop recursing into directories after reaching specified depth]' '*--size=[How to display size]: :(default short bytes)' '*--date=[How to display date \[possible values: date, relative, +date-time-format\]]' '*--sort=[sort by WORD instead of name]: :(size time version extension)' '*--group-dirs=[Sort the directories then the files]: :(none first last)' '*--blocks=[Specify the blocks that will be displayed and in what order]: :(permission user group size date name inode links)' '*-I+[Do not display files/directories with names matching the glob pattern(s). More than one can be specified by repeating the argument]' '*--ignore-glob=[Do not display files/directories with names matching the glob pattern(s). More than one can be specified by repeating the argument]' '*-a[Do not ignore entries starting with .]' '*--all[Do not ignore entries starting with .]' '*-A[Do not list implied . and ..]' '*--almost-all[Do not list implied . and ..]' '*-F[Append indicator (one of */=>@|) at the end of the file names]' '*--classify[Append indicator (one of */=>@|) at the end of the file names]' '*-l[Display extended file metadata as a table]' '*--long[Display extended file metadata as a table]' '--ignore-config[Ignore the configuration file]' '*-1[Display one entry per line]' '*--oneline[Display one entry per line]' '(--tree)*-R[Recurse into directories]' '(--tree)*--recursive[Recurse into directories]' '*-h[For ls compatibility purposes ONLY, currently set by default]' '*--human-readable[For ls compatibility purposes ONLY, currently set by default]' '(-R --recursive)*--tree[Recurse into directories and present the result as a tree]' '(--depth -R --recursive)-d[Display directories themselves, and not their contents (recursively when used with --tree)]' '(--depth -R --recursive)--directory-only[Display directories themselves, and not their contents (recursively when used with --tree)]' '*--total-size[Display the total size of directories]' '*-t[Sort by time modified]' '*--timesort[Sort by time modified]' '*-S[Sort by size]' '*--sizesort[Sort by size]' '*-X[Sort by file extension]' '*--extensionsort[Sort by file extension]' '*-v[Natural sort of (version) numbers within text]' '*--versionsort[Natural sort of (version) numbers within text]' '*-r[Reverse the order of the sort]' '*--reverse[Reverse the order of the sort]' '--classic[Enable classic mode (display output similar to ls)]' '*--no-symlink[Do not display symlink target]' '*-i[Display the index number of each file]' '*--inode[Display the index number of each file]' '*-L[When showing file information for a symbolic link, show information for the file the link references rather than for the link itself]' '*--dereference[When showing file information for a symbolic link, show information for the file the link references rather than for the link itself]' '--help[Prints help information]' '-V[Prints version information]' '--version[Prints version information]' '::FILE:_files' && ret=0
}

@jmdaemon
Copy link

jmdaemon commented Sep 7, 2022

Has there been any progress on what's causing this? I appear to be having the same issue whenever I use lsd in general.

@madorb
Copy link

madorb commented Sep 8, 2022

this recently (today?) seems to have stopped working for me on my mac using zsh (seems to work okay in bash)

lsd <TAB> offers no file completion at all. just system beep.

@khughitt
Copy link

khughitt commented Sep 9, 2022

Similar issue on Arch Linux. Possibly related to v0.23 update?

--edit--

Just checked and reverting to v0.22 did indeed fix the issue.

@duhdugg
Copy link
Contributor

duhdugg commented Sep 9, 2022

submitted PR #741

@meain
Copy link
Member

meain commented Sep 10, 2022

Should now be fixed in the next release via #741 .

@meain meain closed this as completed Sep 10, 2022
@TeamTamoad
Copy link
Contributor

@meain Are you planning to release a new version soon? Should we release this now as 0.23.1?

@meain
Copy link
Member

meain commented Sep 12, 2022

We just made a release, so I was not planning on making another release that soon. Probably in another month or two once we land the custom icon pr in #707 and a few related config changes.

@duhdugg
Copy link
Contributor

duhdugg commented Sep 12, 2022

Temporary fix prior to the next release: https://gist.github.com/duhdugg/02773ab1cb4c4f9b328c739b9f991712?permalink_comment_id=4298545#gistcomment-4298545

@madorb
Copy link

madorb commented Sep 12, 2022

@meain considering lsd is functionally "broken" for lots of general use cases for those of us being hit by this, would a sooner release not be feasible?

@grimm26
Copy link

grimm26 commented Sep 12, 2022

releases are expensive. https://www.youtube.com/watch?v=dLJTgvKFZoQ

@meain
Copy link
Member

meain commented Sep 13, 2022

0.23.1 is now out with this fix :D

@vherbert
Copy link

vherbert commented Oct 20, 2022

I cant complete filename with lsd -I "*#". Instead, it completes flag.

  • lsd 0.22.0
  • zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
  • Ubuntu 22.04.1 LTS

Capture d’écran du 2022-10-20 11-12-21

@vherbert
Copy link

Same issue after updating lsd.

lsd 0.23.1

@meain
Copy link
Member

meain commented Oct 24, 2022

@vherbert At least from the screenshot, the behavior looks correct. It is supposed to complete options when it starts with -.

@vherbert
Copy link

vherbert commented Oct 24, 2022

Problem is that tab adds - and thus options are then completed when I retype tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests