Class: Appydave::Tools::ZshHistory::Filter
- Inherits:
-
Object
- Object
- Appydave::Tools::ZshHistory::Filter
- Defined in:
- lib/appydave/tools/zsh_history/filter.rb
Overview
Applies include/exclude patterns to categorize commands
Constant Summary collapse
- DEFAULT_EXCLUDE_PATTERNS =
Default patterns used when no config file exists
[ '^[a-z]$', # Single letter commands (typos) '^[a-z]{2}$', # Two letter commands (typos) '^ls$', '^ls -', '^pwd$', '^clear$', '^exit$', '^x$', '^cd$', '^cd -$', '^cd \\.\\.$', '^\\.\\.$', '^git status$', '^git diff$', '^git log$', '^git pull$', '^gs$', '^gd$', '^gl$', '^h$', '^history', '^which ', '^type ', '^cat ', '^head ', '^tail ', '^echo \\$', '^\\[\\d+\\]', # Output like [1234] '^davidcruwys\\s+\\d+', # Process listing output '^zsh: command not found', '^X Process completed', '^Coverage report', '^Line Coverage:', '^Finished in \\d', '^\\d+ examples, \\d+ failures' ].freeze
- DEFAULT_INCLUDE_PATTERNS =
[ '^j[a-z]', # Jump aliases '^dam ', # DAM tool '^vat ', # VAT tool '^claude ', # Claude CLI '^c-sonnet', # Claude sonnet alias '^bun run ', '^bun dev$', '^bun web:', '^bun worker:', '^bun convex:', '^npm run ', '^rake ', '^bundle ', '^git commit', '^git push', '^git add', '^gac ', # Git add & commit alias '^kfeat ', # Semantic commit alias '^kfix ', # Semantic commit alias '^docker ', '^docker-compose ', '^brew install', '^gem install', '^npm install' ].freeze
Instance Attribute Summary collapse
-
#exclude_patterns ⇒ Object
readonly
Returns the value of attribute exclude_patterns.
-
#include_patterns ⇒ Object
readonly
Returns the value of attribute include_patterns.
-
#profile_name ⇒ Object
readonly
Returns the value of attribute profile_name.
Instance Method Summary collapse
- #apply(commands, days: nil) ⇒ Object
- #categorize(commands) ⇒ Object
- #filter_by_date(commands, days) ⇒ Object
-
#initialize(profile: nil, exclude_patterns: nil, include_patterns: nil, config: nil) ⇒ Filter
constructor
Initialize filter with patterns.
Constructor Details
#initialize(profile: nil, exclude_patterns: nil, include_patterns: nil, config: nil) ⇒ Filter
Initialize filter with patterns
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/appydave/tools/zsh_history/filter.rb', line 82 def initialize(profile: nil, exclude_patterns: nil, include_patterns: nil, config: nil) @profile_name = profile @config = config # Load patterns: explicit params > config > defaults exclude_list = exclude_patterns || load_exclude_patterns include_list = include_patterns || load_include_patterns @exclude_patterns = exclude_list.map { |p| Regexp.new(p, Regexp::IGNORECASE) } @include_patterns = include_list.map { |p| Regexp.new(p, Regexp::IGNORECASE) } end |
Instance Attribute Details
#exclude_patterns ⇒ Object (readonly)
Returns the value of attribute exclude_patterns.
74 75 76 |
# File 'lib/appydave/tools/zsh_history/filter.rb', line 74 def exclude_patterns @exclude_patterns end |
#include_patterns ⇒ Object (readonly)
Returns the value of attribute include_patterns.
74 75 76 |
# File 'lib/appydave/tools/zsh_history/filter.rb', line 74 def include_patterns @include_patterns end |
#profile_name ⇒ Object (readonly)
Returns the value of attribute profile_name.
74 75 76 |
# File 'lib/appydave/tools/zsh_history/filter.rb', line 74 def profile_name @profile_name end |
Instance Method Details
#apply(commands, days: nil) ⇒ Object
94 95 96 97 |
# File 'lib/appydave/tools/zsh_history/filter.rb', line 94 def apply(commands, days: nil) filtered = filter_by_date(commands, days) categorize(filtered) end |
#categorize(commands) ⇒ Object
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 |
# File 'lib/appydave/tools/zsh_history/filter.rb', line 106 def categorize(commands) wanted = [] unwanted = [] unsure = [] commands.each do |cmd| category, pattern = categorize_command(cmd) cmd.category = category cmd.matched_pattern = pattern case category when :wanted wanted << cmd when :unwanted unwanted << cmd else unsure << cmd end end FilterResult.new( wanted: wanted, unwanted: unwanted, unsure: unsure, stats: build_stats(wanted, unwanted, unsure, commands) ) end |
#filter_by_date(commands, days) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/appydave/tools/zsh_history/filter.rb', line 99 def filter_by_date(commands, days) return commands if days.nil? cutoff = Time.now - (days * 24 * 60 * 60) commands.select { |cmd| cmd.datetime >= cutoff } end |