Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,23 @@ output: print # print, copy, exec
shell: /bin/bash
require_cheat_block: false
auto_continue: false # Auto-accept env vars without prompting

# Substitute search (while resolving a variable, press Ctrl-T to fuzzy-search
# environment variables and shell history for a value to insert)
key_substitute: "ctrl+t"
substitute_sources: ["env", "history"] # set to [] to disable
```

### Substitute search

When a cheat asks for a variable (say `$host`), press `Ctrl-T` to open a
fuzzy-search picker over your environment variables and any assignments
(`VAR=value`, `export VAR=value`, `declare -x VAR=value`, leading inline
assignments) found in shell history. Plain commands in history are ignored.
Pick a row, its value is loaded into the prompt; press `Enter` to accept or
edit it first. `Esc` cancels back to the var prompt. History is read from
`$HISTFILE`, falling back to `~/.bash_history` or `~/.zsh_history`.

## DSL

```
Expand Down
7 changes: 7 additions & 0 deletions cheatmd.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ shell: /bin/bash
# key_open: TUI key for opening markdown in editor (e.g., ctrl+o, ctrl+e)
key_widget: "\\C-g"
key_open: "ctrl+o"
# key_substitute: opens a fuzzy search of env vars + shell history during
# variable resolution, lets you pick a value to substitute into the prompt.
key_substitute: "ctrl+t"

# Substitute search sources. Valid entries: "env", "history".
# Empty list disables the feature.
substitute_sources: ["env", "history"]

# Display options
# Control what appears in the title/list path column
Expand Down
32 changes: 28 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ type Config struct {
AutoContinue bool `mapstructure:"auto_continue"`

// Keybindings
KeyWidget string `mapstructure:"key_widget"`
KeyOpen string `mapstructure:"key_open"`
KeyWidget string `mapstructure:"key_widget"`
KeyOpen string `mapstructure:"key_open"`
KeySubstitute string `mapstructure:"key_substitute"`

// Substitute search
SubstituteSources []string `mapstructure:"substitute_sources"`

// Display options
ShowFolder bool `mapstructure:"show_folder"`
Expand Down Expand Up @@ -77,6 +81,8 @@ var defaults = struct {
autoContinue bool
keyWidget string
keyOpen string
keySubstitute string
substituteSources []string
showFolder bool
showFile bool
previewHeight int
Expand All @@ -92,8 +98,10 @@ var defaults = struct {
requireCheatBlock: false,
autoSelect: false,
autoContinue: false,
keyWidget: "\\C-g", // Ctrl+G for shell widgets
keyOpen: "ctrl+o", // Ctrl+O in TUI
keyWidget: "\\C-g", // Ctrl+G for shell widgets
keyOpen: "ctrl+o", // Ctrl+O in TUI
keySubstitute: "ctrl+t", // Ctrl+T opens substitute search during var resolution
substituteSources: []string{"env", "history"},
showFolder: true,
showFile: true,
previewHeight: 6,
Expand Down Expand Up @@ -156,6 +164,10 @@ func setDefaults() {
// Keybindings
viper.SetDefault("key_widget", defaults.keyWidget)
viper.SetDefault("key_open", defaults.keyOpen)
viper.SetDefault("key_substitute", defaults.keySubstitute)

// Substitute search
viper.SetDefault("substitute_sources", defaults.substituteSources)

// Display options
viper.SetDefault("show_folder", defaults.showFolder)
Expand Down Expand Up @@ -257,6 +269,18 @@ func GetKeyOpen() string {
return viper.GetString("key_open")
}

// GetKeySubstitute returns the keybinding for opening the substitute search
// during variable resolution (e.g., "ctrl+t").
func GetKeySubstitute() string {
return viper.GetString("key_substitute")
}

// GetSubstituteSources returns the enabled sources for substitute search.
// Valid entries: "env", "history". Empty disables the feature.
func GetSubstituteSources() []string {
return viper.GetStringSlice("substitute_sources")
}

// ============================================================================
// Getters - Display Options
// ============================================================================
Expand Down
Loading