diff --git a/README.md b/README.md index 1067cc31..77a01de0 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Just run `topgrade`. It will run the following steps: * ~/.config/fish * ~/.config/nvim * ~/.vim + * Powershell Profile * Custom defined paths * *Unix*: Run [zplug](https://github.com/zplug/zplug) update * *Unix*: Run [fisherman](https://github.com/fisherman/fisherman) update diff --git a/src/main.rs b/src/main.rs index 0208ac91..d417ef7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,6 +123,13 @@ fn run() -> Result<(), Error> { git_repos.insert(base_dirs.home_dir().join(".config/fish")); } + #[cfg(windows)] + { + if let Some(profile) = powershell.profile() { + git_repos.insert(profile); + } + } + if let Some(custom_git_repos) = config.git_repos() { for git_repo in custom_git_repos { git_repos.insert(git_repo); diff --git a/src/windows.rs b/src/windows.rs index 458bd596..b38609ba 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -41,6 +41,24 @@ impl Powershell { }().is_ok() } + pub fn profile(&self) -> Option { + if let Some(powershell) = &self.path { + let result = || -> Result { + let output = Command::new(powershell).args(&["-Command", "echo $profile"]).output()?; + output.status.check()?; + Ok(PathBuf::from( + String::from_utf8_lossy(&output.stdout).trim().to_string(), + )) + }(); + + match result { + Err(e) => error!("Error getting Powershell profile: {}", e), + Ok(path) => return Some(path), + } + } + None + } + #[must_use] pub fn update_modules(&self, terminal: &mut Terminal) -> Option<(&'static str, bool)> { if let Some(powershell) = &self.path {