steer_core/utils/
mod.rs

1pub mod session;
2pub mod tracing;
3
4use std::path::{Path, PathBuf};
5
6/// Returns true if the path exists and is a git repository
7pub fn is_git_repo(path: &Path) -> bool {
8    let git_dir = path.join(".git");
9    git_dir.exists() && git_dir.is_dir()
10}
11
12/// Returns the platform information as a string
13pub fn get_platform() -> String {
14    #[cfg(target_os = "linux")]
15    return "linux".to_string();
16
17    #[cfg(target_os = "macos")]
18    return "macos".to_string();
19
20    #[cfg(target_os = "windows")]
21    return "windows".to_string();
22
23    #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
24    return "unknown".to_string();
25}
26
27/// Escapes special characters in a string for use in a regex
28pub fn escape_regex(s: &str) -> String {
29    let special_chars = r"[\^$.|?*+(){}";
30    let mut result = String::with_capacity(s.len() * 2);
31
32    for c in s.chars() {
33        if special_chars.contains(c) {
34            result.push('\\');
35        }
36        result.push(c);
37    }
38
39    result
40}
41
42/// Returns a default working directory, falling back through several options
43pub fn default_working_directory() -> PathBuf {
44    std::env::current_dir()
45        .or_else(|_| std::env::temp_dir().canonicalize())
46        .unwrap_or_else(|_| PathBuf::from("."))
47}