asdf
/
asdf.nu
256 строк · 7.4 Кб
1def --env configure-asdf [] {
2$env.ASDF_DIR = (
3if ($env | get --ignore-errors ASDF_NU_DIR | is-empty) == false {
4$env.ASDF_NU_DIR
5}
6else if ($env | get --ignore-errors ASDF_DIR | is-empty) == false {
7$env.ASDF_DIR
8} else {
9print --stderr "asdf: Either ASDF_NU_DIR or ASDF_DIR must not be empty"
10return
11}
12)
13
14let shims_dir = (
15if ( $env | get --ignore-errors ASDF_DATA_DIR | is-empty ) {
16$env.HOME | path join '.asdf'
17} else {
18$env.ASDF_DIR
19} | path join 'shims'
20)
21let asdf_bin_dir = ( $env.ASDF_DIR | path join 'bin' )
22
23$env.PATH = ( $env.PATH | split row (char esep) | where { |p| $p != $shims_dir } | prepend $shims_dir )
24$env.PATH = ( $env.PATH | split row (char esep) | where { |p| $p != $asdf_bin_dir } | prepend $asdf_bin_dir )
25}
26
27configure-asdf
28
29## Completions
30
31module asdf {
32
33def "complete asdf sub-commands" [] {
34[
35"plugin",
36"list",
37"install",
38"uninstall",
39"current",
40"where",
41"which",
42"local",
43"global",
44"shell",
45"latest",
46"help",
47"exec",
48"env",
49"info",
50"reshim",
51"shim-version",
52"update"
53]
54}
55
56def "complete asdf installed" [] {
57^asdf plugin list | lines | each { |line| $line | str trim }
58}
59
60
61def "complete asdf plugin sub-commands" [] {
62[
63"list",
64"list all",
65"add",
66"remove",
67"update"
68]
69}
70
71def "complete asdf installed plugins" [] {
72^asdf plugin list | lines | each { |line|
73$line | str trim
74}
75}
76
77# ASDF version manager
78export extern main [
79subcommand?: string@"complete asdf sub-commands"
80]
81
82# Manage plugins
83export extern "asdf plugin" [
84subcommand?: string@"complete asdf plugin sub-commands"
85]
86
87# List installed plugins
88export def "asdf plugin list" [
89--urls # Show urls
90--refs # Show refs
91] {
92
93let params = [
94{name: 'urls', enabled: $urls, flag: '--urls',
95template: '\s+?(?P<repository>(?:http[s]?|git).+\.git|/.+)'}
96{name: 'refs', enabled: $refs, flag: '--refs',
97template: '\s+?(?P<branch>\w+)\s+(?P<ref>\w+)'}
98]
99
100let template = '(?P<name>.+)' + (
101$params |
102where enabled |
103get --ignore-errors template |
104str join '' |
105str trim
106)
107
108let flags = ($params | where enabled | get --ignore-errors flag | default '' )
109
110^asdf plugin list $flags | lines | parse -r $template | str trim
111}
112
113# list all available plugins
114export def "asdf plugin list all" [] {
115let template = '(?P<name>.+)\s+?(?P<installed>[*]?)(?P<repository>(?:git|http|https).+)'
116let is_installed = { |it| $it.installed == '*' }
117
118^asdf plugin list all |
119lines |
120parse -r $template |
121str trim |
122update installed $is_installed |
123sort-by name
124}
125
126# Add a plugin
127export extern "asdf plugin add" [
128name: string # Name of the plugin
129git_url?: string # Git url of the plugin
130]
131
132# Remove an installed plugin and their package versions
133export extern "asdf plugin remove" [
134name: string@"complete asdf installed plugins" # Name of the plugin
135]
136
137# Update a plugin
138export extern "asdf plugin update" [
139name: string@"complete asdf installed plugins" # Name of the plugin
140git_ref?: string # Git ref to update the plugin
141]
142
143# Update all plugins to the latest commit
144export extern "asdf plugin update --all" []
145
146# install a package version
147export extern "asdf install" [
148name?: string # Name of the package
149version?: string # Version of the package or latest
150]
151
152
153# Remove an installed package version
154export extern "asdf uninstall" [
155name: string@"complete asdf installed" # Name of the package
156version: string # Version of the package
157]
158
159# Display current version
160export extern "asdf current" [
161name?: string@"complete asdf installed" # Name of installed version of a package
162]
163
164# Display path of an executable
165export extern "asdf which" [
166command: string # Name of command
167]
168
169# Display install path for an installled package version
170export extern "asdf where" [
171name: string@"complete asdf installed" # Name of installed package
172version?: string # Version of installed package
173]
174
175# Set the package local version
176export extern "asdf local" [
177name: string@"complete asdf installed" # Name of the package
178version?: string # Version of the package or latest
179]
180
181# Set the package global version
182export extern "asdf global" [
183name: string@"complete asdf installed" # Name of the package
184version?: string # Version of the package or latest
185]
186
187# Set the package to version in the current shell
188export extern "asdf shell" [
189name: string@"complete asdf installed" # Name of the package
190version?: string # Version of the package or latest
191]
192
193# Show latest stable version of a package
194export extern "asdf latest" [
195name: string # Name of the package
196version?: string # Filter latest stable version from this version
197]
198
199# Show latest stable version for all installed packages
200export extern "asdf latest --all" []
201
202# List installed package versions
203export extern "asdf list" [
204name?: string@"complete asdf installed" # Name of the package
205version?: string # Filter the version
206]
207
208# List all available package versions
209export def "asdf list all" [
210name: string@"complete asdf installed" # Name of the package
211version?: string="" # Filter the version
212] {
213^asdf list all $name $version | lines | parse "{version}" | str trim
214}
215
216# Show documentation for plugin
217export extern "asdf help" [
218name: string@"complete asdf installed" # Name of the plugin
219version?: string # Version of the plugin
220]
221
222# Execute a command shim for the current version
223export extern "asdf exec" [
224command: string # Name of the command
225...args: any # Arguments to pass to the command
226]
227
228# Run util (default: env) inside the environment used for command shim execution
229export extern "asdf env" [
230command?: string # Name of the command
231util?: string = 'env' # Name of util to run
232]
233
234# Show information about OS, Shell and asdf Debug
235export extern "asdf info" []
236
237# Recreate shims for version package
238export extern "asdf reshim" [
239name?: string@"complete asdf installed" # Name of the package
240version?: string # Version of the package
241]
242
243# List the plugins and versions that provide a command
244export extern "asdf shim-version" [
245command: string # Name of the command
246]
247
248# Update asdf to the latest version on the stable branch
249export extern "asdf update" []
250
251# Update asdf to the latest version on the main branch
252export extern "asdf update --head" []
253
254}
255
256use asdf *
257