-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaliases.go
More file actions
38 lines (29 loc) · 839 Bytes
/
aliases.go
File metadata and controls
38 lines (29 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"io"
"strings"
)
const evalInstruction = "\n# copy and paste the output into your terminal or run\n"
func printAliases(w io.Writer, cfg *Cfg, strictMode, fallbackMode bool) {
commands := cfg.ListCommands()
outputs := make([]string, len(commands))
flags := make([]string, 0, 2)
if strictMode {
flags = append(flags, "--strict")
}
if fallbackMode {
flags = append(flags, "--fallback")
}
for i, c := range commands {
output := append(flags, c)
outputs[i] = strings.Join(output, " ")
}
fmt.Println()
for i, c := range commands {
_, _ = fmt.Fprintf(w, "alias %s='donner run %s';\n", c, outputs[i])
}
aliasCommand := strings.Join(append([]string{"donner", "aliases"}, flags...), " ")
_, _ = fmt.Fprintf(w, evalInstruction)
_, _ = fmt.Fprintf(w, "# eval $(%s)\n", aliasCommand)
}