New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Elvish Shell support #1066
Changes from 30 commits
1af3e99
e8e631c
6e8cf29
242b88d
6baada0
2b034c9
5bb00bb
1f1f570
dfdb59c
8f7ea81
b05968f
8c7fb68
7cabf9b
1a15a53
5186c1a
cec89d7
6b49ba2
207f1c1
384f450
02069ff
9ba6749
1295224
84f073a
2c9529b
f871425
fa84123
9036d91
ab495ff
0b006ed
4383fbe
624949c
0b41485
e697aab
2538279
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
installs | ||
/installs | ||
/downloads | ||
/plugins | ||
shims | ||
/shims | ||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How were you testing that required these changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added asdf install nim 1.4.8 --keep-download I added leading slashes to the other entries because https://stackoverflow.com/a/38433961:
My understanding is that this makes sure other, nested items with the same name won't be excluded. |
||
repository | ||
.vagrant | ||
keyrings | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
|
||
use re | ||
use str | ||
use path | ||
|
||
var asdf_dir = $E:HOME'/.asdf' | ||
if (and (has-env ASDF_DIR) (!=s $E:ASDF_DIR '')) { | ||
asdf_dir = $E:ASDF_DIR | ||
} else { | ||
set-env ASDF_DIR $asdf_dir | ||
} | ||
|
||
var asdf_data_dir = $asdf_dir | ||
if (and (has-env ASDF_DATA_DIR) (!=s $E:ASDF_DATA_DIR '')) { | ||
asdf_data_dir = $E:ASDF_DATA_DIR | ||
} | ||
|
||
# Add function wrapper so we can export variables | ||
fn asdf [command @args]{ | ||
if (==s $command 'shell') { | ||
# set environment variables | ||
parts = [($asdf_dir'/bin/asdf' export-shell-version elvish $@args)] | ||
if (==s $parts[0] 'set-env') { | ||
set-env $parts[1] $parts[2] | ||
} elif (==s $parts[0] 'unset-env') { | ||
unset-env $parts[1] | ||
} | ||
} else { | ||
# forward other commands to asdf script | ||
$asdf_dir'/bin/asdf' $command $@args | ||
} | ||
} | ||
|
||
fn match [argz name]{ | ||
var num = (count $argz) | ||
if (== $num 0) { | ||
==s $name '' | ||
} elif (==s $name $argz[0]) { | ||
== $num 1 | ||
} else { | ||
==s $name (str:join '-' $argz) | ||
} | ||
} | ||
|
||
fn match-nested [argz @pattern]{ | ||
var matched = $true; | ||
if (!= (count $argz) (count $pattern)) { | ||
matched = $false | ||
} else { | ||
for i [(range (count $pattern))] { | ||
chunk = $pattern[$i] | ||
if (and (!=s $chunk '*') (!=s $chunk $argz[$i])) { | ||
matched = $false | ||
break | ||
} | ||
} | ||
} | ||
put $matched | ||
} | ||
|
||
fn ls-shims []{ | ||
ls $asdf_data_dir'/shims' | ||
} | ||
|
||
fn ls-executables []{ | ||
# Print all executable files and links in path | ||
try { | ||
find $@paths '(' -type f -o -type l ')' -print 2>/dev/null | each [p]{ | ||
try { | ||
if (test -x $p) { | ||
path:base $p | ||
} | ||
} except { | ||
# don't fail if permission denied | ||
} | ||
} | ||
} except { | ||
# silence default non-zero exit status | ||
} | ||
} | ||
|
||
fn ls-installed-versions [plugin_name]{ | ||
asdf list $plugin_name | each [version]{ | ||
put (re:replace '^\s*(.*)\s*' '${1}' $version) | ||
} | ||
} | ||
|
||
fn ls-all-versions [plugin_name]{ | ||
asdf list-all $plugin_name | each [version]{ | ||
put (re:replace '^\s*(.*)\s*' '${1}' $version) | ||
} | ||
} | ||
|
||
# Append ~/.asdf/bin and ~/.asdf/shims to PATH | ||
for path [ | ||
$asdf_dir'/bin' | ||
$asdf_data_dir'/shims' | ||
] { | ||
if (not (has-value $paths $path)) { | ||
paths = [ | ||
$@paths | ||
$path | ||
] | ||
} | ||
} | ||
|
||
# Setup argument completions | ||
fn arg-completer [@argz]{ | ||
argz = $argz[1:-1] # strip 'asdf' and trailing empty string | ||
var num = (count $argz) | ||
if (== $num 0) { | ||
# list all subcommands | ||
find $asdf_dir'/lib/commands' -name 'command-*' | each [cmd]{ | ||
put (re:replace '.*/command-(.*)\.bash' '${1}' $cmd) | ||
} | ||
put 'plugin' | ||
put 'list' | ||
} else { | ||
if (match $argz 'current') { | ||
# asdf current <name> | ||
asdf plugin-list | ||
} elif (match $argz 'env') { | ||
# asdf env <command> | ||
ls-shims | ||
} elif (match-nested $argz 'env' '*') { | ||
# asdf env <command> [util] | ||
ls-executables | ||
} elif (match $argz 'exec') { | ||
# asdf exec <command> | ||
ls-shims | ||
} elif (match $argz 'global') { | ||
# asdf global <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'global' '*') { | ||
# asdf global <name> <version> | ||
ls-installed-versions $argz[-1] | ||
} elif (match $argz 'install') { | ||
# asdf install <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'install' '*') { | ||
# asdf install <name> <version> | ||
ls-all-versions $argz[-1] | ||
} elif (match-nested $argz 'install' '*' '*') { | ||
# asdf install <name> <version> [--keep-download] | ||
put '--keep-download' | ||
} elif (match $argz 'latest') { | ||
# asdf latest <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'latest' '*') { | ||
# asdf latest <name> [<version>] | ||
ls-all-versions $argz[-1] | ||
} elif (match $argz 'list-all') { | ||
# asdf list all <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'list-all' '*') { | ||
# asdf list all <name> [<version>] | ||
ls-all-versions $argz[-1] | ||
} elif (match $argz 'list') { | ||
# asdf list <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'list' '*') { | ||
# asdf list <name> [<version>] | ||
ls-installed-versions $argz[-1] | ||
} elif (match $argz 'local') { | ||
# asdf local <name> [-p] [--parent] | ||
asdf plugin-list | ||
} elif (match-nested $argz 'local' '*') { | ||
# asdf local <name> [<version>] [-p] [--parent] | ||
# asdf local <name> [<version>] | ||
ls-installed-versions $argz[-1] | ||
put '-p' | ||
put '--parent' | ||
} elif (match $argz 'plugin-add') { | ||
# asdf plugin add <name> | ||
asdf plugin-list-all | each [line]{ | ||
put (re:replace '([^\s]+)\s+.*' '${1}' $line) | ||
} | ||
} elif (match $argz 'plugin-list') { | ||
# asdf plugin list | ||
put '--urls' | ||
put '--refs' | ||
put 'all' | ||
} elif (match $argz 'plugin-push') { | ||
# asdf plugin push <name> | ||
asdf plugin-list | ||
} elif (match $argz 'plugin-remove') { | ||
# asdf plugin remove <name> | ||
asdf plugin-list | ||
} elif (match $argz 'plugin-update') { | ||
# asdf plugin update <name> | ||
asdf plugin-list | ||
put '--all' | ||
} elif (match $argz 'plugin') { | ||
# list plugin-* subcommands | ||
find $asdf_dir'/lib/commands' -name 'command-plugin-*' | each [cmd]{ | ||
put (re:replace '.*/command-plugin-(.*)\.bash' '${1}' $cmd) | ||
} | ||
} elif (match $argz 'reshim') { | ||
# asdf reshim <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'reshim' '*') { | ||
# asdf reshim <name> <version> | ||
ls-installed-versions $argz[-1] | ||
} elif (match $argz 'shim-versions') { | ||
# asdf shim-versions <command> | ||
ls-shims | ||
} elif (match $argz 'uninstall') { | ||
# asdf uninstall <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'uninstall' '*') { | ||
# asdf uninstall <name> <version> | ||
ls-installed-versions $argz[-1] | ||
} elif (match $argz 'update') { | ||
if (== $num 1) { | ||
# asdf update | ||
put '--head' | ||
} | ||
} elif (match $argz 'where') { | ||
# asdf where <name> | ||
asdf plugin-list | ||
} elif (match-nested $argz 'where' '*') { | ||
# asdf where <name> [<version>] | ||
ls-installed-versions $argz[-1] | ||
} elif (match $argz 'which') { | ||
ls-shims | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this building elvish from source? Or is this just downloading a pre-built binary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Building from source - didn't take too long locally, but looks like there is a linux binary available, so using that instead. Changed in 2538279