Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix symlink for bash completions#1889

Open
skane-lukas wants to merge 7 commits intosharkdp:masterfrom
skane-lukas:issue-1888-fix-symlink-bash-completion
Open

Fix symlink for bash completions#1889
skane-lukas wants to merge 7 commits intosharkdp:masterfrom
skane-lukas:issue-1888-fix-symlink-bash-completion

Conversation

@skane-lukas
Copy link

Problem

In the deb package a broken symlink is created for bash completions to the alias command fdfind.

Solution

Change the symlink target for the fdfind bash completion

Changes

  • Changed symlink target for completion fdfind in create-deb from ./fd.bash to ./fd
  • Updated CHANGELOG.md with the fix.

fixes #1888

@skane-lukas
Copy link
Author

skane-lukas commented Feb 20, 2026

The completions still dont work because they are generated for fd and not fdfind.

I can only think of changing the symlinks in create-deb.sh to something like:

ln -sf "/usr/bin/fd" "${DPKG_DIR}/usr/bin/fdfind"

"${DPKG_DIR}/usr/bin/fdfind" --gen-completions bash > autocomplete/fdfind.bash
"${DPKG_DIR}/usr/bin/fdfind" --gen-completions fish > autocomplete/fdfind.fish
"${DPKG_DIR}/usr/bin/fdfind" --gen-completions powershell > autocomplete/_fdfind.ps1
# Generate Zsh completion by substituting top row of static completion file
sed '1s/^#compdef fd/#compdef fdfind/' autocomplete/_fd > autocomplete/_fdfind

install -Dm644 autocomplete/fdfind.bash "${DPKG_DIR}/usr/share/bash-completion/completions/fdfind"
install -Dm644 autocomplete/fdfind.fish "${DPKG_DIR}/usr/share/fish/vendor_completions.d/fdfind.fish"
install -Dm644 autocomplete/_fdfind.ps1 "${DPKG_DIR}/usr/share/powershell/Modules/fdfind/_fdfind.ps1"
install -Dm644 autocomplete/_fdfind "${DPKG_DIR}/usr/share/zsh/vendor-completions/_fdfind"

I am not sure if there is a better way to do this.

@tmccombs
Copy link
Collaborator

I wonder if it would be better for the fdfind completions to call the fd completions, rather than duplicating them

@skane-lukas
Copy link
Author

skane-lukas commented Feb 24, 2026

I agree that would be ideal.

For bash the fdfind could look like:

# Source fd completions
source /usr/share/bash-completion/completions/fd

# Complete with same options as fd
eval "$(complete -p fd | sed 's/ fd$/ fdfind/')"
# Or
#if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
#    complete -F _fd -o nosort -o bashdefault -o default fdfind
#else
#    complete -F _fd -o bashdefault -o default fdfind
#fi

Bash completions are evaluated lazily so a side efffect would be that the completions for fd would be registered when completions for fdfind are triggered in the terminal.

similar apply to zsh

#compdef fdfind

# Source completions from fd
source /usr/share/zsh/vendor-completions/_fd

# Register completions for fdfind
compdef _fd fdfind

For fish the --wraps flag could be used and a completion file could look like:

complete -c fdfind --wraps fd

This seem to work without sourcing anything else.

I am not sure about powershell.
Is this a better approach?

Could these completion files be generated in the create-deb.sh script or should they be static files in contrib/completions?

Another direction could be to append the code snippets for registering the completions in the fd completion files and keeping the symlinks.

@tmccombs
Copy link
Collaborator

That seems like a better approach to me, although I don't know how to do it for Powershell either.

I think putting those in contrib/completions would be fine

Use autoload instead of source for zsh
Dont use complete command to catch options for compdef in bash
@villarroelgj
Copy link

The current implementation looks good directionally, but there's a build gap that needs fixing before merge.

create-deb.sh now installs from autocomplete/fdfind.bash, autocomplete/fdfind.fish, and autocomplete/_fdfind, but the Makefile was not updated to generate those files. The autocomplete/ directory is built by make it is not checked into the repo.completions

You'll need to add Makefile targets similar to:

autocomplete/fdfind.bash: contrib/completion/fdfind.bash
knowledge.md $(comp_dir)
knowledge.md cp $< $@

autocomplete/fdfind.fish: contrib/completion/fdfind.fish
knowledge.md $(comp_dir)
knowledge.md cp $< $@

autocomplete/_fdfind: contrib/completion/_fdfind
knowledge.md $(comp_dir)
knowledge.md cp $< $@

And add autocomplete/fdfind.bash autocomplete/fdfind.fish autocomplete/_fdfind as dependencies of the completions target. Without this, the deb build will fail with "no such file."

Otherwise the delegation approach (bash source + complete, zsh _fd "$@", fish --wraps) looks clean. Once this is fixed, could @tmccombs do a formal review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bash completions do not work for alias fdfind in deb release

3 participants