pzsh 0.3.5

Performance-first shell framework with sub-10ms startup
Documentation
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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
//! CLI module for pzsh
//!
//! Commands: bench, lint, compile, fix, profile, status

use crate::config::CompiledConfig;
use crate::{MAX_STARTUP_MS, Pzsh};
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use std::time::{Duration, Instant};

/// pzsh: Performance-first shell framework
#[derive(Parser, Debug)]
#[command(name = "pzsh")]
#[command(author, version, about, long_about = None)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Benchmark shell startup time
    Bench {
        /// Number of iterations
        #[arg(short, long, default_value = "100")]
        iterations: u32,

        /// Show detailed statistics
        #[arg(short, long)]
        verbose: bool,
    },

    /// Lint configuration for slow patterns
    Lint {
        /// Path to configuration file
        #[arg(short, long, default_value = "~/.pzshrc")]
        config: PathBuf,
    },

    /// Compile configuration to optimized form
    Compile {
        /// Path to source configuration
        #[arg(short, long, default_value = "~/.pzshrc")]
        config: PathBuf,

        /// Output path for compiled config
        #[arg(short, long)]
        output: Option<PathBuf>,
    },

    /// Auto-fix slow patterns
    Fix {
        /// Path to configuration file
        #[arg(short, long, default_value = "~/.pzshrc")]
        config: PathBuf,

        /// Dry run (show fixes without applying)
        #[arg(short, long)]
        dry_run: bool,
    },

    /// Profile detailed startup breakdown
    Profile {
        /// Show timing for each component
        #[arg(short, long)]
        verbose: bool,
    },

    /// Show pzsh status
    Status,

    /// Initialize pzsh configuration
    Init {
        /// Shell type (zsh or bash)
        #[arg(short, long, default_value = "zsh")]
        shell: String,
    },
}

/// Benchmark result
#[derive(Debug)]
pub struct BenchResult {
    pub iterations: u32,
    pub min: Duration,
    pub max: Duration,
    pub mean: Duration,
    pub p50: Duration,
    pub p95: Duration,
    pub p99: Duration,
    pub std_dev: Duration,
    pub passed: bool,
}

impl BenchResult {
    /// Format as string
    #[must_use]
    pub fn format(&self) -> String {
        let status = if self.passed { "" } else { "" };
        format!(
            "Startup Benchmark ({} iterations)\n\
             ────────────────────────────────\n\
             min:    {:>8.3}ms\n\
             max:    {:>8.3}ms\n\
             mean:   {:>8.3}ms\n\
             p50:    {:>8.3}ms\n\
             p95:    {:>8.3}ms\n\
             p99:    {:>8.3}ms\n\
             stddev: {:>8.3}ms\n\
             ────────────────────────────────\n\
             Budget: {}ms {} (p99 < {}ms)",
            self.iterations,
            self.min.as_secs_f64() * 1000.0,
            self.max.as_secs_f64() * 1000.0,
            self.mean.as_secs_f64() * 1000.0,
            self.p50.as_secs_f64() * 1000.0,
            self.p95.as_secs_f64() * 1000.0,
            self.p99.as_secs_f64() * 1000.0,
            self.std_dev.as_secs_f64() * 1000.0,
            MAX_STARTUP_MS,
            status,
            MAX_STARTUP_MS,
        )
    }
}

/// Run benchmark
pub fn run_bench(iterations: u32, _verbose: bool) -> BenchResult {
    let mut times: Vec<Duration> = Vec::with_capacity(iterations as usize);

    // Warmup
    for _ in 0..10 {
        let config = CompiledConfig::default();
        let _ = Pzsh::new(config);
    }

    // Benchmark
    for _ in 0..iterations {
        let config = CompiledConfig::default();
        let start = Instant::now();
        let _ = Pzsh::new(config);
        times.push(start.elapsed());
    }

    // Sort for percentiles
    times.sort();

    let min = times[0];
    let max = times[times.len() - 1];

    let sum: Duration = times.iter().sum();
    let mean = sum / iterations;

    let p50_idx = (times.len() as f64 * 0.50) as usize;
    let p95_idx = (times.len() as f64 * 0.95) as usize;
    let p99_idx = (times.len() as f64 * 0.99) as usize;

    let p50 = times[p50_idx.min(times.len() - 1)];
    let p95 = times[p95_idx.min(times.len() - 1)];
    let p99 = times[p99_idx.min(times.len() - 1)];

    // Calculate standard deviation
    let mean_nanos = mean.as_nanos() as f64;
    let variance: f64 = times
        .iter()
        .map(|t| {
            let diff = t.as_nanos() as f64 - mean_nanos;
            diff * diff
        })
        .sum::<f64>()
        / times.len() as f64;
    let std_dev = Duration::from_nanos(variance.sqrt() as u64);

    let passed = p99 < Duration::from_millis(MAX_STARTUP_MS);

    BenchResult {
        iterations,
        min,
        max,
        mean,
        p50,
        p95,
        p99,
        std_dev,
        passed,
    }
}

