Skip to main content

slox_shim/
lib.rs

1use std::path::PathBuf;
2
3pub struct Shim {
4    target: PathBuf,
5}
6
7impl Shim {
8    pub fn new(bin: &str) -> Self {
9        let path = PathBuf::from(bin);
10        if !path.exists() {
11            panic!("Requested path is not available: {}", bin);
12        }
13
14        Self { target: path }
15    }
16
17    pub fn generate(&self) -> String {
18        let target_path = self.target.to_string_lossy();
19
20        // The shim targets a fixed absolute path so it remains stable regardless
21        // of the working directory it is invoked from.
22        // regardless of where it's called from.
23        format!("#!/bin/sh\nexec \"{}\" \"$@\"", target_path)
24    }
25}