Windows: look for git repos in the startup directory

This commit is contained in:
Roey Darwish Dror
2021-02-02 22:28:22 +02:00
parent 27a3d37591
commit 66e62cc3eb
4 changed files with 51 additions and 2 deletions

View File

@@ -1,11 +1,14 @@
use crate::error::SkipStep;
use crate::execution_context::ExecutionContext;
use crate::executor::{CommandExt, RunType};
use crate::powershell;
use crate::terminal::print_separator;
use crate::utils::require;
use crate::{error::SkipStep, steps::git::Repositories};
use anyhow::Result;
use std::process::Command;
use log::debug;
use std::convert::TryFrom;
use std::path::Path;
use std::{ffi::OsStr, process::Command};
pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> {
let choco = require("choco")?;
@@ -85,3 +88,25 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
pub fn reboot() {
Command::new("shutdown").args(&["/R", "/T", "0"]).spawn().ok();
}
pub fn insert_startup_scripts(ctx: &ExecutionContext, git_repos: &mut Repositories) -> Result<()> {
let startup_dir = ctx
.base_dirs()
.data_dir()
.join("Microsoft\\Windows\\Start Menu\\Programs\\Startup");
for entry in std::fs::read_dir(&startup_dir)? {
if let Ok(entry) = entry {
let path = entry.path();
if path.extension().and_then(OsStr::to_str) == Some("lnk") {
if let Ok(lnk) = parselnk::Lnk::try_from(Path::new(&path)) {
debug!("Startup link: {:?}", lnk);
if let Some(path) = lnk.relative_path() {
git_repos.insert_if_repo(&startup_dir.join(path));
}
}
}
}
}
Ok(())
}