https://github.com/pfgray/fish-completion-sync
A fish plugin to help dynamically load fish completions from `$XDG_DATA_DIRS`.
https://github.com/pfgray/fish-completion-sync
Last synced: about 1 month ago
JSON representation
A fish plugin to help dynamically load fish completions from `$XDG_DATA_DIRS`.
- Host: GitHub
- URL: https://github.com/pfgray/fish-completion-sync
- Owner: pfgray
- Created: 2023-03-09T14:41:31.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-08-01T17:25:16.000Z (almost 2 years ago)
- Last Synced: 2025-03-25T08:11:15.311Z (about 2 months ago)
- Language: Shell
- Size: 6.84 KB
- Stars: 10
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# fish-completion-sync
A fish plugin to help dynamically load fish completions from `$XDG_DATA_DIRS`.
## Installation
### home-manager
```nix
{
programs.fish = {
# ...
plugins = [
#...
{
name = "fish-completion-sync";
src = pkgs.fetchFromGitHub {
owner = "pfgray";
repo = "fish-completion-sync";
rev = "ba70b6457228af520751eab48430b1b995e3e0e2";
sha256 = "sha256-JdOLsZZ1VFRv7zA2i/QEZ1eovOym/Wccn0SJyhiP9hI=";
};
}
];
};
}
```### fisher
```
fisher install pfgray/fish-completion-sync
```## Why
Fish only considers `$XDG_DATA_DIRS` on shell startup, and thus will not dynamically load completions if `$XDG_DATA_DIRS` changes sometime after the shell starts. This leads to problems when using tools like [direnv](https://github.com/direnv/direnv), which try to add completions on a per-folder basis.
This plugin tries to alleviate this issue.
tl;dr; it's the bit of glue between:
https://github.com/fish-shell/fish-shell/issues/8261
and:
https://github.com/direnv/direnv/issues/443## How it works
Fish _will_ search `$fish_complete_path` dynamically, so the idea is to implement a function which listens for changes to `$XDG_DATA_DIRS`, and attempts to keep that in sync with `$fish_complete_path`.
```
function fish_completion_sync --on-variable XDG_DATA_DIRS
# If there are paths in $FISH_COMPLETION_ADDITIONS,
# but not in $XDG_DATA_DIRS
# remove them from $fish_complete_path
# remove them from $FISH_COMPLETION_ADDITIONS# if there are paths in $XDG_DATA_DIRS
# but not in $FISH_COMPLETION_ADDITIONS
# add them to $fish_complete_path
# add them to $FISH_COMPLETION_ADDITIONSecho "got new data dirs: $XDG_DATA_DIRS"
end
```### Caveats
This has been working well for me, but it's stopped working a few times, and I haven't been able to pinpoint why. If you experience this, you can set the environment variable `FISH_COMPLETION_DEBUG` to help debug:
```fish
set -x FISH_COMPLETION_DEBUG 1
```Submit an issue if the problem persists.