mirror of
https://git.sr.ht/~nixgoat/vento
synced 2025-07-23 13:00:55 +00:00
Compare commits
5 commits
f8750f3515
...
af0a27464b
Author | SHA1 | Date | |
---|---|---|---|
|
af0a27464b | ||
|
0434457475 | ||
|
4f0c52ac16 | ||
|
69ce377ec1 | ||
|
26699fe765 |
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -592,7 +592,7 @@ checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vento"
|
name = "vento"
|
||||||
version = "1.0.4"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"colored",
|
"colored",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "vento"
|
name = "vento"
|
||||||
version = "1.0.4"
|
version = "1.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,9 @@ $ vento
|
||||||
// switching inventory slots
|
// switching inventory slots
|
||||||
$ vento -c
|
$ vento -c
|
||||||
|
|
||||||
|
// undoing last action
|
||||||
|
$ vento -c
|
||||||
|
|
||||||
// taking a file or directory
|
// taking a file or directory
|
||||||
$ take <file|directory>
|
$ take <file|directory>
|
||||||
|
|
||||||
|
|
6
build.rs
6
build.rs
|
@ -56,6 +56,12 @@ fn vento() -> Result<Page> {
|
||||||
.long("--switch")
|
.long("--switch")
|
||||||
.help("Switches inventory slots"),
|
.help("Switches inventory slots"),
|
||||||
)
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new()
|
||||||
|
.short("-u")
|
||||||
|
.long("--undo")
|
||||||
|
.help("Undoes the last action"),
|
||||||
|
)
|
||||||
.flag(
|
.flag(
|
||||||
Flag::new()
|
Flag::new()
|
||||||
.short("-i")
|
.short("-i")
|
||||||
|
|
|
@ -30,11 +30,11 @@ fn main() -> Result<()> {
|
||||||
if args[1].contains("--slot=") {
|
if args[1].contains("--slot=") {
|
||||||
// Checks if the user has provided the long argument "--slot="
|
// Checks if the user has provided the long argument "--slot="
|
||||||
match args.len() {
|
match args.len() {
|
||||||
4 => item::drop(&args[2], &args[1].as_str().replace("--slot=", ""), Path::new(&args[4]).to_path_buf())?,
|
4 => item::drop(&args[2], &args[1].as_str().replace("--slot=", ""), Path::new(&args[4]).to_path_buf(), true)?,
|
||||||
3 => item::drop(&args[2], &args[1].as_str().replace("--slot=", ""), match env::current_dir() {
|
3 => item::drop(&args[2], &args[1].as_str().replace("--slot=", ""), match env::current_dir() {
|
||||||
Ok(dir) => dir,
|
Ok(dir) => dir,
|
||||||
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
||||||
})?,
|
}, true)?,
|
||||||
2 => bail!("{}", "You need to specify a file".red()),
|
2 => bail!("{}", "You need to specify a file".red()),
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => bail!("{}", "Too many arguments".red()),
|
||||||
};
|
};
|
||||||
|
@ -42,21 +42,21 @@ fn main() -> Result<()> {
|
||||||
match args[1].as_str() {
|
match args[1].as_str() {
|
||||||
"--help" | "-h" => help::drop()?,
|
"--help" | "-h" => help::drop()?,
|
||||||
"-s" => match args.len() {
|
"-s" => match args.len() {
|
||||||
5 => item::drop(&args[3], &args[2], Path::new(&args[4]).to_path_buf())?,
|
5 => item::drop(&args[3], &args[2], Path::new(&args[4]).to_path_buf(), true)?,
|
||||||
4 => item::drop(&args[3], &args[2], match env::current_dir() {
|
4 => item::drop(&args[3], &args[2], match env::current_dir() {
|
||||||
Ok(dir) => dir,
|
Ok(dir) => dir,
|
||||||
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
||||||
})?,
|
}, true)?,
|
||||||
3 => bail!("{}", "You need to specify a file".red()),
|
3 => bail!("{}", "You need to specify a file".red()),
|
||||||
2 => bail!("{}", "You need to specify a slot".red()),
|
2 => bail!("{}", "You need to specify a slot".red()),
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => bail!("{}", "Too many arguments".red()),
|
||||||
},
|
},
|
||||||
_ => match args.len() {
|
_ => match args.len() {
|
||||||
3 => item::drop(&args[1], &String::from("active"), Path::new(&args[2]).to_path_buf())?,
|
3 => item::drop(&args[1], &String::from("active"), Path::new(&args[2]).to_path_buf(), true)?,
|
||||||
2 => item::drop(&args[1], &String::from("active"), match env::current_dir() {
|
2 => item::drop(&args[1], &String::from("active"), match env::current_dir() {
|
||||||
Ok(dir) => dir,
|
Ok(dir) => dir,
|
||||||
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
||||||
})?,
|
}, true)?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => bail!("{}", "Too many arguments".red()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn main() -> Result<()> {
|
||||||
if args[1].contains("--slot=") {
|
if args[1].contains("--slot=") {
|
||||||
// Checks if the user has provided the long argument "--slot="
|
// Checks if the user has provided the long argument "--slot="
|
||||||
match args.len() {
|
match args.len() {
|
||||||
3 => item::take(&args[2], &args[1].replace("--slot=", ""))?,
|
3 => item::take(&args[2], &args[1].replace("--slot=", ""), true)?,
|
||||||
2 => bail!("{}", "You need to specify a file".red()),
|
2 => bail!("{}", "You need to specify a file".red()),
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => bail!("{}", "Too many arguments".red()),
|
||||||
};
|
};
|
||||||
|
@ -37,13 +37,13 @@ fn main() -> Result<()> {
|
||||||
match args[1].as_str() {
|
match args[1].as_str() {
|
||||||
"--help" | "-h" => help::take()?,
|
"--help" | "-h" => help::take()?,
|
||||||
"-s" => match args.len() {
|
"-s" => match args.len() {
|
||||||
4 => item::take(&args[3], &args[2])?,
|
4 => item::take(&args[3], &args[2], true)?,
|
||||||
3 => bail!("{}", "You need to specify a file".red()),
|
3 => bail!("{}", "You need to specify a file".red()),
|
||||||
2 => bail!("{}", "You need to specify a slot".red()),
|
2 => bail!("{}", "You need to specify a slot".red()),
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => bail!("{}", "Too many arguments".red()),
|
||||||
},
|
},
|
||||||
_ => match args.len() {
|
_ => match args.len() {
|
||||||
2 => item::take(&args[1], &String::from("active"))?,
|
2 => item::take(&args[1], &String::from("active"), true)?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => bail!("{}", "Too many arguments".red()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::env;
|
use std::env;
|
||||||
use vento::{help, inv};
|
use vento::{help, inv, item};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// Handles args in Vento
|
// Handles args in Vento
|
||||||
|
@ -39,6 +39,7 @@ fn main() -> Result<()> {
|
||||||
"-h" | "--help" => help::vento()?,
|
"-h" | "--help" => help::vento()?,
|
||||||
"-i" | "--init" => inv::init()?,
|
"-i" | "--init" => inv::init()?,
|
||||||
"-c" | "--switch" => inv::switch()?,
|
"-c" | "--switch" => inv::switch()?,
|
||||||
|
"-u" | "--undo" => item::undo()?,
|
||||||
"-s" => match args.len() {
|
"-s" => match args.len() {
|
||||||
4 => inv::list(&args[2], &args[3])?,
|
4 => inv::list(&args[2], &args[3])?,
|
||||||
3 => inv::list(&args[2], "")?,
|
3 => inv::list(&args[2], "")?,
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub struct Settings {
|
||||||
pub struct HistoryData {
|
pub struct HistoryData {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub file: String,
|
pub file: String,
|
||||||
|
pub slot: String,
|
||||||
pub action: Action,
|
pub action: Action,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +42,8 @@ pub enum Action {
|
||||||
Drop,
|
Drop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides required variables for Vento
|
||||||
pub fn env_config() -> Result<Settings> {
|
pub fn env_config() -> Result<Settings> {
|
||||||
// Configures the directories for Vento
|
|
||||||
let home = match dirs::home_dir() {
|
let home = match dirs::home_dir() {
|
||||||
Option::Some(dir) => dir,
|
Option::Some(dir) => dir,
|
||||||
_ => PathBuf::new(),
|
_ => PathBuf::new(),
|
||||||
|
@ -99,6 +100,7 @@ fn dir_config() -> Result<String> {
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Writes an action into the history file
|
||||||
pub fn history(data: HistoryData) -> Result<()> {
|
pub fn history(data: HistoryData) -> Result<()> {
|
||||||
let mut last_path = env_config()?.vento_dir;
|
let mut last_path = env_config()?.vento_dir;
|
||||||
last_path.push("last");
|
last_path.push("last");
|
||||||
|
@ -108,9 +110,11 @@ pub fn history(data: HistoryData) -> Result<()> {
|
||||||
&mut last_file,
|
&mut last_file,
|
||||||
"{}
|
"{}
|
||||||
{}
|
{}
|
||||||
|
{}
|
||||||
{}",
|
{}",
|
||||||
data.path.to_str().unwrap(),
|
data.path.to_str().unwrap(),
|
||||||
data.file,
|
data.file,
|
||||||
|
data.slot,
|
||||||
match data.action {
|
match data.action {
|
||||||
Action::Take => "take",
|
Action::Take => "take",
|
||||||
Action::Drop => "drop",
|
Action::Drop => "drop",
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
|
/// Displays the help message for the vento command
|
||||||
pub fn vento() -> Result<()> {
|
pub fn vento() -> Result<()> {
|
||||||
// A quick guide to move around in Vento
|
|
||||||
println!(
|
println!(
|
||||||
"{}, a CLI inventory for your files
|
"{}, a CLI inventory for your files
|
||||||
© 2022 Lux Aliaga. Licensed under GPLv3
|
© 2022 Lux Aliaga. Licensed under GPLv3
|
||||||
|
@ -29,6 +29,7 @@ pub fn vento() -> Result<()> {
|
||||||
{}
|
{}
|
||||||
- {}: Lists files in selected inventory
|
- {}: Lists files in selected inventory
|
||||||
- {}: Switches slots
|
- {}: Switches slots
|
||||||
|
- {}: Undoes the last action
|
||||||
- {}: Initializes Vento
|
- {}: Initializes Vento
|
||||||
- {}: Displays this message",
|
- {}: Displays this message",
|
||||||
"Vento".bold().blue(),
|
"Vento".bold().blue(),
|
||||||
|
@ -37,14 +38,15 @@ pub fn vento() -> Result<()> {
|
||||||
.bold()
|
.bold()
|
||||||
.green(),
|
.green(),
|
||||||
"vento ( -c | --switch )".bold().green(),
|
"vento ( -c | --switch )".bold().green(),
|
||||||
|
"vento ( -u | --undo )".bold().green(),
|
||||||
"vento ( -i | --init )".bold().green(),
|
"vento ( -i | --init )".bold().green(),
|
||||||
"vento ( -h | --help )".bold().green()
|
"vento ( -h | --help )".bold().green()
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Displays the help message for the take command
|
||||||
pub fn take() -> Result<()> {
|
pub fn take() -> Result<()> {
|
||||||
// A quick guide to move around in Take
|
|
||||||
println!(
|
println!(
|
||||||
"{}, a file grabber for Vento
|
"{}, a file grabber for Vento
|
||||||
© 2022 Lux Aliaga. Licensed under GPLv3
|
© 2022 Lux Aliaga. Licensed under GPLv3
|
||||||
|
@ -62,8 +64,8 @@ pub fn take() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Displays the help message for the drop command
|
||||||
pub fn drop() -> Result<()> {
|
pub fn drop() -> Result<()> {
|
||||||
// A quick guide to move around in Drop
|
|
||||||
println!(
|
println!(
|
||||||
"{}, a file dropper for Vento
|
"{}, a file dropper for Vento
|
||||||
© 2022 Lux Aliaga. Licensed under GPLv3
|
© 2022 Lux Aliaga. Licensed under GPLv3
|
||||||
|
|
|
@ -25,8 +25,8 @@ use std::io::{self, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{fs, process};
|
use std::{fs, process};
|
||||||
|
|
||||||
|
/// Initializes Vento by creating the respective directories it will use
|
||||||
pub fn init() -> Result<()> {
|
pub fn init() -> Result<()> {
|
||||||
// Initializes Vento
|
|
||||||
let ventodir = &common::env_config()?.vento_dir;
|
let ventodir = &common::env_config()?.vento_dir;
|
||||||
|
|
||||||
if ventodir.is_dir() {
|
if ventodir.is_dir() {
|
||||||
|
@ -45,8 +45,8 @@ pub fn init() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lists files in the provided slot and/or directory
|
||||||
pub fn list(slot: &str, dir: &str) -> Result<()> {
|
pub fn list(slot: &str, dir: &str) -> Result<()> {
|
||||||
// Lists files in inventory
|
|
||||||
let ventodir = &common::env_config()?.vento_dir;
|
let ventodir = &common::env_config()?.vento_dir;
|
||||||
|
|
||||||
if !ventodir.is_dir() {
|
if !ventodir.is_dir() {
|
||||||
|
@ -164,8 +164,8 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Switches inevntory slots between each other, making the currently active inventory inactive and viceversa
|
||||||
pub fn switch() -> Result<()> {
|
pub fn switch() -> Result<()> {
|
||||||
// Switches between inventory slots
|
|
||||||
let ventodir = &common::env_config()?.vento_dir;
|
let ventodir = &common::env_config()?.vento_dir;
|
||||||
let active = &common::env_config()?.active_dir;
|
let active = &common::env_config()?.active_dir;
|
||||||
let inactive = &common::env_config()?.inactive_dir;
|
let inactive = &common::env_config()?.inactive_dir;
|
||||||
|
@ -183,8 +183,8 @@ pub fn switch() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used only on init. Creates all required directories
|
||||||
fn create_slots() -> Result<()> {
|
fn create_slots() -> Result<()> {
|
||||||
// Used only on init. Creates all required directories
|
|
||||||
let active = &common::env_config()?.active_dir;
|
let active = &common::env_config()?.active_dir;
|
||||||
let inactive = &common::env_config()?.inactive_dir;
|
let inactive = &common::env_config()?.inactive_dir;
|
||||||
|
|
||||||
|
|
79
src/item.rs
79
src/item.rs
|
@ -24,8 +24,8 @@ use fs_extra::dir::{move_dir, CopyOptions};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub fn take(file: &String, slot: &str) -> Result<()> {
|
/// Takes a file or directory and stores it in an inventory slot
|
||||||
// Takes a file or directory
|
pub fn take(file: &String, slot: &str, message: bool) -> Result<()> {
|
||||||
let ventodir = &common::env_config()?.vento_dir;
|
let ventodir = &common::env_config()?.vento_dir;
|
||||||
|
|
||||||
if !ventodir.is_dir() {
|
if !ventodir.is_dir() {
|
||||||
|
@ -58,7 +58,9 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
|
||||||
let mut sourcelocation: PathBuf = fs::canonicalize(&sourcepath)?;
|
let mut sourcelocation: PathBuf = fs::canonicalize(&sourcepath)?;
|
||||||
sourcelocation.pop();
|
sourcelocation.pop();
|
||||||
let filename = Path::new(&file).file_name().unwrap().to_str().unwrap();
|
let filename = Path::new(&file).file_name().unwrap().to_str().unwrap();
|
||||||
let destpath: PathBuf = [&slotdir, &sourcepath].iter().collect();
|
let destpath: PathBuf = [&slotdir, &Path::new(&filename).to_path_buf()]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
if Path::exists(&destpath) {
|
if Path::exists(&destpath) {
|
||||||
// Checks if there's a file with the same name in the inventory.
|
// Checks if there's a file with the same name in the inventory.
|
||||||
|
@ -82,20 +84,24 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
|
||||||
common::history(common::HistoryData {
|
common::history(common::HistoryData {
|
||||||
path: sourcelocation.clone(),
|
path: sourcelocation.clone(),
|
||||||
file: String::from(filename),
|
file: String::from(filename),
|
||||||
|
slot: String::from(slot),
|
||||||
action: common::Action::Take,
|
action: common::Action::Take,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
println!(
|
if message {
|
||||||
"✅ {} {} {} ",
|
println!(
|
||||||
"Took".green(),
|
"✅ {} {} {} ",
|
||||||
&filename.bold(),
|
"Took".green(),
|
||||||
format!("from {}", &sourcelocation.to_str().unwrap()).green()
|
&filename.bold(),
|
||||||
);
|
format!("from {}", &sourcelocation.to_str().unwrap()).green()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
|
/// Drops a file or directory and stores it in an inventory slot
|
||||||
|
pub fn drop(file: &String, slot: &str, dest: PathBuf, message: bool) -> Result<()> {
|
||||||
// Drops a file or directory
|
// Drops a file or directory
|
||||||
let ventodir = &common::env_config()?.vento_dir;
|
let ventodir = &common::env_config()?.vento_dir;
|
||||||
|
|
||||||
|
@ -156,15 +162,56 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
|
||||||
common::history(common::HistoryData {
|
common::history(common::HistoryData {
|
||||||
path: destpath.clone(),
|
path: destpath.clone(),
|
||||||
file: String::from(file),
|
file: String::from(file),
|
||||||
|
slot: String::from(slot),
|
||||||
action: common::Action::Drop,
|
action: common::Action::Drop,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
println!(
|
if message {
|
||||||
"✅ {} {} {} ",
|
println!(
|
||||||
"Dropped".green(),
|
"✅ {} {} {} ",
|
||||||
&file.bold(),
|
"Dropped".green(),
|
||||||
format!("into {}", &destpath.to_str().unwrap()).green()
|
&file.bold(),
|
||||||
);
|
format!("into {}", &destpath.to_str().unwrap()).green()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Undoes the last action made by Vento using the history file located on the Vento directory
|
||||||
|
pub fn undo() -> Result<()> {
|
||||||
|
let lastpath: PathBuf = [
|
||||||
|
common::env_config()?.vento_dir,
|
||||||
|
Path::new("last").to_path_buf(),
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let lastfile = fs::read_to_string(lastpath)?;
|
||||||
|
|
||||||
|
let mut contents = vec![];
|
||||||
|
|
||||||
|
for line in lastfile.lines() {
|
||||||
|
contents.push(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
if contents.len() != 4 {
|
||||||
|
bail!("Invalid history length".red());
|
||||||
|
}
|
||||||
|
|
||||||
|
match contents[3] {
|
||||||
|
"take" => {
|
||||||
|
let destpath = Path::new(contents[0]).to_path_buf();
|
||||||
|
drop(&String::from(contents[1]), contents[2], destpath, false)?;
|
||||||
|
}
|
||||||
|
"drop" => {
|
||||||
|
let path = vec![contents[0], contents[1]].join("/");
|
||||||
|
take(&path, contents[2], false)?;
|
||||||
|
}
|
||||||
|
_ => bail!("Illegal action".red()),
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("✅ {}", "Last action undone".green());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue