Skip to content

Commit

Permalink
Adding \getenv metacommand
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Mar 27, 2024
1 parent 5b7cfbb commit 414012f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ func NewDefaultCompleter(opts ...Option) readline.AutoCompleter {
`\?`,
`\a`,
`\begin`,
`\bind`,
`\c`,
`\connect`,
`\C`,
`\cd`,
`\commit`,
`\connect`,
`\conninfo`,
`\copyright`,
`\copy`,
`\copyright`,
`\d+`,
`\da+`,
`\da`,
Expand Down Expand Up @@ -172,6 +173,7 @@ func NewDefaultCompleter(opts ...Option) readline.AutoCompleter {
`\echo`,
`\f`,
`\g`,
`\getenv`,
`\gexec`,
`\gset`,
`\gx`,
Expand Down
23 changes: 23 additions & 0 deletions metacmd/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,29 @@ func init() {
return os.Setenv(n, v)
},
},
GetEnv: {
Section: SectionOperatingSystem,
Name: "getenv",
Desc: Desc{"fetch environment variable", "VARNAME ENVVAR"},
Process: func(p *Params) error {
n, err := p.Get(true)
switch {
case err != nil:
return err
case n == "":
return text.ErrMissingRequiredArgument
}
v, err := p.Get(true)
switch {
case err != nil:
return err
case v == "":
return text.ErrMissingRequiredArgument
}
value, _ := env.Getenv(v)
return env.Set(n, value)
},
},
Timing: {
Section: SectionOperatingSystem,
Name: "timing",
Expand Down
2 changes: 2 additions & 0 deletions metacmd/metacmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const (
ChangeDir
// SetEnv is the system set environment variable meta command (\setenv).
SetEnv
// GetEnv is the system get environment variable meta command (\getenv).
GetEnv
// Shell is the system shell exec meta command (\!).
Shell
// Out is the switch output meta command (\o).
Expand Down

0 comments on commit 414012f

Please sign in to comment.