Class: Appydave::Tools::ZshHistory::Config
- Inherits:
-
Object
- Object
- Appydave::Tools::ZshHistory::Config
- Defined in:
- lib/appydave/tools/zsh_history/config.rb
Overview
Loads zsh_history configuration from ~/.config/appydave/zsh_history/
Directory structure:
~/.config/appydave/zsh_history/
config.txt # default_profile=crash-recovery
base_exclude.txt # Always excluded (typos, output lines)
profiles/
crash-recovery/
exclude.txt # Profile-specific excludes
include.txt # Profile-specific includes
Pattern files: One regex pattern per line, # for comments, blank lines ignored
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
File.('~/.config/appydave/zsh_history')
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#profile_name ⇒ Object
readonly
Returns the value of attribute profile_name.
Class Method Summary collapse
-
.create_default_config(config_path = DEFAULT_CONFIG_PATH) ⇒ Object
Create default config structure with example files.
Instance Method Summary collapse
-
#available_profiles ⇒ Object
List available profiles.
-
#configured? ⇒ Boolean
Check if config directory exists.
-
#default_profile ⇒ Object
Get default profile from config.txt.
-
#exclude_patterns ⇒ Object
Returns merged exclude patterns (base + profile).
-
#include_patterns ⇒ Object
Returns profile include patterns.
-
#initialize(config_path: nil, profile: nil) ⇒ Config
constructor
A new instance of Config.
-
#profile_exists?(name = profile_name) ⇒ Boolean
Check if specific profile exists.
Constructor Details
#initialize(config_path: nil, profile: nil) ⇒ Config
Returns a new instance of Config.
24 25 26 27 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 24 def initialize(config_path: nil, profile: nil) @config_path = config_path || DEFAULT_CONFIG_PATH @profile_name = profile || default_profile end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
22 23 24 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 22 def config_path @config_path end |
#profile_name ⇒ Object (readonly)
Returns the value of attribute profile_name.
22 23 24 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 22 def profile_name @profile_name end |
Class Method Details
.create_default_config(config_path = DEFAULT_CONFIG_PATH) ⇒ Object
Create default config structure with example files
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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 82 def self.create_default_config(config_path = DEFAULT_CONFIG_PATH) FileUtils.mkdir_p(config_path) FileUtils.mkdir_p(File.join(config_path, 'profiles', 'crash-recovery')) # Create config.txt write_if_missing(File.join(config_path, 'config.txt'), " # ZSH History Configuration\n # Set default profile (used when --profile not specified)\n default_profile=crash-recovery\n CONFIG\n\n # Create base_exclude.txt\n write_if_missing(File.join(config_path, 'base_exclude.txt'), <<~PATTERNS)\n # Base exclude patterns - always applied\n # These are noise in ANY scenario\n\n # Typos and single-letter commands\n ^[a-z]$\n ^[a-z]{2}$\n\n # Output lines accidentally captured\n ^\\\\[\\\\d+\\\\]\n ^zsh: command not found\n ^X Process completed\n ^Coverage report\n ^Line Coverage:\n ^Finished in \\\\d\n ^\\\\d+ examples, \\\\d+ failures\n\n # Process listing output\n ^davidcruwys\\\\s+\\\\d+\n PATTERNS\n\n # Create crash-recovery profile\n profile_path = File.join(config_path, 'profiles', 'crash-recovery')\n\n write_if_missing(File.join(profile_path, 'exclude.txt'), <<~PATTERNS)\n # Crash Recovery - Exclude patterns\n # Navigation and quick-check commands (noise when finding what you were working on)\n\n # Basic navigation\n ^ls$\n ^ls -\n ^pwd$\n ^clear$\n ^exit$\n ^x$\n ^cd$\n ^cd -$\n ^cd \\\\.\\\\.\n ^\\\\.\\\\.\n\n # Git quick checks (not actual work)\n ^git status$\n ^git diff$\n ^git log$\n ^git pull$\n ^gs$\n ^gd$\n ^gl$\n\n # History and lookups\n ^h$\n ^history\n ^which\n ^type\n\n # File viewing\n ^cat\n ^head\n ^tail\n ^echo \\\\$\n PATTERNS\n\n write_if_missing(File.join(profile_path, 'include.txt'), <<~PATTERNS)\n # Crash Recovery - Include patterns\n # Commands that represent actual work\n\n # Jump aliases (navigation to projects)\n ^j[a-z]\n\n # Tools\n ^dam\n ^vat\n ^claude\n ^c-sonnet\n\n # JavaScript/Node\n ^bun run\n ^bun dev$\n ^bun web:\n ^bun worker:\n ^bun convex:\n ^npm run\n\n # Ruby\n ^rake\n ^bundle\n\n # Git commits (actual work, not checks)\n ^git commit\n ^git push\n ^git add\n ^gac\n ^kfeat\n ^kfix\n\n # Docker\n ^docker\n ^docker-compose\n\n # Package installation\n ^brew install\n ^gem install\n ^npm install\n PATTERNS\n\n config_path\nend\n") |
Instance Method Details
#available_profiles ⇒ Object
List available profiles
56 57 58 59 60 61 62 63 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 56 def available_profiles profiles_dir = File.join(config_path, 'profiles') return [] unless Dir.exist?(profiles_dir) Dir.children(profiles_dir) .select { |f| File.directory?(File.join(profiles_dir, f)) } .sort end |
#configured? ⇒ Boolean
Check if config directory exists
43 44 45 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 43 def configured? Dir.exist?(config_path) end |
#default_profile ⇒ Object
Get default profile from config.txt
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 66 def default_profile config_file = File.join(config_path, 'config.txt') return nil unless File.exist?(config_file) File.readlines(config_file).each do |line| line = line.strip next if line.empty? || line.start_with?('#') key, value = line.split('=', 2) return value.strip if key.strip == 'default_profile' end nil end |
#exclude_patterns ⇒ Object
Returns merged exclude patterns (base + profile)
30 31 32 33 34 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 30 def exclude_patterns patterns = load_base_exclude patterns += load_profile_patterns('exclude') if profile_name patterns.empty? ? nil : patterns end |
#include_patterns ⇒ Object
Returns profile include patterns
37 38 39 40 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 37 def include_patterns patterns = load_profile_patterns('include') patterns.empty? ? nil : patterns end |
#profile_exists?(name = profile_name) ⇒ Boolean
Check if specific profile exists
48 49 50 51 52 53 |
# File 'lib/appydave/tools/zsh_history/config.rb', line 48 def profile_exists?(name = profile_name) return false unless name profile_path = File.join(config_path, 'profiles', name) Dir.exist?(profile_path) end |