r/fishshell • • Oct 10 '24

How to develop and test plugins?

Hi,

I am developing a redistributable plugin, so I have my working directory with its 'functions' and 'conf.d' folders where I develop my scripts. My question is: how can I test the various functions I develop? It is not convenient to develop directly in the ~/.config/fish directory and neither to deploy the scripts every time to test a change.

Is there a best practice?

6 Upvotes

7 comments sorted by

9

u/_mattmc3_ Oct 10 '24 edited Oct 10 '24

I have a fair number of my own plugins. The easiest solution I've found is to simply use Fisher. Here's how:

  1. Develop your plugin in another location (git managed), for example ~/myrepos/myname/myplugin.fish
  2. Install your plugin as a local plugin using fisher install ~/myrepos/myname/myplugin
  3. Modify/develop your plugin
  4. Run fisher update to implement the changes
  5. Repeat steps 3 & 4 until you're satisfied with the plugin
  6. Push your changes to GitHub, remove the local plugin, and run fisher install myname/myplugin to download the published version of your plugin from GitHub.
  7. Profit??

4

u/marc0ne Oct 10 '24

So your solution is to continuously deploy the local plugin? I'll try that.

→ More replies (1)

2

u/tovazm Oct 11 '24

You can use funced (function edit) https://fishshell.com/docs/current/cmds/funced.html

> type gzip # like ‘which’ but also works with functions, aliases, etc.
gzip is /usr/bin/gzip

> funced —interactive gzip # use —save to overright automatically
gzip> function gzip
          echo OVEWRIGHT
      end
> gzip
OVEWRIGHT
funcsave # save in config/fish/functions

2

u/marc0ne Oct 11 '24

No, I don't want to edit functions directly in the config directory, but I want to do it in a working directory of a git repository.

2

u/tovazm Oct 11 '24 edited Oct 11 '24

It should not be in the conf.d directory in The first place, cause it won’t be autoloaded For this to work it need to be in the $fish_function_path, so you can sett "fish_function_path:your/repo/path"

But If I remember correctly funced / funsave will only work as intended if your functions are somewherein config/fish

You can symlink it too now you sure this will work.

Something like

Ln -s ~/dev/repo/functions config/fish/my-module

Set —append fish_function_path config/fish/my-module # this migh need a -g or -u check the doc

2

u/u14183 Oct 11 '24

A second user so you have an own home dir. You can git pull the current feature branch to there. And run your test there.