generated from nhcarrigan/template
feat: add /cd command to change working directory
This commit is contained in:
@@ -105,6 +105,51 @@ pub async fn get_usage_stats(
|
||||
manager.get_usage_stats(&conversation_id)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn validate_directory(path: String, current_dir: Option<String>) -> Result<String, String> {
|
||||
use std::path::Path;
|
||||
|
||||
let path = Path::new(&path);
|
||||
|
||||
// Expand ~ to home directory
|
||||
let expanded_path = if path.starts_with("~") {
|
||||
if let Some(home) = std::env::var_os("HOME") {
|
||||
let home_path = Path::new(&home);
|
||||
if path == Path::new("~") {
|
||||
home_path.to_path_buf()
|
||||
} else {
|
||||
home_path.join(path.strip_prefix("~").unwrap())
|
||||
}
|
||||
} else {
|
||||
return Err("Could not determine home directory".to_string());
|
||||
}
|
||||
} else if path.is_relative() {
|
||||
// Handle relative paths (., .., or any relative path) by resolving against current_dir
|
||||
if let Some(ref cwd) = current_dir {
|
||||
Path::new(cwd).join(path)
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
}
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
};
|
||||
|
||||
// Check if the path exists and is a directory
|
||||
if !expanded_path.exists() {
|
||||
return Err(format!("Directory does not exist: {}", expanded_path.display()));
|
||||
}
|
||||
|
||||
if !expanded_path.is_dir() {
|
||||
return Err(format!("Path is not a directory: {}", expanded_path.display()));
|
||||
}
|
||||
|
||||
// Return the canonicalized (absolute) path
|
||||
expanded_path
|
||||
.canonicalize()
|
||||
.map(|p| p.to_string_lossy().to_string())
|
||||
.map_err(|e| format!("Failed to resolve path: {}", e))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn load_saved_achievements(app: AppHandle) -> Result<Vec<AchievementUnlockedEvent>, String> {
|
||||
use chrono::Utc;
|
||||
|
||||
Reference in New Issue
Block a user