## What's new - color completion message command green https://github.com/versenilvis/IRIS/pull/10/commits/6e141f5e6909fad1ec42725cce38d51729acf399 - new flat command folder structure https://github.com/versenilvis/IRIS/pull/10/commits/87026a854a529ec5d5baed967d5f7a7f0085a24b - fix some linter problems https://github.com/versenilvis/IRIS/pull/10/commits/536de790cefda912f50bf4022e40ce2b965db2e2 - fix some gemini fix suggestions
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package sys
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/versenilvis/iris/commands/core"
|
|
)
|
|
|
|
func envVarGenerator(tokens []string, _ string, _ string) []core.Suggestion {
|
|
var results []core.Suggestion
|
|
for _, env := range os.Environ() {
|
|
parts := strings.SplitN(env, "=", 2)
|
|
name := parts[0]
|
|
val := ""
|
|
if len(parts) == 2 {
|
|
val = parts[1]
|
|
// truncate long values
|
|
if len(val) > 60 {
|
|
val = val[:57] + "..."
|
|
}
|
|
}
|
|
results = append(results, core.Suggestion{Cmd: name, Desc: val})
|
|
}
|
|
return results
|
|
}
|
|
|
|
func init() {
|
|
core.Register(&core.Spec{
|
|
Name: "export",
|
|
Description: "set environment variable",
|
|
Generator: envVarGenerator,
|
|
})
|
|
|
|
core.Register(&core.Spec{
|
|
Name: "env",
|
|
Description: "print environment",
|
|
Generator: envVarGenerator,
|
|
Options: []core.Option{
|
|
{Name: "-i", Description: "start with empty env"},
|
|
{Name: "-u", Description: "unset variable"},
|
|
{Name: "-0", Description: "null delimited"},
|
|
},
|
|
})
|
|
|
|
core.Register(&core.Spec{
|
|
Name: "printenv",
|
|
Description: "print environment variables",
|
|
Generator: envVarGenerator,
|
|
})
|
|
|
|
core.Register(&core.Spec{
|
|
Name: "unset",
|
|
Description: "unset variable",
|
|
Generator: envVarGenerator,
|
|
})
|
|
}
|