Skip to content

Commit 414012f

Browse files
committed
Adding \getenv metacommand
1 parent 5b7cfbb commit 414012f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

drivers/completer/completer.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ func NewDefaultCompleter(opts ...Option) readline.AutoCompleter {
124124
`\?`,
125125
`\a`,
126126
`\begin`,
127+
`\bind`,
127128
`\c`,
128-
`\connect`,
129129
`\C`,
130130
`\cd`,
131131
`\commit`,
132+
`\connect`,
132133
`\conninfo`,
133-
`\copyright`,
134134
`\copy`,
135+
`\copyright`,
135136
`\d+`,
136137
`\da+`,
137138
`\da`,
@@ -172,6 +173,7 @@ func NewDefaultCompleter(opts ...Option) readline.AutoCompleter {
172173
`\echo`,
173174
`\f`,
174175
`\g`,
176+
`\getenv`,
175177
`\gexec`,
176178
`\gset`,
177179
`\gx`,

metacmd/cmds.go

+23
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,29 @@ func init() {
420420
return os.Setenv(n, v)
421421
},
422422
},
423+
GetEnv: {
424+
Section: SectionOperatingSystem,
425+
Name: "getenv",
426+
Desc: Desc{"fetch environment variable", "VARNAME ENVVAR"},
427+
Process: func(p *Params) error {
428+
n, err := p.Get(true)
429+
switch {
430+
case err != nil:
431+
return err
432+
case n == "":
433+
return text.ErrMissingRequiredArgument
434+
}
435+
v, err := p.Get(true)
436+
switch {
437+
case err != nil:
438+
return err
439+
case v == "":
440+
return text.ErrMissingRequiredArgument
441+
}
442+
value, _ := env.Getenv(v)
443+
return env.Set(n, value)
444+
},
445+
},
423446
Timing: {
424447
Section: SectionOperatingSystem,
425448
Name: "timing",

metacmd/metacmd.go

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const (
6868
ChangeDir
6969
// SetEnv is the system set environment variable meta command (\setenv).
7070
SetEnv
71+
// GetEnv is the system get environment variable meta command (\getenv).
72+
GetEnv
7173
// Shell is the system shell exec meta command (\!).
7274
Shell
7375
// Out is the switch output meta command (\o).

0 commit comments

Comments
 (0)