lsd
lsd copied to clipboard
bash and zsh not completing filenames
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 -*).
I have tried the lsd --date='date' <TAB> but it shows the files like this:

could you add:
- the version of lsd
- the version of zsh
- did you use some extensions like
oh-my-zshor something others
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.
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.
I think subcommand would be better as that way it would be easier to keep in sync for the user.
but subcommand may be confused with the files args
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.
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.
Looks like this is related to https://github.com/clap-rs/clap/issues/568.
It's been some time since last comments. Any fixes for this?
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" ; }
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
--datethat is causing issues or any arg - Does it autocomplete filenames when doing
lsd --date='date' ./<TAB> - What is the output of
complete -p lsdorwhich _lsd
Which distro/package manager are you using?
- Ubuntu 20.04.4 LTS: installed from release 0.21.0
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
--datethat is causing issues or any arg?
- It seems that the
--depthflag 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 filenotes) - zsh: no, not even for a partial match
What is the output of
complete -p lsdorwhich _lsd?
- bash:
$ complete -p lsd
complete -o bashdefault -o default -F _lsd lsd
- zsh:
% which _lsd
_lsd () {
# undefined
builtin autoload -XUz
}
(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
--datethat 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 lsdorwhich _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
}
Has there been any progress on what's causing this? I appear to be having the same issue whenever I use lsd in general.
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.
Similar issue on Arch Linux. Possibly related to v0.23 update?
--edit--
Just checked and reverting to v0.22 did indeed fix the issue.
submitted PR #741
Should now be fixed in the next release via #741 .
@meain Are you planning to release a new version soon? Should we release this now as 0.23.1?
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.
Temporary fix prior to the next release: https://gist.github.com/duhdugg/02773ab1cb4c4f9b328c739b9f991712?permalink_comment_id=4298545#gistcomment-4298545
@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?
releases are expensive. https://www.youtube.com/watch?v=dLJTgvKFZoQ
0.23.1 is now out with this fix :D
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

Same issue after updating lsd.
lsd 0.23.1
@vherbert At least from the screenshot, the behavior looks correct. It is supposed to complete options when it starts with -.
Problem is that tab adds - and thus options are then completed when I retype tab.