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

20
Cargo.lock generated
View File

@@ -943,6 +943,19 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "parselnk"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d098204d9ef47f80312460c1555a152972ea9f0a67487a77b2ab7e03fd510d4f"
dependencies = [
"bitflags 1.2.1",
"byteorder",
"chrono",
"thiserror",
"widestring",
]
[[package]]
name = "percent-encoding"
version = "2.1.0"
@@ -1700,6 +1713,7 @@ dependencies = [
"nix",
"notify-rust",
"openssl-probe",
"parselnk",
"pretty_env_logger",
"regex",
"rust-ini",
@@ -1958,6 +1972,12 @@ dependencies = [
"thiserror",
]
[[package]]
name = "widestring"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
[[package]]
name = "winapi"
version = "0.3.9"

View File

@@ -44,6 +44,7 @@ self_update_crate = { version = "0.23.0", optional = true, package = "self_upda
[target.'cfg(windows)'.dependencies]
self_update_crate = { version = "0.23.0", optional = true, package = "self_update", features = ["archive-zip", "compression-zip-deflate"] }
winapi = "0.3.9"
parselnk = "0.1"
[target.'cfg(target_os = "linux")'.dependencies]
rust-ini = "0.16.0"

View File

@@ -222,6 +222,9 @@ fn run() -> Result<()> {
.join("Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState"),
);
#[cfg(windows)]
windows::insert_startup_scripts(&ctx, &mut git_repos).ok();
if let Some(profile) = powershell.profile() {
git_repos.insert_if_repo(profile);
}

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(())
}