Skip to content

Commit bc3e459

Browse files
authored
Merge pull request #151 from xscriptor/update/plugins
update remove function plugins
2 parents 878f688 + c11fe2f commit bc3e459

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod ui;
55

66
use crate::config::{generate_config, load_config};
77
use crate::info::Info;
8-
use crate::plugins::{install_plugin, list_plugins};
8+
use crate::plugins::{install_plugin, list_plugins, remove_plugin};
99
use crate::ui::draw;
1010
use clap::{Parser, Subcommand};
1111

@@ -15,7 +15,7 @@ use clap::{Parser, Subcommand};
1515
version,
1616
about,
1717
long_about = None,
18-
after_help = "Examples:\n xfetch\n xfetch --config ~/.config/xfetch/config.jsonc\n xfetch --gen-config\n xfetch plugin install ./plugins/animate-logo\n xfetch plugin list"
18+
after_help = "Examples:\n xfetch\n xfetch --config ~/.config/xfetch/config.jsonc\n xfetch --gen-config\n xfetch plugin install ./plugins/animate-logo\n xfetch plugin list\n xfetch plugin remove animate-logo"
1919
)]
2020
struct Cli {
2121
#[command(subcommand)]
@@ -57,6 +57,11 @@ enum PluginCommands {
5757
},
5858
/// List installed plugins
5959
List,
60+
/// Remove an installed plugin
61+
Remove {
62+
/// Name of the plugin to remove (e.g., animate-logo)
63+
name: String,
64+
},
6065
}
6166

6267
fn main() {
@@ -106,6 +111,15 @@ fn main() {
106111
}
107112
}
108113
}
114+
PluginCommands::Remove { name } => {
115+
match remove_plugin(&name) {
116+
Ok(()) => {}
117+
Err(err) => {
118+
eprintln!("Error: {}", err);
119+
std::process::exit(1);
120+
}
121+
}
122+
}
109123
},
110124
None => {
111125
// Normal fetch behavior

src/plugins.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ fn install_remote_plugin(name: &str, repo_url: &str) -> Result<(), String> {
189189
.args([
190190
"clone",
191191
"--depth", "1",
192-
"--filter=blob:none",
193-
"--sparse",
194192
repo_url,
195193
])
196194
.arg(&temp_dir)
@@ -204,15 +202,7 @@ fn install_remote_plugin(name: &str, repo_url: &str) -> Result<(), String> {
204202
return Err("Failed to clone repository".to_string());
205203
}
206204

207-
let sparse_checkout = Command::new("git")
208-
.args(["sparse-checkout", "set", &format!("plugins/{}", name)])
209-
.current_dir(&temp_dir)
210-
.stdout(Stdio::inherit())
211-
.stderr(Stdio::inherit())
212-
.status()
213-
.map_err(|_| "Failed to set sparse checkout".to_string())?;
214-
215-
if !sparse_checkout.success() || !plugin_path.is_dir() {
205+
if !plugin_path.is_dir() {
216206
let _ = fs::remove_dir_all(&temp_dir);
217207
return Err(format!(
218208
"Plugin '{}' not found in repository '{}'.\n\
@@ -227,6 +217,25 @@ fn install_remote_plugin(name: &str, repo_url: &str) -> Result<(), String> {
227217
result
228218
}
229219

220+
pub fn remove_plugin(name: &str) -> Result<(), String> {
221+
let binary_name = plugin_binary_name(name);
222+
let plugin_dir = default_plugin_dir();
223+
let binary_path = plugin_dir.join(&binary_name);
224+
225+
if binary_path.is_file() {
226+
fs::remove_file(&binary_path)
227+
.map_err(|err| format!("Failed to remove plugin '{}': {}", name, err))?;
228+
println!("Removed plugin '{}'", name);
229+
Ok(())
230+
} else {
231+
Err(format!(
232+
"Plugin '{}' is not installed (not found at {})",
233+
name,
234+
binary_path.display()
235+
))
236+
}
237+
}
238+
230239
pub fn list_plugins() -> Result<Vec<(String, PathBuf)>, String> {
231240
let mut plugins = Vec::new();
232241

0 commit comments

Comments
 (0)