-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from tsirysndr/feat/rtx-extension
feat: add rtx extension
- Loading branch information
Showing
12 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
authors = ["Tsiry Sandratraina <[email protected]>"] | ||
categories = ["command-line-utilities"] | ||
description = "Manage your dotfiles and packages with ease." | ||
edition = "2021" | ||
keywords = ["nix", "shell", "environment", "dotfiles"] | ||
license = "MIT" | ||
name = "envhub-ext" | ||
repository = "https://github.com/tsirysndr/envhub" | ||
version = "0.1.0" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1.0.71" | ||
envhub-types = {version = "0.2.0", path = "../types"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use anyhow::Error; | ||
use envhub_types::configuration::Configuration; | ||
|
||
pub mod rtx; | ||
|
||
pub trait Extension { | ||
fn load(&self, config: &Configuration) -> Result<(), Error>; | ||
fn setup(&self) -> Result<(), Error>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::{ | ||
env, fs, | ||
process::{Command, Stdio}, | ||
}; | ||
|
||
use anyhow::Error; | ||
use envhub_types::configuration::Configuration; | ||
|
||
use crate::Extension; | ||
|
||
pub struct Rtx {} | ||
|
||
impl Rtx { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
pub fn install(&self, package: &str) -> Result<(), Error> { | ||
let mut child = Command::new("sh") | ||
.arg("-c") | ||
.arg(format!("rtx install {}", package)) | ||
.stdin(Stdio::inherit()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.spawn()?; | ||
child.wait()?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Extension for Rtx { | ||
fn load(&self, config: &Configuration) -> Result<(), Error> { | ||
self.setup()?; | ||
match config.rtx { | ||
Some(ref rtx) => { | ||
for package in &rtx.packages { | ||
self.install(package)?; | ||
} | ||
} | ||
None => {} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn setup(&self) -> Result<(), Error> { | ||
env::set_var( | ||
"PATH", | ||
format!( | ||
"{}/.local/share/rtx/bin:{}", | ||
env::var("HOME")?, | ||
env::var("PATH")? | ||
), | ||
); | ||
env::set_var( | ||
"PATH", | ||
format!( | ||
"{}/.local/share/rtx/shims:{}", | ||
env::var("HOME")?, | ||
env::var("PATH")? | ||
), | ||
); | ||
let mut child = Command::new("sh") | ||
.arg("-c") | ||
.arg("type rtx > /dev/null || curl https://rtx.pub/install.sh | sh") | ||
.stdin(Stdio::inherit()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.spawn()?; | ||
child.wait()?; | ||
|
||
fs::create_dir_all(format!("{}/.local/share/rtx/shims", env::var("HOME")?))?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
packages = [ | ||
"hello" | ||
] | ||
|
||
rtx { | ||
packages = [ | ||
"[email protected]" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters