asdf

Форк
0
/
asdf.nu 
256 строк · 7.4 Кб
1
def --env configure-asdf [] {
2
    $env.ASDF_DIR = (
3
      if ($env | get --ignore-errors ASDF_NU_DIR | is-empty) == false {
4
        $env.ASDF_NU_DIR
5
      }
6
      else if ($env | get --ignore-errors ASDF_DIR | is-empty) == false {
7
        $env.ASDF_DIR
8
      } else {
9
        print --stderr "asdf: Either ASDF_NU_DIR or ASDF_DIR must not be empty"
10
        return
11
      }
12
    )
13

14
    let shims_dir = (
15
      if ( $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
    )
21
    let 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

27
configure-asdf
28

29
## Completions
30

31
module asdf {
32

33
    def "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

56
    def "complete asdf installed" [] {
57
        ^asdf plugin list | lines | each { |line| $line | str trim }
58
    }
59

60

61
    def "complete asdf plugin sub-commands" [] {
62
        [
63
            "list",
64
            "list all",
65
            "add",
66
            "remove",
67
            "update"
68
        ]
69
    }
70

71
    def "complete asdf installed plugins" [] {
72
        ^asdf plugin list | lines | each { |line|
73
            $line | str trim
74
        }
75
    }
76

77
    # ASDF version manager
78
    export extern main [
79
        subcommand?: string@"complete asdf sub-commands"
80
    ]
81

82
    # Manage plugins
83
    export extern "asdf plugin" [
84
        subcommand?: string@"complete asdf plugin sub-commands"
85
    ]
86

87
    # List installed plugins
88
    export def "asdf plugin list" [
89
        --urls # Show urls
90
        --refs # Show refs
91
    ] {
92

93
        let params = [
94
            {name: 'urls', enabled: $urls, flag: '--urls',
95
             template: '\s+?(?P<repository>(?:http[s]?|git).+\.git|/.+)'}
96
            {name: 'refs', enabled: $refs, flag: '--refs',
97
             template: '\s+?(?P<branch>\w+)\s+(?P<ref>\w+)'}
98
        ]
99

100
        let template = '(?P<name>.+)' + (
101
                            $params |
102
                            where enabled |
103
                            get --ignore-errors template |
104
                            str join '' |
105
                            str trim
106
                        )
107

108
        let 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
114
    export def "asdf plugin list all" [] {
115
        let template = '(?P<name>.+)\s+?(?P<installed>[*]?)(?P<repository>(?:git|http|https).+)'
116
        let is_installed = { |it| $it.installed == '*' }
117

118
        ^asdf plugin list all |
119
            lines |
120
            parse -r $template |
121
            str trim |
122
            update installed $is_installed |
123
            sort-by name
124
    }
125

126
    # Add a plugin
127
    export extern  "asdf plugin add" [
128
        name: string # Name of the plugin
129
        git_url?: string # Git url of the plugin
130
    ]
131

132
    # Remove an installed plugin and their package versions
133
    export extern "asdf plugin remove" [
134
        name: string@"complete asdf installed plugins" # Name of the plugin
135
    ]
136

137
    # Update a plugin
138
    export extern "asdf plugin update" [
139
        name: string@"complete asdf installed plugins" # Name of the plugin
140
        git_ref?: string # Git ref to update the plugin
141
    ]
142

143
    # Update all plugins to the latest commit
144
    export extern "asdf plugin update --all" []
145

146
    # install a package version
147
    export extern "asdf install" [
148
        name?: string # Name of the package
149
        version?: string # Version of the package or latest
150
    ]
151

152

153
    # Remove an installed package version
154
    export extern "asdf uninstall" [
155
        name: string@"complete asdf installed" # Name of the package
156
        version: string # Version of the package
157
    ]
158

159
    # Display current version
160
    export extern "asdf current" [
161
        name?: string@"complete asdf installed" # Name of installed version of a package
162
    ]
163

164
    # Display path of an executable
165
    export extern "asdf which" [
166
        command: string # Name of command
167
    ]
168

169
    # Display install path for an installled package version
170
    export extern "asdf where" [
171
        name: string@"complete asdf installed" # Name of installed package
172
        version?: string # Version of installed package
173
    ]
174

175
    # Set the package local version
176
    export extern "asdf local" [
177
        name: string@"complete asdf installed" # Name of the package
178
        version?: string # Version of the package or latest
179
    ]
180

181
    # Set the package global version
182
    export extern "asdf global" [
183
        name: string@"complete asdf installed" # Name of the package
184
        version?: string # Version of the package or latest
185
    ]
186

187
    # Set the package to version in the current shell
188
    export extern "asdf shell" [
189
        name: string@"complete asdf installed" # Name of the package
190
        version?: string # Version of the package or latest
191
    ]
192

193
    # Show latest stable version of a package
194
    export extern "asdf latest" [
195
        name: string # Name of the package
196
        version?: string # Filter latest stable version from this version
197
    ]
198

199
    # Show latest stable version for all installed packages
200
    export extern "asdf latest --all" []
201

202
    # List installed package versions
203
    export extern "asdf list" [
204
        name?: string@"complete asdf installed" # Name of the package
205
        version?: string # Filter the version
206
    ]
207

208
    # List all available package versions
209
    export def "asdf list all" [
210
        name: string@"complete asdf installed" # Name of the package
211
        version?: string="" # Filter the version
212
    ]    {
213
        ^asdf list all $name $version | lines | parse "{version}" | str trim
214
    }
215

216
    # Show documentation for plugin
217
    export extern "asdf help" [
218
        name: string@"complete asdf installed" # Name of the plugin
219
        version?: string # Version of the plugin
220
    ]
221

222
    # Execute a command shim for the current version
223
    export extern "asdf exec" [
224
        command: 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
229
    export extern "asdf env" [
230
        command?: string # Name of the command
231
        util?: string = 'env' # Name of util to run
232
    ]
233

234
    # Show information about OS, Shell and asdf Debug
235
    export extern "asdf info" []
236

237
    # Recreate shims for version package
238
    export extern "asdf reshim" [
239
        name?: string@"complete asdf installed" # Name of the package
240
        version?: string # Version of the package
241
    ]
242

243
    # List the plugins and versions that provide a command
244
    export extern "asdf shim-version" [
245
        command: string # Name of the command
246
    ]
247

248
    # Update asdf to the latest version on the stable branch
249
    export extern "asdf update" []
250

251
    # Update asdf to the latest version on the main branch
252
    export extern "asdf update --head" []
253

254
}
255

256
use asdf *
257

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.