-
Notifications
You must be signed in to change notification settings - Fork 41
/
configGet.go
173 lines (157 loc) · 5.21 KB
/
configGet.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package cmd
import (
"fmt"
"os"
"strings"
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/spf13/cobra"
)
var GROUP_ID_CONFIG string = "group_id_config"
var configGetCmd = &cobra.Command{
Use: "config-get",
Short: "Get the value of a config option",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
lib.CheckFatalError(cmd.Help())
os.Exit(1)
},
}
var getEnableControlRCmd = &cobra.Command{
Use: "enable-control-r",
Short: "Whether hishtory replaces your shell's default control-r",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.ControlRSearchEnabled)
},
}
var getHighlightMatchesCmd = &cobra.Command{
Use: "highlight-matches",
Short: "Whether hishtory highlights matches in the search results",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.HighlightMatches)
},
}
var getDefaultFilterCmd = &cobra.Command{
Use: "default-filter",
Short: "The default filter that is applied to all search queries",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Printf("%#v", config.DefaultFilter)
},
}
var getFilterDuplicateCommandsCmd = &cobra.Command{
Use: "filter-duplicate-commands",
Short: "Whether hishtory filters out duplicate commands when displaying your history",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.FilterDuplicateCommands)
},
}
var getEnableAiCompletion = &cobra.Command{
Use: "ai-completion",
Short: "Enable AI completion for searches starting with '?'",
Long: "Note that AI completion requests are sent to the shared hiSHtory backend and then to OpenAI. Requests are not logged, but still be careful not to put anything sensitive in queries.",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.AiCompletion)
},
}
var getPresavingCmd = &cobra.Command{
Use: "presaving",
Short: "Enable 'presaving' of shell entries that never finish running",
Long: "If enabled, there is a slight risk of duplicate history entries. If disabled, non-terminating history entries will not be recorded.",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.EnablePresaving)
},
}
var getBetaModeCmd = &cobra.Command{
Use: "beta-mode",
Short: "Enable beta-mode to opt-in to unreleased features",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.BetaMode)
},
}
var getDisplayedColumnsCmd = &cobra.Command{
Use: "displayed-columns",
Aliases: []string{"displayed-column"},
Short: "The list of columns that hishtory displays",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
for _, col := range config.DisplayedColumns {
if strings.Contains(col, " ") {
fmt.Printf("%q ", col)
} else {
fmt.Print(col + " ")
}
}
fmt.Print("\n")
},
}
var getTimestampFormatCmd = &cobra.Command{
Use: "timestamp-format",
Short: "The go format string to use for formatting the timestamp",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.TimestampFormat)
},
}
var getCustomColumnsCmd = &cobra.Command{
Use: "custom-columns",
Aliases: []string{"custom-column"},
Short: "The list of custom columns that hishtory is tracking",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
for _, cc := range config.CustomColumns {
fmt.Println(cc.ColumnName + ": " + cc.ColumnCommand)
}
},
}
var getColorScheme = &cobra.Command{
Use: "color-scheme",
Short: "Get the currently configured color scheme for selected text in the TUI",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println("selected-text: " + config.ColorScheme.SelectedText)
fmt.Println("selected-background: " + config.ColorScheme.SelectedBackground)
fmt.Println("border-color: " + config.ColorScheme.BorderColor)
},
}
var getAiCompletionEndpoint = &cobra.Command{
Use: "ai-completion-endpoint",
Short: "The AI endpoint to use for AI completions",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)
fmt.Println(config.AiCompletionEndpoint)
},
}
func init() {
rootCmd.AddCommand(configGetCmd)
configGetCmd.AddCommand(getEnableControlRCmd)
configGetCmd.AddCommand(getFilterDuplicateCommandsCmd)
configGetCmd.AddCommand(getDisplayedColumnsCmd)
configGetCmd.AddCommand(getTimestampFormatCmd)
configGetCmd.AddCommand(getCustomColumnsCmd)
configGetCmd.AddCommand(getBetaModeCmd)
configGetCmd.AddCommand(getHighlightMatchesCmd)
configGetCmd.AddCommand(getEnableAiCompletion)
configGetCmd.AddCommand(getPresavingCmd)
configGetCmd.AddCommand(getColorScheme)
configGetCmd.AddCommand(getDefaultFilterCmd)
configGetCmd.AddCommand(getAiCompletionEndpoint)
}