Skip to content

Commit b2e95c9

Browse files
cursoragentseatedro
andcommitted
Add support for skipping config prompts in specific repositories
Co-authored-by: rohit <[email protected]>
1 parent d116df3 commit b2e95c9

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

src/config.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ pub struct Config {
8282

8383
#[serde(default)]
8484
pub traverse_links: bool,
85+
86+
/// List of canonical project directories for which the user has already declined to
87+
/// save a local `.glimpse` configuration file. When a directory is present in this
88+
/// list Glimpse will not prompt the user again.
89+
#[serde(default)]
90+
pub skipped_prompt_repos: Vec<String>,
8591
}
8692

8793
impl Default for Config {
@@ -95,6 +101,7 @@ impl Default for Config {
95101
default_tokenizer_model: default_tokenizer_model(),
96102
default_link_depth: default_link_depth(),
97103
traverse_links: false,
104+
skipped_prompt_repos: Vec::new(),
98105
}
99106
}
100107
}
@@ -202,3 +209,16 @@ pub fn load_repo_config(path: &Path) -> anyhow::Result<RepoConfig> {
202209
Ok(RepoConfig::default())
203210
}
204211
}
212+
213+
/// Persist the provided global configuration to disk, overriding any existing config file.
214+
pub fn save_config(config: &Config) -> anyhow::Result<()> {
215+
let config_path = get_config_path()?;
216+
217+
if let Some(parent) = config_path.parent() {
218+
std::fs::create_dir_all(parent)?;
219+
}
220+
221+
let config_str = toml::to_string_pretty(config)?;
222+
std::fs::write(config_path, config_str)?;
223+
Ok(())
224+
}

src/main.rs

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod url_processor;
1010

1111
use crate::analyzer::process_directory;
1212
use crate::cli::Cli;
13-
use crate::config::{get_config_path, load_config, load_repo_config, save_repo_config, RepoConfig};
13+
use crate::config::{get_config_path, load_config, load_repo_config, save_repo_config, save_config, RepoConfig};
1414
use crate::git_processor::GitProcessor;
1515
use crate::url_processor::UrlProcessor;
1616
use std::fs;
@@ -33,7 +33,7 @@ fn has_custom_options(args: &Cli) -> bool {
3333
}
3434

3535
fn main() -> anyhow::Result<()> {
36-
let config = load_config()?;
36+
let mut config = load_config()?;
3737
let mut args = Cli::parse_with_config(&config)?;
3838

3939
if args.config_path {
@@ -59,20 +59,55 @@ fn main() -> anyhow::Result<()> {
5959
let repo_config = create_repo_config_from_args(&args);
6060
save_repo_config(&glimpse_file, &repo_config)?;
6161
println!("Configuration saved to {}", glimpse_file.display());
62+
63+
// If the user explicitly saved a config, remove this directory from the skipped list
64+
if let Ok(canonical_root) = std::fs::canonicalize(&root_dir) {
65+
let root_str = canonical_root.to_string_lossy().to_string();
66+
if let Some(pos) = config
67+
.skipped_prompt_repos
68+
.iter()
69+
.position(|p| p == &root_str)
70+
{
71+
config.skipped_prompt_repos.remove(pos);
72+
save_config(&config)?;
73+
}
74+
}
6275
} else if glimpse_file.exists() {
6376
println!("Loading configuration from {}", glimpse_file.display());
6477
let repo_config = load_repo_config(&glimpse_file)?;
6578
apply_repo_config(&mut args, &repo_config);
6679
} else if has_custom_options(&args) {
67-
print!("Would you like to save these options as defaults for this directory? (y/n): ");
68-
io::stdout().flush()?;
69-
let mut response = String::new();
70-
io::stdin().read_line(&mut response)?;
71-
72-
if response.trim().to_lowercase() == "y" {
73-
let repo_config = create_repo_config_from_args(&args);
74-
save_repo_config(&glimpse_file, &repo_config)?;
75-
println!("Configuration saved to {}", glimpse_file.display());
80+
// Determine canonical root directory path for consistent tracking
81+
let canonical_root = std::fs::canonicalize(&root_dir).unwrap_or(root_dir.clone());
82+
let root_str = canonical_root.to_string_lossy().to_string();
83+
84+
if !config.skipped_prompt_repos.contains(&root_str) {
85+
print!(
86+
"Would you like to save these options as defaults for this directory? (y/n): "
87+
);
88+
io::stdout().flush()?;
89+
let mut response = String::new();
90+
io::stdin().read_line(&mut response)?;
91+
92+
if response.trim().to_lowercase() == "y" {
93+
let repo_config = create_repo_config_from_args(&args);
94+
save_repo_config(&glimpse_file, &repo_config)?;
95+
println!("Configuration saved to {}", glimpse_file.display());
96+
97+
// In case it was previously skipped, remove from skipped list
98+
if let Some(pos) = config
99+
.skipped_prompt_repos
100+
.iter()
101+
.position(|p| p == &root_str)
102+
{
103+
config.skipped_prompt_repos.remove(pos);
104+
save_config(&config)?;
105+
}
106+
} else {
107+
// Record that user declined for this project
108+
config.skipped_prompt_repos.push(root_str);
109+
save_config(&config)?;
110+
}
76111
}
77112
}
78113
}

0 commit comments

Comments
 (0)