Skip to content

Instantly share code, notes, and snippets.

@ksoda
Created January 13, 2020 15:23
Show Gist options
  • Save ksoda/8794724abaeb32a7a1051daa041c34b9 to your computer and use it in GitHub Desktop.
Save ksoda/8794724abaeb32a7a1051daa041c34b9 to your computer and use it in GitHub Desktop.
Install a specific version of a package
//usr/bin/env go run "$0" "$@"; exit "$?"
package main
import (
"fmt"
"os"
"github.com/codeskyblue/go-sh"
)
func main() {
plugin := asdfWithSelect("plugin-list")
version := asdfWithSelect("list-all", plugin)
sh.Command("asdf", "install", plugin, version).Run()
}
func asdfWithSelect(args ...string) string {
lis := make([]interface{}, 0)
for _, v := range args {
lis = append(lis, v)
}
out, err := sh.Command("asdf", lis...).Command("fzf").Output()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
return string(out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment