github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/config/defaults/config.go (about) 1 package defaults 2 3 import ( 4 "os" 5 "runtime" 6 7 "github.com/lmorg/murex/config" 8 "github.com/lmorg/murex/config/profile" 9 "github.com/lmorg/murex/lang" 10 "github.com/lmorg/murex/lang/expressions/noglob" 11 "github.com/lmorg/murex/lang/types" 12 "github.com/lmorg/murex/shell" 13 "github.com/lmorg/murex/shell/autocomplete" 14 "github.com/lmorg/murex/utils/cache" 15 "github.com/lmorg/murex/utils/parser" 16 "github.com/lmorg/murex/utils/spellcheck/userdictionary" 17 ) 18 19 // Config defines the default config 20 func Config(c *config.Config, isInteractive bool) { 21 22 // --- shell --- 23 24 c.Define("shell", "prompt", config.Properties{ 25 Description: "Interactive shell prompt", 26 Default: "{ out 'murex » ' }", 27 DataType: types.CodeBlock, 28 Global: true, 29 }) 30 31 c.Define("shell", "prompt-multiline", config.Properties{ 32 Description: "Shell prompt when command line string spans multiple lines", 33 Default: `{ out "$linenum » " }`, 34 DataType: types.CodeBlock, 35 Global: true, 36 }) 37 38 c.Define("shell", "get-cursor-pos", config.Properties{ 39 Description: "Toggle support for the getCursorPos ANSI escape sequence to detect when prompt needs to write a new line (more accurate than zsh's wrap mode but also supported by fewer terminal emulators)", 40 Default: false, 41 DataType: types.Boolean, 42 Global: true, 43 GoFunc: config.GoFuncProperties{ 44 Read: shell.ConfigReadGetCursorPos, 45 Write: shell.ConfigWriteGetCursorPos, 46 }, 47 }) 48 49 c.Define("shell", "max-suggestions", config.Properties{ 50 Description: "Maximum number of lines with auto-completion suggestions to display", 51 Default: 12, 52 DataType: types.Integer, 53 Global: true, 54 }) 55 56 c.Define("shell", "recursive-enabled", config.Properties{ 57 Description: "Enable a recursive scan through the directory hierarchy when using autocomplete against a file or directory parameter", 58 Default: true, 59 DataType: types.Boolean, 60 Global: true, 61 }) 62 63 c.Define("shell", "recursive-max-depth", config.Properties{ 64 Description: "Maximum depth to scan through when compiling the recursive list for auto-completion", 65 Default: 5, 66 DataType: types.Integer, 67 Global: true, 68 }) 69 70 c.Define("shell", "autocomplete-soft-timeout", config.Properties{ 71 Description: "Number of milliseconds (1/1000th second) to wait when running autocompletins before the task is backgrounded and the results appended to the existing completions (longer reduces responsiveness, shorter means autocompletion fields aren't sized to the longest suggestion)", 72 Default: 150, 73 DataType: types.Integer, 74 Global: true, 75 }) 76 77 c.Define("shell", "autocomplete-hard-timeout", config.Properties{ 78 Description: "Number of milliseconds (1/1000th second) to wait when running long autocompletions before the shell gives up. When timeout is reached on recursive directory lookups, only the results it had up to that point are returned", 79 Default: 5000, 80 DataType: types.Integer, 81 Global: true, 82 }) 83 84 c.Define("shell", "history", config.Properties{ 85 Description: "Write shell history (interactive shell) to disk", 86 Default: true, 87 DataType: types.Boolean, 88 Global: true, 89 }) 90 91 c.Define("shell", "color", config.Properties{ 92 Description: "ANSI escape sequences in Murex builtins to highlight syntax errors, history completions, variables, etc", 93 Default: true, 94 DataType: types.Boolean, 95 Global: true, 96 }) 97 98 c.Define("shell", "syntax-highlighting", config.Properties{ 99 Description: "Syntax highlighting of murex code when in the interactive shell", 100 Default: true, 101 DataType: types.Boolean, 102 Global: true, 103 }) 104 105 c.Define("shell", "hint-text-enabled", config.Properties{ 106 Description: "Display the interactive shell's hint text helper. Please note, even when this is disabled, it will still appear when used for regexp searches and other readline-specific functions", 107 Default: true, 108 DataType: types.Boolean, 109 Global: true, 110 }) 111 112 c.Define("shell", "hint-text-func", config.Properties{ 113 Description: "Murex function to call if the helper hint text is otherwise blank", 114 Default: `{}`, 115 DataType: types.CodeBlock, 116 Global: true, 117 }) 118 119 c.Define("shell", "hint-text-formatting", config.Properties{ 120 Description: "Any additional ANSI formatting for the hint text (typically color)", 121 Default: "{BLUE}", 122 DataType: types.String, 123 Global: true, 124 }) 125 126 c.Define("shell", "pre-cache-hint-summaries", config.Properties{ 127 Description: "Run the command hint summary pre-cache", 128 Default: "on-start", 129 Options: []string{"on-start", "on-tab", "false"}, 130 DataType: types.String, 131 Global: true, 132 }) 133 134 c.Define("shell", "cache.db-enabled", config.Properties{ 135 Description: "Enable or disable the persistent cache.db. Typically located in: " + profile.ModulePath(), 136 Default: true, 137 DataType: types.Boolean, 138 Global: true, 139 GoFunc: config.GoFuncProperties{ 140 Read: cache.ReadStatus, 141 Write: cache.WriteStatus, 142 }, 143 }) 144 145 var defaultTitleBarFunc string 146 if runtime.GOOS != "windows" { 147 defaultTitleBarFunc = `{ out "$(USER)\@$(HOSTNAME):$(PWD)" }` 148 } 149 c.Define("shell", "titlebar-func", config.Properties{ 150 Description: "Linux and UNIX only! Murex function to define your terminal emulators title bar text while you're sat on a prompt. Carriage returns and tabs are replaced with spaces", 151 Default: defaultTitleBarFunc, 152 DataType: types.CodeBlock, 153 Global: true, 154 }) 155 156 c.Define("shell", "stop-status-enabled", config.Properties{ 157 Description: "Display some status information about the stop process when ctrl+z is pressed (conceptually similar to ctrl+t / SIGINFO on some BSDs)", 158 Default: true, 159 DataType: types.Boolean, 160 Global: true, 161 }) 162 163 c.Define("shell", "stop-status-func", config.Properties{ 164 Description: "Murex function to execute when an `exec` process is stopped", 165 Default: `{}`, 166 DataType: types.CodeBlock, 167 Global: true, 168 }) 169 170 c.Define("shell", "mime-types", config.Properties{ 171 Description: "Supported MIME types and their corresponding Murex data types", 172 Default: lang.GetMimes(), 173 DataType: types.Json, 174 Global: true, 175 GoFunc: config.GoFuncProperties{ 176 Read: lang.ReadMimes, 177 Write: lang.WriteMimes, 178 }, 179 }) 180 181 c.Define("shell", "extensions", config.Properties{ 182 Description: "Supported file extensions and their corresponding Murex data types", 183 Default: lang.GetFileExts(), 184 DataType: types.Json, 185 Global: true, 186 GoFunc: config.GoFuncProperties{ 187 Read: lang.ReadFileExtensions, 188 Write: lang.WriteFileExtensions, 189 }, 190 }) 191 192 c.Define("shell", "safe-commands", config.Properties{ 193 Description: "Commands whitelisted for being safe to automatically execute in the commandline pipe", 194 Default: parser.GetSafeCmds(), 195 DataType: types.Json, 196 Global: true, 197 GoFunc: config.GoFuncProperties{ 198 Read: parser.ReadSafeCmds, 199 Write: parser.WriteSafeCmds, 200 }, 201 }) 202 203 c.Define("shell", "spellcheck-enabled", config.Properties{ 204 Description: "Enable spellchecking in the interactive prompt", 205 Default: false, 206 DataType: types.Boolean, 207 Global: true, 208 }) 209 210 c.Define("shell", "spellcheck-func", config.Properties{ 211 Description: "Code block to run as part of the spellchecker (STDIN the line, STDOUT is array for misspelt words)", 212 Default: "{ -> aspell list }", 213 DataType: types.CodeBlock, 214 Global: true, 215 }) 216 217 c.Define("shell", "spellcheck-user-dictionary", config.Properties{ 218 Description: "An array of words not to count as misspellings", 219 Default: userdictionary.Get(), 220 DataType: types.Json, 221 Global: true, 222 GoFunc: config.GoFuncProperties{ 223 Read: userdictionary.Read, 224 Write: userdictionary.Write, 225 }, 226 }) 227 228 _, WSLENV := os.LookupEnv("WSLENV") 229 _, WSL_DISTRO_NAME := os.LookupEnv("WSL_DISTRO_NAME") 230 wsl := WSLENV || WSL_DISTRO_NAME 231 232 c.Define("wsl", "windows-mounts", config.Properties{ 233 Description: "Windows mount points when running WSL (this improves autocompletion suggestions)", 234 Default: "", 235 DataType: types.String, 236 Global: true, 237 GoFunc: config.GoFuncProperties{ 238 Read: autocomplete.WslMountsGet, 239 Write: autocomplete.WslMountsSet, 240 }, 241 }) 242 243 c.Define("shell", "extensions-enabled", config.Properties{ 244 Description: "Windows and WSL only! Auto-completes file extensions. This also affects the auto-completion parameters. This is best left `true` for WSL. You may need to run `murex-update-exe-list` to apply the changes", 245 Default: wsl || runtime.GOOS == "windows", 246 DataType: types.Boolean, 247 Global: true, 248 }) 249 250 c.Define("shell", "expand-globs", config.Properties{ 251 Description: "Expand globs in the REPL shell (globs in functions / modules will still need to be invoked via the `g` function)", 252 Default: true, 253 DataType: types.Boolean, 254 Global: true, 255 }) 256 257 c.Define("shell", "expand-glob-unsafe-commands", config.Properties{ 258 Description: "Commands blacklisted for being unsafe to glob", 259 Default: noglob.GetNoGlobCmds(), 260 DataType: types.Json, 261 Global: true, 262 GoFunc: config.GoFuncProperties{ 263 Read: noglob.ReadNoGlobCmds, 264 Write: noglob.WriteNoGlobCmds, 265 }, 266 }) 267 268 c.Define("shell", "start-directory", config.Properties{ 269 Description: "If set, this is the default working directory for each new instance of murex. If unset murex will default to the current working directory", 270 Default: "", 271 DataType: types.String, 272 Global: true, 273 }) 274 275 c.Define("shell", "preview-images", config.Properties{ 276 Description: "If set, file previews will display images as ANSI art rendered graphics rather than text descriptions", 277 Default: true, 278 DataType: types.Boolean, 279 Global: true, 280 }) 281 282 c.Define("shell", "auto-cd", config.Properties{ 283 Description: "If set, `cd` is assumed when directory path supplied as a command", 284 Default: false, 285 DataType: types.Boolean, 286 Global: true, 287 }) 288 289 // --- proc --- 290 291 c.Define("proc", "force-tty", config.Properties{ 292 Description: "This is used to override the red highlighting on STDERR on a per-process level", 293 Default: false, 294 DataType: types.Boolean, 295 }) 296 297 c.Define("proc", "strict-types", config.Properties{ 298 Description: "Enables or disables automatic type conversions in expressions. If enabled you might need to liberally use type tagging to ensure strings from random sources are treated as numbers", 299 Default: false, 300 DataType: types.Boolean, 301 }) 302 303 c.Define("proc", "strict-vars", config.Properties{ 304 Description: "Return an error if an unset variable is used. Enabling this means all variables will need to be `set` before than can be used", 305 Default: true, 306 DataType: types.Boolean, 307 }) 308 309 c.Define("proc", "strict-arrays", config.Properties{ 310 Description: "Return an error if an array is empty (applies to array subshells as well as variables)", 311 Default: true, 312 DataType: types.Boolean, 313 }) 314 315 c.Define("proc", "echo-tmux", config.Properties{ 316 Description: "Echo shell function names to the tmux window name", 317 Default: false, 318 DataType: types.Boolean, 319 }) 320 321 // --- test --- 322 323 c.Define("test", "enabled", config.Properties{ 324 Description: "Run test cases", 325 Default: false, 326 DataType: types.Boolean, 327 }) 328 329 c.Define("test", "verbose", config.Properties{ 330 Description: "Report all pass conditions for a defined test rather than just the pass summary", 331 Default: false, 332 DataType: types.Boolean, 333 }) 334 335 c.Define("test", "auto-report", config.Properties{ 336 Description: "Automatically report the results from test cases ran", 337 Default: true, 338 DataType: types.Boolean, 339 }) 340 341 c.Define("test", "report-format", config.Properties{ 342 Description: "Output format of the report", 343 Default: "table", 344 Options: []string{"table", "json", "csv"}, 345 DataType: types.String, 346 }) 347 348 c.Define("test", "report-pipe", config.Properties{ 349 Description: "Redirect the test reports to a named pipe. Empty string send to terminal's STDERR", 350 Default: "", 351 DataType: types.String, 352 }) 353 354 c.Define("test", "crop-message", config.Properties{ 355 Description: "This is the character limit for the report message when the report is set to `table`. Set to zero, `0`, to disable message cropping", 356 Default: 0, 357 DataType: types.Integer, 358 }) 359 }