aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md13
-rw-r--r--example-config.toml2
-rw-r--r--src/app.rs22
-rw-r--r--src/cliargs.rs7
4 files changed, 20 insertions, 24 deletions
diff --git a/README.md b/README.md
index 47d57de..d62c847 100644
--- a/README.md
+++ b/README.md
@@ -56,7 +56,7 @@ POSITIONAL ARGS:
FLAGS:
-h, --help Show this help and exit
-v, --version Show the version and exit
- -c, --config-file Path to config file for current session
+ -c, --config-file= Path to config file for current session needed as argument.
Takes precedence over standard config file
--light-terminal Enable color mode for light terminal background
@@ -129,10 +129,17 @@ At the moment, the following values can be set through the config file:
bibfiles = [ "/path/to/bibfile", "path/to/dir/with/bibfiles" ]
# Default editor to use when editing files. Arguments are possible
editor = "vim" # with args: "vim -y"
+# Default app to open PDFs/Epubs
+pdf_opener = "xdg-open"
+# Default app to open URLs/DOIs
+url_opener = "xdg-open"
```
-Paths to bibfiles/dirs passed through the CLI will be added to the ones provided
-by the config file.
+No value *needs* to be set. For every one exists a default value. Only exception
+is the `bibfiles` key. If no file or dir is set, you *have to* add a path via
+CLI interface. If the `bibfiles` value is set *and* a further path (or multiple)
+is provided through the CLI call, the entries of all those files will be opened
+in the started `bibiman` session.
## Features
diff --git a/example-config.toml b/example-config.toml
index 9d110ed..50c0467 100644
--- a/example-config.toml
+++ b/example-config.toml
@@ -1,5 +1,5 @@
[general]
-bibfiles = ["./tests/biblatex-test.bib"] # files and dirs are possible
+bibfiles = ["./tests/biblatex-test.bib"] # multiple files and dirs are possible
editor = "vim" # arguments are possible: "vim -y"
# pdf_opener = "xdg-open"
# url_opener = "xdg-open"
diff --git a/src/app.rs b/src/app.rs
index e03f8d7..55f49de 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -364,15 +364,6 @@ impl App {
pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> {
// Build command to execute pdf-reader. 'xdg-open' is Linux standard
- // TODO: make custom opener command possible through config
- // let cmd = {
- // match std::env::consts::OS {
- // "linux" => String::from("xdg-open"),
- // "macos" => String::from("open"),
- // "windows" => String::from("start"),
- // _ => panic!("Couldn't detect OS for setting correct opener"),
- // }
- // };
let cmd = match &cfg.general.pdf_opener {
Some(c) => c,
None => &select_opener(),
@@ -397,15 +388,6 @@ pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> {
pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> {
// Build command to execute pdf-reader. 'xdg-open' is Linux standard
- // TODO: make custom opener command possible through config
- // let cmd = {
- // match std::env::consts::OS {
- // "linux" => String::from("xdg-open"),
- // "macos" => String::from("open"),
- // "windows" => String::from("start"),
- // _ => panic!("Couldn't detect OS for setting correct opener"),
- // }
- // };
let cmd = match &cfg.general.url_opener {
Some(c) => c,
None => &select_opener(),
@@ -433,8 +415,8 @@ pub fn prepare_weblink(url: &str) -> String {
}
}
-fn expand_home(path: &PathBuf) -> PathBuf {
- // let path = PathBuf::from(path);
+/// Expand leading tilde (`~`) to `/home/user`
+pub fn expand_home(path: &PathBuf) -> PathBuf {
if path.starts_with("~") {
let mut home = dirs::home_dir().unwrap();
let path = path.strip_prefix("~").unwrap();
diff --git a/src/cliargs.rs b/src/cliargs.rs
index 895f116..bb3c8d1 100644
--- a/src/cliargs.rs
+++ b/src/cliargs.rs
@@ -23,6 +23,7 @@ use std::env;
use std::path::PathBuf;
use walkdir::WalkDir;
+use crate::app;
use crate::tui::colors::AppColors;
// struct for CLIArgs
@@ -76,6 +77,12 @@ pub fn parse_files(args: Vec<PathBuf>) -> Vec<PathBuf> {
let mut files: Vec<PathBuf> = Vec::new();
// If pos arg is file, just push it to path vec
for i in args {
+ // Expand tilde to /home/user
+ let i = if i.starts_with("~") {
+ app::expand_home(&i)
+ } else {
+ i
+ };
if i.is_file() {
files.push(i);
// If pos arg is dir, walk dir and collect bibfiles