Rename Z.Aliases to Z.Shortcuts

pull/97/head
rwxrob 2 years ago
parent 13a0b42b25
commit c5d6bb50aa
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -290,14 +290,14 @@ func ArgsOrIn(args []string) string {
return strings.Join(args, " ")
}
// Aliases allows Bonzai tree developers to create aliases (similar to
// shell aliases) that are directly translated into arguments to the
// Bonzai tree executable by overriding the os.Args in a controlled way.
// The value of an alias is always a slice of strings that will replace
// the os.Args[2:]. A slice is used (instead of a string parsed with
// strings.Fields) to ensure that hard-coded arguments containing
// whitespace are properly handled.
var Aliases = make(map[string][]string)
// Shortcuts allows Bonzai tree developers to create single-word
// shortcuts (similar to shell aliases) that are directly translated
// into arguments to the Bonzai tree executable by overriding the
// os.Args in a controlled way. The value of a shortcut is always a slice
// of strings that will replace the os.Args[2:]. A slice is used
// (instead of a string parsed with strings.Fields) to ensure that
// hard-coded arguments containing whitespace are properly handled.
var Shortcuts = make(map[string][]string)
// AllowPanic disables TrapPanic stopping it from cleaning panic errors.
var AllowPanic = false

@ -243,10 +243,10 @@ func (x *Cmd) Run() {
x.cacheSections()
// resolve Z.Aliases (if completion didn't replace them)
// resolve Z.Shortcuts (if completion didn't replace them)
if len(os.Args) > 1 {
args := []string{os.Args[0]}
alias := Aliases[os.Args[1]]
alias := Shortcuts[os.Args[1]]
if alias != nil {
args = append(args, alias...)
args = append(args, os.Args[2:]...)
@ -263,7 +263,7 @@ func (x *Cmd) Run() {
// find the leaf command
lineargs := ArgsFrom(line)
if len(lineargs) == 2 {
list = append(list, maps.KeysWithPrefix(Aliases, lineargs[1])...)
list = append(list, maps.KeysWithPrefix(Shortcuts, lineargs[1])...)
}
cmd, args := x.Seek(lineargs[1:])
@ -273,7 +273,7 @@ func (x *Cmd) Run() {
list = append(list, Comp.Complete(cmd, args...)...)
}
if len(list) == 1 && len(lineargs) == 2 {
if v, has := Aliases[list[0]]; has {
if v, has := Shortcuts[list[0]]; has {
fmt.Println(strings.Join(EscAll(v), " "))
Exit()
return

Loading…
Cancel
Save