diff options
| -rw-r--r-- | Cargo.lock | 62 | ||||
| -rw-r--r-- | Cargo.toml | 3 | ||||
| -rw-r--r-- | src/app.rs | 36 | ||||
| -rw-r--r-- | tests/biblatex-test.bib | 2 |
4 files changed, 100 insertions, 3 deletions
@@ -71,12 +71,13 @@ dependencies = [ [[package]] name = "bibiman" -version = "0.8.1" +version = "0.8.2" dependencies = [ "arboard", "biblatex", "color-eyre", "crossterm", + "dirs", "editor-command", "futures", "itertools", @@ -315,6 +316,27 @@ dependencies = [ ] [[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[package]] name = "dlib" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -546,6 +568,17 @@ dependencies = [ ] [[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] name = "gimli" version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -678,6 +711,16 @@ dependencies = [ ] [[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", +] + +[[package]] name = "linux-raw-sys" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -914,6 +957,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] name = "os_pipe" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1057,6 +1106,17 @@ dependencies = [ ] [[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1,6 +1,6 @@ [package] name = "bibiman" -version = "0.8.1" +version = "0.8.2" authors = ["lukeflo <lukeflo_git@posteo.de>"] license = "GPL-3.0-or-later" repository = "https://codeberg.org/lukeflo/bibiman" @@ -20,6 +20,7 @@ arboard = { version = "3.4.1", features = ["wayland-data-control"] } biblatex = "0.10.0" color-eyre = "0.6.3" crossterm = { version = "0.28.1", features = ["event-stream"] } +dirs = "5.0.1" # doi = "0.3.0" editor-command = "0.1.1" futures = "0.3.30" @@ -24,6 +24,7 @@ use crate::tui::popup::PopupKind; use crate::tui::{self, Tui}; use crate::{bibiman::Bibiman, tui::commands::CmdAction}; use std::ffi::OsStr; +use std::path::PathBuf; use std::process::{Command, Stdio}; use tui::Event; use tui_input::backend::crossterm::EventHandler; @@ -335,6 +336,11 @@ pub fn open_connected_file(file: &OsStr) -> Result<()> { } }; + // If necessary, replace ~ with /home dir + let file = PathBuf::from(file); + + let file = expand_home(&file); + // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) let _ = Command::new(&cmd) @@ -380,3 +386,33 @@ pub fn prepare_weblink(url: &str) -> String { url.to_string() } } + +fn expand_home(path: &PathBuf) -> PathBuf { + // let path = PathBuf::from(path); + if path.starts_with("~") { + let mut home = dirs::home_dir().unwrap(); + let path = path.strip_prefix("~").unwrap(); + home.push(path); + home + } else { + path.into() + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_home_expansion() { + let path: PathBuf = "~/path/to/file.txt".into(); + + let path = expand_home(&path); + + let home: String = dirs::home_dir().unwrap().to_str().unwrap().to_string(); + + let full_path = home + "/path/to/file.txt"; + + assert_eq!(path, PathBuf::from(full_path)) + } +} diff --git a/tests/biblatex-test.bib b/tests/biblatex-test.bib index cf90822..b366fc3 100644 --- a/tests/biblatex-test.bib +++ b/tests/biblatex-test.bib @@ -71,7 +71,7 @@ keywords = {primary, ancient, philosophy}, langid = {english}, langidopts = {variant=american}, - file = {./tests/aristotle_physics.pdf}, + file = {~/Documents/projects/coding/bibiman/tests/aristotle_physics.pdf}, annotation = {A \texttt{book} entry with a \texttt{translator} field}, } |
