Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 2 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 43 additions & 65 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,44 @@ license = "MIT"
repository = "https://github.com/MordechaiHadad/bob"
rust-version = "1.85"


[[bin]]
path = "src/main.rs"
name = "bob"
proc-macro = false
required-features = []


[features]
default = ["rustls-tls"]
native-tls = ["reqwest/default-tls"]
rustls-tls = ["reqwest/rustls-tls-native-roots"]


[dependencies]
anyhow = "1.0.52"
cfg-if = "1.0"
indicatif = "0.18.0"
rand = "0.8.5"
serde_json = "1.0"
yansi = "0.5.1"
async-recursion = "1.0.2"
chrono = { version = "0.4.23", features = ["serde"] }
clap_complete = "4.1"
toml = "0.8.8"
clap_complete_nushell = "4.5.8"
clap = { version = "4.0.15", features = ["derive"] }
dialoguer = { version = "0.11.0" }
futures-util = { version = "0.3.14" }
indicatif = "0.18.0"
regex = "1.5"
reqwest = { version = "0.11", features = ["stream", "rustls-tls"] }
semver = "1.0.22"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10.8"
what-the-path = "^0.1.3"
sysinfo = "0.35.2"
clap_complete_nushell = "4.5.8"
tokio = { version = "1.16.1", features = ["full"] }
toml = "0.8.8"
tracing = "0.1.41"
tracing-subscriber = "0.3.20"
what-the-path = "^0.1.3"
yansi = "0.5.1"

[dependencies.chrono]
version = "0.4.23"
features = ["serde"]
optional = false

[dependencies.clap]
version = "4.0.15"
features = ["derive"]
optional = false

[dependencies.dialoguer]
version = "0.11.0"
features = []
optional = false
default-features = false

[dependencies.futures-util]
version = "0.3.14"
features = []
optional = false
default-features = false

[dependencies.regex]
version = "1.5"
features = []
optional = false

[dependencies.reqwest]
version = "0.11"
features = ["stream", "rustls-tls"]
optional = false
default-features = false

[dependencies.serde]
version = "1.0"
features = ["derive"]
optional = false

[dependencies.tokio]
version = "1.16.1"
features = ["full"]
optional = false

[dependencies.tracing]
version = "0.1.41"
features = []
optional = false

[dependencies.tracing-subscriber]
version = "0.3.20"
optional = false

[target.'cfg(unix)'.dependencies.nix]
version = "0.28.0"
Expand All @@ -96,12 +62,6 @@ winreg = "0.10.1"
zip = "2.2.0"


[[bin]]
path = "src/main.rs"
name = "bob"
proc-macro = false
required-features = []

[profile.dev]
opt-level = 1
codegen-units = 256
Expand All @@ -114,6 +74,24 @@ strip = true
lto = true
codegen-units = 1

[profile.dev.package."*"]
inherits = "dev"
codegen-units = 1
incremental = false

[profile.release.package."*"]
opt-level = "z"
strip = true
codegen-units = 1
incremental = false

[profile.optimized.package."*"]
opt-level = "z"
strip = true
codegen-units = 1
incremental = false


[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/v{ version }/bob-{ target-family }-{ target-arch }{ archive-suffix }"
bin-dir = "bob-{ target-family }-{ target-arch }/{ bin }{ binary-ext }"
Expand Down
94 changes: 54 additions & 40 deletions src/handlers/erase_handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::Path;

use anyhow::{Result, anyhow};
use tokio::fs;
use tracing::info;
Expand Down Expand Up @@ -46,46 +48,7 @@ pub async fn start(config: Config) -> Result<()> {
let downloads = directories::get_downloads_directory(&config).await?;
let mut installation_dir = directories::get_installation_directory(&config).await?;

cfg_if::cfg_if! {
if #[cfg(windows)] {
use winreg::RegKey;
use winreg::enums::*;

let current_usr = RegKey::predef(HKEY_CURRENT_USER);
let env = current_usr.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)?;
let usr_path: String = env.get_value("Path")?;
if usr_path.contains("neovim") {
let usr_path = usr_path.replace(&format!("{}", installation_dir.display()), "");
env.set_value("Path", &usr_path)?;

info!("Successfully removed neovim's installation PATH from registry");
}
} else {
use what_the_path::shell::Shell;

let shell = Shell::detect_by_shell_var()?;

match shell {
Shell::Fish(fish) => {
if let Ok(files) = fish.get_rcfiles() {
let fish_file = files[0].join("bob.fish");
if !fish_file.exists() { return Ok(()) }
fs::remove_file(fish_file).await?;
}
},
shell => {
if let Ok(files) = shell.get_rcfiles() {
let env_path = downloads.join("env/env.sh");
let source_string = format!(". \"{}\"", env_path.display());
for file in files {
what_the_path::shell::remove_from_rcfile(file, &source_string)?;
}

}
}
}
}
}
update_platform_path(&downloads, &installation_dir)?;

if config.installation_location.is_some() {
installation_dir.push("nvim");
Expand All @@ -95,6 +58,7 @@ pub async fn start(config: Config) -> Result<()> {
} else if fs::remove_dir_all(&installation_dir).await.is_ok() {
info!("Successfully removed neovim's installation folder");
}

if fs::remove_dir_all(downloads).await.is_ok() {
// For some weird reason this check doesn't really work for downloads folder
// as it keeps thinking the folder exists, and it runs with no issues even tho the folder
Expand All @@ -106,3 +70,53 @@ pub async fn start(config: Config) -> Result<()> {

Ok(())
}

#[cfg(windows)]
fn update_platform_path<P: AsRef<Path>>(_downloads: &P, installation_dir: &P) -> Result<()> {
use winreg::RegKey;
use winreg::enums::*;

let installation_dir = installation_dir.as_ref();

let current_usr = RegKey::predef(HKEY_CURRENT_USER);
let env = current_usr.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)?;
let usr_path: String = env.get_value("Path")?;
if usr_path.contains("neovim") {
let usr_path = usr_path.replace(&format!("{}", installation_dir.display()), "");
env.set_value("Path", &usr_path)?;

info!("Successfully removed neovim's installation PATH from registry");
}
Ok(())
}

#[cfg(not(windows))]
fn update_platform_path<P: AsRef<Path>>(downloads: &P, _installation_dir: &P) -> Result<()> {
use what_the_path::shell::Shell;

let shell = Shell::detect_by_shell_var()?;
let downloads = downloads.as_ref();

match shell {
Shell::Fish(fish) => {
if let Ok(files) = fish.get_rcfiles() {
let fish_file = files[0].join("bob.fish");
if !fish_file.exists() {
return Ok(());
}
std::fs::remove_file(fish_file)?; //.await?;
}
Ok(())
}
shell => {
if let Ok(files) = shell.get_rcfiles() {
let env_path = downloads.join("env/env.sh");
let source_string = format!(". \"{}\"", env_path.display());
for file in files {
what_the_path::shell::remove_from_rcfile(file, &source_string)?;
}
}
Ok(())
}
}
}
Loading
Loading