/// Lint result
#[derive(Debug)]
pub struct LintResult {
    pub issues: Vec<LintIssue>,
}

#[derive(Debug)]
pub struct LintIssue {
    pub severity: LintSeverity,
    pub message: String,
    pub line: Option<usize>,
    pub fix: Option<String>,
}

#[derive(Debug, Clone, Copy)]
pub enum LintSeverity {
    Error,
    Warning,
    Info,
}

impl LintResult {
    /// Check if lint passed (no errors)
    #[must_use]
    pub fn passed(&self) -> bool {
        !self
            .issues
            .iter()
            .any(|i| matches!(i.severity, LintSeverity::Error))
    }

    /// Format as string
    #[must_use]
    pub fn format(&self) -> String {
        if self.issues.is_empty() {
            return "✓ 0 issues found".to_string();
        }

        let mut output = String::new();
        for issue in &self.issues {
            let severity = match issue.severity {
                LintSeverity::Error => "error",
                LintSeverity::Warning => "warning",
                LintSeverity::Info => "info",
            };

            let line_info = issue
                .line
                .map_or(String::new(), |l| format!(" (line {})", l));

            output.push_str(&format!("[{}]{}: {}\n", severity, line_info, issue.message));

            if let Some(fix) = &issue.fix {
                output.push_str(&format!("  fix: {}\n", fix));
            }
        }

        let error_count = self
            .issues
            .iter()
            .filter(|i| matches!(i.severity, LintSeverity::Error))
            .count();
        let warning_count = self
            .issues
            .iter()
            .filter(|i| matches!(i.severity, LintSeverity::Warning))
            .count();

        output.push_str(&format!(
            "\n{} errors, {} warnings",
            error_count, warning_count
        ));

        output
    }
}

/// Lint configuration content
pub fn lint_config(content: &str) -> LintResult {
    let mut issues = Vec::new();

    for (line_num, line) in content.lines().enumerate() {
        let line_num = line_num + 1;

        // Check for subprocess calls
        if line.contains("$(") {
            issues.push(LintIssue {
                severity: LintSeverity::Error,
                message: "subprocess call $() not allowed at startup".to_string(),
                line: Some(line_num),
                fix: Some("use pre-resolved path instead".to_string()),
            });
        }

        // Check for backticks
        if line.contains('`') && !line.trim_start().starts_with('#') {
            issues.push(LintIssue {
                severity: LintSeverity::Error,
                message: "backtick substitution not allowed".to_string(),
                line: Some(line_num),
                fix: Some("use pre-resolved value instead".to_string()),
            });
        }

        // Check for brew --prefix
        if line.contains("brew --prefix") {
            issues.push(LintIssue {
                severity: LintSeverity::Error,
                message: "brew --prefix is slow (50-100ms)".to_string(),
                line: Some(line_num),
                fix: Some("run `brew --prefix <formula>` once and hardcode the path".to_string()),
            });
        }

        // Check for eval
        if line.contains("eval ") && !line.trim_start().starts_with('#') {
            issues.push(LintIssue {
                severity: LintSeverity::Error,
                message: "eval not allowed for safety".to_string(),
                line: Some(line_num),
                fix: None,
            });
        }

        // Check for slow plugin managers
        if line.contains("oh-my-zsh") || line.contains("source $ZSH/oh-my-zsh.sh") {
            issues.push(LintIssue {
                severity: LintSeverity::Error,
                message: "oh-my-zsh is slow (500-2000ms startup)".to_string(),
                line: Some(line_num),
                fix: Some("remove oh-my-zsh, use pzsh plugins instead".to_string()),
            });
        }

        // Check for NVM
        if line.contains("nvm.sh") && !line.trim_start().starts_with('#') {
            issues.push(LintIssue {
                severity: LintSeverity::Warning,
                message: "NVM adds 200-500ms to startup".to_string(),
                line: Some(line_num),
                fix: Some("use fnm or volta instead, or lazy-load NVM".to_string()),
            });
        }

        // Check for conda init
        if line.contains("conda init") || line.contains("conda.sh") {
            issues.push(LintIssue {
                severity: LintSeverity::Warning,
                message: "conda init adds 200-400ms to startup".to_string(),
                line: Some(line_num),
                fix: Some("lazy-load conda or use mamba".to_string()),
            });
        }
    }

    LintResult { issues }
}

