joseluisq / gitnow

Speed up your Git workflow. :tropical_fish:
https://github.com/joseluisq/gitnow
MIT License
391 stars 25 forks source link

fisher with custom $fisher_path is not supported #51

Closed legeana closed 11 months ago

legeana commented 1 year ago

Issue

gitnow assumes that fisher installs plugin into user's $__fish_config_dir. This is not always the case. If a $fisher_path is used, the plugin fails to load and produces a lot of error messages on fish startup.

How to reproduce:

  1. Set $fisher_path to a custom path, e.g. ~/.local/share/fisher.
  2. Install fisher: curl ...
  3. Load $fisher_path/conf.d and add functions/completions to the appropriate paths in your own configuration as described in https://github.com/jorgebucaran/fisher/issues/640.
  4. Try to install gitnow and observe the failure:
    $ fisher install joseluisq/gitnow@2.11.0
    fisher install version 4.4.3
    Fetching https://api.github.com/repos/joseluisq/gitnow/tarball/2.11.0
    Installing joseluisq/gitnow@2.11.0
           /home/liri/.local/share/fisher/functions/__gitnow_config_file.fish
           /home/liri/.local/share/fisher/functions/__gitnow_functions.fish
           /home/liri/.local/share/fisher/functions/__gitnow_manual.fish
           /home/liri/.local/share/fisher/conf.d/gitnow.fish
           /home/liri/.local/share/fisher/conf.d/gitnow_config.fish
           /home/liri/.local/share/fisher/completions/__gitnow_completions.fish
    GitNow version  is installed and ready to use!
    Just run the `gitnow` command if you want explore the API.
    source: Error encountered while sourcing file '/home/liri/.config/fish/functions/__gitnow_functions.fish':
    source: No such file or directory
    source: Error encountered while sourcing file '/home/liri/.config/fish/functions/__gitnow_manual.fish':
    source: No such file or directory
    source: Error encountered while sourcing file '/home/liri/.config/fish/functions/__gitnow_config_file.fish':
    source: No such file or directory
    source: Error encountered while sourcing file '/home/liri/.config/fish/completions/__gitnow_completions.fish':
    source: No such file or directory
    Installed 1 plugin/s

I am pretty sure the issue is with gitnow_config.fish that tries to source fish functions directly. I am not sure why this is necessary.

Possible solutions

Check $fisher_path in gitnow_config.fish explicitly

Since $__fundle_plugins_dir is already queried in this file, checking $fisher_path could also be an option. This is how it looks on my PC after I install gitnow:

$ tree $fisher_path
/home/liri/.local/share/fisher
├── completions
│   ├── fisher.fish
│   └── __gitnow_completions.fish
├── conf.d
│   ├── gitnow_config.fish
│   └── gitnow.fish
├── functions
│   ├── fisher.fish
│   ├── __gitnow_config_file.fish
│   ├── __gitnow_functions.fish
│   └── __gitnow_manual.fish
└── themes

Make gitnow functions fish autoload-compliant

Don't explicitly source gitnow functions, and rely on $fish_function_path and other autoloaders to correctly load your plugin. For backward compatibility that can be done with something like set -q __gitnow_dont_autoload.

This will require splitting existing gitnow function files into multiple files, one file per gitnow function:

See how fish autoloads functions.

Move gitnow functions from functions to conf.d subdirectory

These functions will be loaded once by the plugin system, since conf.d is automatically sourced. And if these functions are ordered correctly, for example

This approach is not idiomatic in fish, but it will load these functions correctly, and there is no more need to source functions/*.fish files.

joseluisq commented 1 year ago

Great ideas to improve Gitnow to support $fisher_path!

And yes, I'm in favor of being Fish autoload-compliant so any help more than welcome.

joseluisq commented 11 months ago

FYI I'm refactoring Gitnow to be Fish autoload-compliant on #54.

However, in order to support a custom $fisher_path, #54 should be finished first.

joseluisq commented 11 months ago

I already tested a default and custom $fisher_path Fisher installation and both work as expected. Please try out the latest changes.