diff options
| author | lukeflo | 2025-02-27 17:45:40 +0100 |
|---|---|---|
| committer | lukeflo | 2025-02-27 17:45:40 +0100 |
| commit | c52dc7ed6951af2d74804d1275e577205960b235 (patch) | |
| tree | 3dc8acd0bd0e0a83922c2927cc5e00c35837ba5c | |
| parent | 5da77a2f812a0bb6e0057f7b2e2c642142fca125 (diff) | |
| download | bibiman-c52dc7ed6951af2d74804d1275e577205960b235.tar.gz bibiman-c52dc7ed6951af2d74804d1275e577205960b235.zip | |
add `file_prefix` option to config and opening function
| -rw-r--r-- | README.md | 20 | ||||
| -rw-r--r-- | files/bibiman.toml | 4 | ||||
| -rw-r--r-- | src/app.rs | 6 | ||||
| -rw-r--r-- | src/config.rs | 2 | ||||
| -rw-r--r-- | tests/biblatex-test.bib | 2 |
5 files changed, 32 insertions, 2 deletions
@@ -145,6 +145,9 @@ editor = "vim" # with args: "vim -y" pdf_opener = "xdg-open" # Default app to open URLs/DOIs url_opener = "xdg-open" +# Prefix which is prepended to the filepath from the `file` field +# Use absolute paths (~ for HOME works). Otherwise, loading might not work. +file_prefix = "/some/path/prefix" ``` If no file or dir is set as `bibfiles` value, you *have to* add a path via CLI @@ -152,6 +155,23 @@ 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. +The file prefix offers the possibility to keep file paths in your `.bib` file +short: E.g. a combination of those values in config and bibfile: + +```toml +# bibiman.toml +file_prefix = "~/Documents/literature" +``` + +```bibtex +# bibfile.bib +file = {aristotle.pdf} +``` + +Will result in opening the file `~/Documents/literature/aristotle.pdf` when +trying to open the PDF from inside `bibiman`. The `.bib` file itself will not be +edited! + ### Color Configuration<a name="color-configuration"></a> Furthermore, it is now possible to customize the colors. The following values diff --git a/files/bibiman.toml b/files/bibiman.toml index 2e5d51b..987e780 100644 --- a/files/bibiman.toml +++ b/files/bibiman.toml @@ -12,6 +12,10 @@ ## Default app to open URLs/DOIs # url_opener = "xdg-open" +## Prefix which is prepended to the filepath from the `file` field +## Use absolute paths (~ for HOME works). Otherwise, loading might not work. +# file_prefix = [ "/some/path/prefix" ] + # [colors] ## Default values for dark-themed terminal ## Possible values are: @@ -359,7 +359,11 @@ pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard let cmd = &cfg.general.pdf_opener; // If necessary, replace ~ with /home dir - let file = PathBuf::from(file); + let file = if cfg.general.file_prefix.is_some() { + cfg.general.file_prefix.clone().unwrap().join(file) + } else { + PathBuf::from(file) + }; let file = expand_home(&file); diff --git a/src/config.rs b/src/config.rs index 956b724..f1ac3ca 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,6 +41,7 @@ pub struct General { pub editor: Option<String>, pub pdf_opener: String, pub url_opener: String, + pub file_prefix: Option<PathBuf>, } /// Substruct [colors] in config.toml @@ -66,6 +67,7 @@ impl Default for BibiConfig { editor: None, pdf_opener: select_opener(), url_opener: select_opener(), + file_prefix: None, }, colors: Colors { main_text_color: Color::Indexed(250), diff --git a/tests/biblatex-test.bib b/tests/biblatex-test.bib index 0a1202e..4071dcb 100644 --- a/tests/biblatex-test.bib +++ b/tests/biblatex-test.bib @@ -80,7 +80,7 @@ keywords = {primary, ancient, philosophy}, langid = {english}, langidopts = {variant=american}, - file = {~/Documents/projects/coding/bibiman/tests/aristotle_physics.pdf}, + file = {~/Documents/coding/projects/bibiman/tests/aristotle_physics.pdf}, annotation = {A \texttt{book} entry with a \texttt{translator} field}, } |