/// Profile result
#[derive(Debug)]
pub struct ProfileResult {
    pub parse_time: Duration,
    pub env_time: Duration,
    pub alias_time: Duration,
    pub prompt_time: Duration,
    pub total_time: Duration,
    pub passed: bool,
}

impl ProfileResult {
    /// Format as string
    #[must_use]
    pub fn format(&self) -> String {
        let status = if self.passed { "" } else { "" };
        format!(
            "Startup Profile\n\
             ├─ parse:  {:>6.3}ms\n\
             ├─ env:    {:>6.3}ms\n\
             ├─ alias:  {:>6.3}ms\n\
             ├─ prompt: {:>6.3}ms\n\
             └─ total:  {:>6.3}ms {}\n",
            self.parse_time.as_secs_f64() * 1000.0,
            self.env_time.as_secs_f64() * 1000.0,
            self.alias_time.as_secs_f64() * 1000.0,
            self.prompt_time.as_secs_f64() * 1000.0,
            self.total_time.as_secs_f64() * 1000.0,
            status,
        )
    }
}

/// Run profile
pub fn run_profile() -> ProfileResult {
    use crate::executor::Executor;
    use crate::parser::Parser;
    use crate::prompt::Prompt;

    let config = CompiledConfig::default();
    let total_start = Instant::now();

    // Parser
    let start = Instant::now();
    let _ = Parser::new(&config);
    let parse_time = start.elapsed();

    // Executor (env + alias)
    let start = Instant::now();
    let _ = Executor::new(&config);
    let env_time = start.elapsed();

    let alias_time = Duration::ZERO; // Included in executor

    // Prompt
    let start = Instant::now();
    let _ = Prompt::new(&config);
    let prompt_time = start.elapsed();

    let total_time = total_start.elapsed();
    let passed = total_time < Duration::from_millis(MAX_STARTUP_MS);

    ProfileResult {
        parse_time,
        env_time,
        alias_time,
        prompt_time,
        total_time,
        passed,
    }
}

/// Generate initial configuration
#[must_use]
pub fn generate_init_config(shell: &str) -> String {
    format!(
        r#"# pzsh configuration
# Performance-first shell framework with sub-10ms startup
# oh-my-zsh compatible features without the overhead

[pzsh]
version = "0.1.0"
shell = "{shell}"

[performance]
startup_budget_ms = 10
prompt_budget_ms = 2
lazy_load = true

[prompt]
# Format: {{user}}, {{host}}, {{cwd}}, {{git}}, {{char}}
format = "{{user}}@{{host}} {{cwd}} {{git}} {{char}} "
git_async = true
git_cache_ms = 1000
# Enable ANSI colors in prompt (oh-my-zsh style)
colors = true

[aliases]
# Add your aliases here (no subprocess calls!)
# Common git aliases (like oh-my-zsh git plugin)
ll = "ls -la"
la = "ls -A"
l = "ls -CF"
gs = "git status"
ga = "git add"
gc = "git commit"
gp = "git push"
gl = "git pull"
gd = "git diff"
gco = "git checkout"
gb = "git branch"
glog = "git log --oneline --graph"

[env]
# Add your environment variables here (pre-resolved paths only!)
EDITOR = "vim"
# GOROOT = "/usr/local/opt/go/libexec"  # Example: hardcoded, not $(brew --prefix)

[plugins]
# Built-in plugins: git, docker
# Plugins provide aliases and shell integration while maintaining O(1) startup
enabled = ["git"]
lazy = ["docker"]

[completion]
# Enable intelligent auto-complete
enabled = true
# Use aprender-shell ML model for predictions (when available)
# model_path = "~/.pzsh/models/aprender-shell.onnx"

[keybindings]
# ctrl-r = "history-search"
# ctrl-p = "completion-prev"
# ctrl-n = "completion-next"
"#
    )
}

