Asdf: Plugin uninstall does not remove that plugin's shims

Created on 21 Jun 2016  ·  6Comments  ·  Source: asdf-vm/asdf

Steps to reproduce

$ asdf plugin-add ruby https://github.com/asdf-vm/asdf-ruby.git
$ asdf install ruby 2.3.1
$ asdf global ruby 2.3.1
$ gem install bundler
$ asdf plugin-remove ruby
$ bundle
No such plugin

Observed behavior

Removing a plugin, leaves it's shims in the asdf shims directory, which leaves them polluting my PATH.

Expected behavior

When removing a plugin, all it's shims are removed as well. Calling bundle should give a "command not found" error.

bug

Most helpful comment

Yeah, the downside is that you need to loop over that directory and add everything to the PATH. A huge PATH might actually be a dealbreaker.

Another option is to add a comment to each shim with the metadata about which plugin it belongs to.

echo """#!/usr/bin/env bash
# asdf-plugin: ${plugin_name}
exec $(asdf_dir)/bin/private/asdf-exec ${plugin_name} ${executable_path} \"\$@\"
""" > $shim_path

Then grep for files containing that line and remove those? Plugins using custom shims would need to be aware of this though.

All 6 comments

@duijf true. We should fix this ~!

So I thought about this a bit, and I think the simplest way to go about things is to namespace the directory shims are stored per plugin. So instead of this:

❯ ls ~/.asdf/shims/ 
bundle*    elixirc*  escript*   listen*     rake*     sass-convert*
bundler*   epmd*     gem*       middleman*  rdoc*     scss*
ct_run*    erb*      haml*      mix*        ri*       thor*
dialyzer*  erl*      iex*       node*       ruby*     tilt*
dotenv*    erlc*     irb*       npm*        run_erl*  to_erl*
elixir*    erubis*   kramdown*  rackup*     sass*     typer*

Doing something like this:

❯ ls ~/.asdf/shims/ 
ruby/   elixir/    nodejs/    erlang/

And having asdf plugin-remove do a rm -r ~/.asdf/shims/<plugin-name>

I'll see if I can help with a PR, if this works for you.

@duijf I went with this because it makes the importing of shims easier (only one dir to add to PATH). But I have this feeling that I might have missed something. Any suggestions to make adding to PATH easier but keep the per-plugin shim dir like you mentioned?

cc: @asdf-vm/maintainers

Yeah, the downside is that you need to loop over that directory and add everything to the PATH. A huge PATH might actually be a dealbreaker.

Another option is to add a comment to each shim with the metadata about which plugin it belongs to.

echo """#!/usr/bin/env bash
# asdf-plugin: ${plugin_name}
exec $(asdf_dir)/bin/private/asdf-exec ${plugin_name} ${executable_path} \"\$@\"
""" > $shim_path

Then grep for files containing that line and remove those? Plugins using custom shims would need to be aware of this though.

@duijf Yes adding metadata to shim is a smart idea sire ~! Thanks for sharing this. We'll go that route.

I like the idea of metadata in the shim too!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rhiroyuki picture rhiroyuki  ·  3Comments

dmlemos picture dmlemos  ·  3Comments

Quintasan picture Quintasan  ·  5Comments

robsonpeixoto picture robsonpeixoto  ·  4Comments

jthegedus picture jthegedus  ·  3Comments