Skip to content

Commit d94e022

Browse files
committed
Implement plugin hook to customize executable path
This feature allows the plugin to optionally change the executable path of a shim prior to execution. This is useful when the plugin tool has commands that may exist in multiple locations (like npm).
1 parent 27b5e21 commit d94e022

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

bin/private/asdf-exec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ for version in "${versions[@]}"; do
2727
exit 127
2828
fi
2929

30+
# custom plugin hook for executable path
31+
if [ -f "${plugin_path}/bin/exec-path" ]; then
32+
cmd=$(basename "$executable_path")
33+
executable_path="$("${plugin_path}/bin/exec-path" "$install_path" "$cmd" "$executable_path")"
34+
fi
35+
3036
if full_executable_path=$(get_executable_path "$plugin_name" "$version" "$executable_path"); then
3137
if [ -f "$full_executable_path" ]; then
3238
if [ -f "${plugin_path}/bin/exec-env" ]; then

docs/creating-plugins.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ If this script is not specified, asdf will look for the `bin` dir in an installa
5757

5858
Setup the env to run the binaries in the package.
5959

60+
#### bin/exec-path
61+
62+
Get the executable path for the specified version of the tool. Must print a string with the relative executable path. This allows the plugin to conditionally override the shim's specified executable path, otherwise return the default path specified by the shim.
63+
64+
```
65+
Usage:
66+
plugin/bin/exec-path <install-path> <command> <executable-path>
67+
68+
Example Call:
69+
~/.asdf/plugins/foo/bin/exec-path "~/.asdf/installs/foo/1.0" "foo" "bin/foo"
70+
71+
Output:
72+
bin/foox
73+
```
74+
6075
#### bin/uninstall
6176

6277
Uninstalls a specific version of a tool.

0 commit comments

Comments
 (0)