/// Generate shell initialization script
#[must_use]
pub fn generate_shell_init(shell: &str) -> String {
    match shell {
        "bash" => generate_bash_init(),
        _ => generate_zsh_init(),
    }
}

fn generate_zsh_init() -> String {
    r#"# pzsh initialization for zsh
# Add to your .zshrc: eval "$(pzsh init zsh)"

# Completion system
autoload -Uz compinit
compinit -C  # -C for faster startup (skip security check)

# Enable colors
autoload -U colors && colors

# History settings (optimized)
HISTSIZE=10000
SAVEHIST=10000
setopt SHARE_HISTORY
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE

# Key bindings
bindkey -e  # Emacs mode (or use -v for vi mode)
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward
bindkey '^R' history-incremental-search-backward

# Load pzsh config
if [[ -f ~/.pzshrc ]]; then
    # Source compiled config (O(1))
    source <(pzsh compile --config ~/.pzshrc 2>/dev/null || echo "")
fi
"#
    .to_string()
}

fn generate_bash_init() -> String {
    r#"# pzsh initialization for bash
# Add to your .bashrc: eval "$(pzsh init bash)"

# Enable colors
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

# History settings
HISTSIZE=10000
HISTFILESIZE=20000
HISTCONTROL=ignoreboth
shopt -s histappend

# Load pzsh config
if [[ -f ~/.pzshrc ]]; then
    # Source compiled config (O(1))
    eval "$(pzsh compile --config ~/.pzshrc 2>/dev/null || echo "")"
fi
"#
    .to_string()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_bench_passes_under_10ms() {
        let result = run_bench(10, false);
        assert!(result.passed, "Benchmark should pass under 10ms");
    }

    #[test]
    fn test_lint_detects_subprocess() {
        let content = r#"
export GOROOT="$(brew --prefix golang)/libexec"
"#;
        let result = lint_config(content);
        assert!(!result.passed());
        assert!(!result.issues.is_empty());
    }

    #[test]
    fn test_lint_detects_backticks() {
        let content = r#"
export DATE=`date`
"#;
        let result = lint_config(content);
        assert!(!result.passed());
    }

    #[test]
    fn test_lint_detects_oh_my_zsh() {
        let content = r#"
source $ZSH/oh-my-zsh.sh
"#;
        let result = lint_config(content);
        assert!(!result.passed());
    }

    #[test]
    fn test_lint_clean_config() {
        let content = r#"
export EDITOR="vim"
alias ll="ls -la"
"#;
        let result = lint_config(content);
        assert!(result.passed());
        assert!(result.issues.is_empty());
    }

    #[test]
    fn test_profile_under_10ms() {
        let result = run_profile();
        assert!(result.passed, "Profile should pass under 10ms");
    }

    #[test]
    fn test_generate_init_config() {
        let config = generate_init_config("zsh");
        assert!(config.contains("shell = \"zsh\""));
        assert!(config.contains("startup_budget_ms = 10"));
    }

    #[test]
    fn test_lint_detects_nvm() {
        let content = r#"
source ~/.nvm/nvm.sh
"#;
        let result = lint_config(content);
        assert!(!result.issues.is_empty());
        assert!(result.issues.iter().any(|i| i.message.contains("NVM")));
    }

    #[test]
    fn test_lint_detects_conda() {
        let content = r#"
source ~/miniconda3/etc/profile.d/conda.sh
"#;
        let result = lint_config(content);
        assert!(!result.issues.is_empty());
        assert!(result.issues.iter().any(|i| i.message.contains("conda")));
    }

    #[test]
    fn test_lint_detects_eval() {
        let content = r#"
eval "$(pyenv init -)"
"#;
        let result = lint_config(content);
        assert!(!result.passed());
        assert!(result.issues.iter().any(|i| i.message.contains("eval")));
    }

    #[test]
    fn test_lint_ignores_comments() {
        let content = r#"
# eval "$(something)"
# `backticks`
# source nvm.sh
"#;
        let result = lint_config(content);
        // Comments should be ignored for backticks and eval, but not for other patterns
        let eval_issues: Vec<_> = result
            .issues
            .iter()
            .filter(|i| i.message.contains("eval"))
            .collect();
        let backtick_issues: Vec<_> = result
            .issues
            .iter()
            .filter(|i| i.message.contains("backtick"))
            .collect();
        assert!(eval_issues.is_empty(), "eval in comments should be ignored");
        assert!(
            backtick_issues.is_empty(),
            "backticks in comments should be ignored"
        );
    }

    #[test]
    fn test_bench_result_format() {
        let result = BenchResult {
            iterations: 100,
            min: Duration::from_micros(100),
            max: Duration::from_micros(500),
            mean: Duration::from_micros(200),
            p50: Duration::from_micros(180),
            p95: Duration::from_micros(400),
            p99: Duration::from_micros(450),
            std_dev: Duration::from_micros(50),
            passed: true,
        };
        let formatted = result.format();
        assert!(formatted.contains("100 iterations"));
        assert!(formatted.contains("Budget: 10ms"));
        assert!(formatted.contains(""));
    }

    #[test]
    fn test_bench_result_format_failed() {
        let result = BenchResult {
            iterations: 10,
            min: Duration::from_millis(5),
            max: Duration::from_millis(15),
            mean: Duration::from_millis(12),
            p50: Duration::from_millis(11),
            p95: Duration::from_millis(14),
            p99: Duration::from_millis(15),
            std_dev: Duration::from_millis(2),
            passed: false,
        };
        let formatted = result.format();
        assert!(formatted.contains(""));
    }

    #[test]
    fn test_lint_result_format_with_issues() {
        let result = LintResult {
            issues: vec![
                LintIssue {
                    severity: LintSeverity::Error,
                    message: "test error".to_string(),
                    line: Some(10),
                    fix: Some("fix it".to_string()),
                },
                LintIssue {
                    severity: LintSeverity::Warning,
                    message: "test warning".to_string(),
                    line: None,
                    fix: None,
                },
                LintIssue {
                    severity: LintSeverity::Info,
                    message: "test info".to_string(),
                    line: Some(5),
                    fix: None,
                },
            ],
        };
        let formatted = result.format();
        assert!(formatted.contains("[error]"));
        assert!(formatted.contains("[warning]"));
        assert!(formatted.contains("[info]"));
        assert!(formatted.contains("(line 10)"));
        assert!(formatted.contains("fix: fix it"));
        assert!(formatted.contains("1 errors, 1 warnings"));
    }

    #[test]
    fn test_lint_result_format_empty() {
        let result = LintResult { issues: vec![] };
        let formatted = result.format();
        assert!(formatted.contains("0 issues found"));
    }

    #[test]
    fn test_profile_result_format() {
        let result = ProfileResult {
            parse_time: Duration::from_micros(500),
            env_time: Duration::from_micros(100),
            alias_time: Duration::from_micros(50),
            prompt_time: Duration::from_micros(200),
            total_time: Duration::from_micros(850),
            passed: true,
        };
        let formatted = result.format();
        assert!(formatted.contains("parse:"));
        assert!(formatted.contains("env:"));
        assert!(formatted.contains("total:"));
        assert!(formatted.contains(""));
    }

    #[test]
    fn test_profile_result_format_failed() {
        let result = ProfileResult {
            parse_time: Duration::from_millis(5),
            env_time: Duration::from_millis(3),
            alias_time: Duration::from_millis(2),
            prompt_time: Duration::from_millis(4),
            total_time: Duration::from_millis(14),
            passed: false,
        };
        let formatted = result.format();
        assert!(formatted.contains(""));
    }

    #[test]
    fn test_generate_init_config_bash() {
        let config = generate_init_config("bash");
        assert!(config.contains("shell = \"bash\""));
    }

    #[test]
    fn test_generate_init_config_has_colors() {
        let config = generate_init_config("zsh");
        assert!(config.contains("colors = true"));
    }

    #[test]
    fn test_generate_init_config_has_completion() {
        let config = generate_init_config("zsh");
        assert!(config.contains("[completion]"));
        assert!(config.contains("aprender-shell"));
    }

    #[test]
    fn test_generate_init_config_has_plugins() {
        let config = generate_init_config("zsh");
        assert!(config.contains("[plugins]"));
        assert!(config.contains("git"));
        assert!(config.contains("docker"));
    }

    #[test]
    fn test_generate_shell_init_zsh() {
        let init = generate_shell_init("zsh");
        assert!(init.contains("compinit"));
        assert!(init.contains("colors"));
        assert!(init.contains("HISTSIZE"));
    }

    #[test]
    fn test_generate_shell_init_bash() {
        let init = generate_shell_init("bash");
        assert!(init.contains("CLICOLOR"));
        assert!(init.contains("HISTSIZE"));
        assert!(init.contains("shopt"));
    }
}