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