Skip to content

Commit

Permalink
fix: wrong path prefix for WSL.
Browse files Browse the repository at this point in the history
  • Loading branch information
shiipou committed Sep 5, 2024
1 parent f919ed9 commit 0d05e84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
17 changes: 14 additions & 3 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ fn main() {
let clone_location = match target_path {
Some(path) => path,
None => {
let workspaces_dir = Path::new(&config.workspaces_dir);
let workspaces_dir = &config.workspaces_dir;

workspaces_dir
.join(host.clone())
.join(group.clone())
.join(name.clone())
.to_path_buf()
}
};

Expand Down Expand Up @@ -168,9 +168,20 @@ fn main() {
if debug {
println!("Writing to {:?}", config.vscode_projectmanager_path);
}

let path_with_prefix = match &config.vscode_path_prefix {
Some(prefix) => {
let prefixed_path = prefix.to_owned()
+ clone_location
.to_str()
.expect("Cannot parse clone_location as a string");
Path::new(&prefixed_path).to_path_buf()
}
None => clone_location,
};
add_project_to_vscode(
config.vscode_projectmanager_path,
clone_location,
path_with_prefix,
host,
group,
name,
Expand Down
23 changes: 13 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const DEFAULT_REGEX: &str = r"^(?:https://|git@)([^/:]+)[/:]([^/]+)/([^\.]+(?:\.
#[derive(Serialize, Deserialize, Debug)]
#[serde(default)]
pub struct AppConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub vscode_path_prefix: Option<String>,
pub workspaces_dir: PathBuf,
pub nvim_projectmanager_path: PathBuf,
pub vscode_projectmanager_path: PathBuf,
Expand Down Expand Up @@ -59,7 +61,8 @@ impl Default for AppConfig {
);

AppConfig {
workspaces_dir: format!("vscode-remote://wsl+{}{}/workspaces", wsl_distro_name, wsl_user_home_path).into(),
vscode_path_prefix: Some(format!("vscode-remote://wsl+{}", wsl_distro_name)),
workspaces_dir: format!("{}/workspaces", wsl_user_home_path).into(),
nvim_projectmanager_path: format!("{}/.local/share/nvim/lazy/projectmgr.nvim/projects.json", wsl_user_home_path).into(),
vscode_projectmanager_path: format!("{}/AppData/Roaming/Code/User/globalStorage/alefragnani.project-manager/projects.json", win_user_home_path).into(),
regex: DEFAULT_REGEX.to_string()
Expand All @@ -72,16 +75,18 @@ impl Default for AppConfig {
let user_home_path =
std::env::var("HOME").expect("'HOME' environment variable must be set.");
AppConfig {
workspaces_dir: format!("{}/workspaces", user_home_path).into(),
nvim_projectmanager_path: format!("{}/.local/share/nvim/lazy/projectmgr.nvim/projects.json", user_home_path).into(),
vscode_projectmanager_path: format!("{}/Library/Application Support/Code/User/globalStorage/alefragnani.project-manager/projects.json", user_home_path).into(),
regex: DEFAULT_REGEX.to_string()
}
vscode_path_prefix: None,
workspaces_dir: format!("{}/workspaces", user_home_path).into(),
nvim_projectmanager_path: format!("{}/.local/share/nvim/lazy/projectmgr.nvim/projects.json", user_home_path).into(),
vscode_projectmanager_path: format!("{}/Library/Application Support/Code/User/globalStorage/alefragnani.project-manager/projects.json", user_home_path).into(),
regex: DEFAULT_REGEX.to_string()
}
}
"windows" => {
let user_home_path = std::env::var("USERPROFILE")
.expect("'USERPROFILE' environment variable must be set.");
AppConfig {
vscode_path_prefix: None,
workspaces_dir: format!("{}/workspaces", user_home_path).into(),
nvim_projectmanager_path: format!("{}/AppData/Roaming/nvim/", user_home_path).into(),
vscode_projectmanager_path: format!("{}/AppData/Roaming/Code/User/globalStorage/alefragnani.project-manager/projects.json", user_home_path).into(),
Expand All @@ -92,6 +97,7 @@ impl Default for AppConfig {
let user_home_path =
std::env::var("HOME").expect("'HOME' environment variable must be set.");
AppConfig {
vscode_path_prefix: None,
workspaces_dir: format!("{}/workspaces", user_home_path).into(),
nvim_projectmanager_path: format!("{}/.local/share/nvim/lazy/projectmgr.nvim/projects.json", user_home_path).into(),
vscode_projectmanager_path:format!("{}/.config/Code/User/globalStorage/alefragnani.project-manager/projects.json", user_home_path).into(),
Expand Down Expand Up @@ -169,10 +175,7 @@ fn get_wsl_user_name() -> Option<String> {
}

fn detect_wsl_with_envs() -> bool {
match std::env::var("WSL_DISTRO_NAME") {
Ok(_) => true,
_ => false,
}
std::env::var("WSL_DISTRO_NAME").is_ok()
}

pub fn add_project_to_nvim(
Expand Down

0 comments on commit 0d05e84

Please sign in to comment.