Skip to content

Commit

Permalink
Add terminal args variable
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed Oct 20, 2024
1 parent aefe2da commit 3d05098
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ A (supported) PDF viewer is not necessary, but it will provide the file name
and the current page number for later reference.

**Note:** Currently, the application is only tested on Linux systems and probably won't work on Windows.
Also, it currently uses arguments which are specific to the `st` terminal, but I expect to fix the latter within
the next couple of days.

(I am open for better names for this application)

Expand All @@ -24,32 +22,35 @@ https://github.com/user-attachments/assets/78836e33-c59a-4773-83ac-4d5d028e5a82

### Steps
1. Clone this repository:
```
```bash
git clone https://github.com/yourusername/bookminer.git
cd bookminer
```

2. Build the application:
```
```bash
cargo build --release
```

3. Add the compiled binary to your PATH:
```
```bash
sudo cp ./target/release/bookminer /usr/local/bin/
```

## Usage

BookMiner uses the `EDITOR` and `TERMINAL` environment variables to choose the terminal and editor.
Ensure these are set in your environment. \
Then map the binary `bookminer` binary to a key in your window manager. \
You can also specify a custom terminal and editor for a single session by using:
You can either set these in your environment (`.bash_profile` for bash) or pass them like this:
```bash
TERMINAL=st EDITOR=nvim bookminer
```
Then map the binary `bookminer` binary to a key in your window manager. \
You can also pass arguments to the spawned terminal with the `BM_TERMINAL_ARGS` environment variable:
```bash
TERMINAL="st" BM_TERMINAL_ARGS="-n floatterm -g 90x25" bookminer
```

You can either use Vim keys (`j`,`k`) to move up and down in the menus or use arrow keys.
In the menus, you can then either use Vim keys (`j`,`k`) or arrow keys to move up and down.

### Supported PDF viewers

Expand Down
7 changes: 7 additions & 0 deletions src/env_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ pub fn get_terminal_binary_name() -> String {
process::exit(1);
}
}
}

pub fn get_terminal_args() -> Vec<String> {
match env::var("BM_TERMINAL_ARGS") {
Ok(terminal_args) => terminal_args.split(" ").map(|s| String::from(s)).collect(),
Err(_) => Vec::with_capacity(0),
}
}
12 changes: 4 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use anyhow::{anyhow, Context, Result};
use std::process::{Child, Command, Stdio};
use clap::Parser;
use tempfile::TempDir;
use crate::env_variables::get_terminal_binary_name;
use crate::env_variables::{get_terminal_args, get_terminal_binary_name};
use crate::main_application::run_terminal_application;
use crate::screenshot::{create_unique_screenshot_filename, capture_screenshot, save_image};

Expand Down Expand Up @@ -66,18 +66,14 @@ fn create_tmp_dir() -> std::io::Result<TempDir> {

fn spawn_terminal_with_main_process(tmp_dir: &Path, screenshot_path: &Path, args: Args) -> Result<Child> {
let terminal_name = get_terminal_binary_name();
let terminal_args = get_terminal_args();

let mut command = Command::new(terminal_name);

command
.arg("-n")
.arg("floatterm")
.arg("-g")
.arg("90x25")
.arg("-e");
terminal_args.iter().for_each(|arg| {command.arg(arg);});

// Application arguments
command
.arg("-e")
.arg(std::env::current_exe()?)
.arg("--main")
.arg("--tmp-dir")
Expand Down

0 comments on commit 3d05098

Please sign in to comment.