Skip to content

Commit

Permalink
Many more links
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerthecoder committed Sep 21, 2024
1 parent 0dc65bb commit b5332a7
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 68 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ This repository contains all of my dotfiles, scripts, and configs I use across d

## Quick start

Download and run the setup script.
```
curl https://raw.githubusercontent.com/tylerthecoder/owl/main/setups/owl.sh | sh
curl https://raw.githubusercontent.com/tylerthecoder/owl/main/setups/owl/setup.sh | sh
```

Link files. This will ask to select a nest file.
```
owl link
```

Setup software
```
owl setup base-shell
owl setup zsh
owl setup python
```

## Getting Started

Expand Down
5 changes: 5 additions & 0 deletions comps/redwood/.shenv
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ for file in ~/.config/alias/*; do
[ -f "$file" ] && source "$file"
done

# Run owl-rc
for file in ~/.config/owl-rc/*; do
[ -f "$file" ] && source "$file"
done

# Secrets
[ -f "$HOME/.secrets" ] && source "$HOME/.secrets"

Expand Down
7 changes: 7 additions & 0 deletions setups/base-shell/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "base-shell",
"actions": [
"./setup.sh"
],
"links": [ ]
}
1 change: 1 addition & 0 deletions setups/base-shell/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo pacman -Sy ranger highlight bat xclip
1 change: 0 additions & 1 deletion setups/basic.sh

This file was deleted.

17 changes: 0 additions & 17 deletions setups/owl.sh

This file was deleted.

7 changes: 7 additions & 0 deletions setups/owl/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "owl",
"actions": [
"./setup.sh"
],
"links": [ ]
}
10 changes: 10 additions & 0 deletions setups/owl/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if [ ! -d ~/owl ]; then
echo "installing owl..."
curl -L https://github.com/tylerthecoder/owl/releases/download/main/owl -o owl-bin
chmod +x owl-bin
mv owl-bin /usr/local/bin/owl
git clone [email protected]:tylerthecoder/owl.git ~/owl
else
echo "owl already installed, updating..."
git -C ~/owl pull
fi
12 changes: 12 additions & 0 deletions setups/python/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "python",
"actions": [
"./setup.sh"
],
"links": [
{
"source": "setups/python/rc",
"target": "~/.config/owl-rc/pyenv"
}
]
}
3 changes: 3 additions & 0 deletions setups/python/rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
7 changes: 7 additions & 0 deletions setups/python/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
curl https://pyenv.run | bash

# Ask user for python version
read -p "Enter the Python version you want to install: " python_version

pyenv install $python_version
pyenv global $python_version
90 changes: 41 additions & 49 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct Config {
}

fn get_default_owl_path() -> PathBuf {
Path::new("/home/tyler/owl").to_path_buf()
let owl_path = "~/owl";
PathBuf::from(shellexpand::tilde(&owl_path).to_string())
}

fn get_config_path() -> String {
Expand Down Expand Up @@ -54,7 +55,7 @@ fn save_config(config: Config) {
std::fs::write(config_path, config_raw).expect("Unable to write config file");
}

fn verify_config() -> bool {
fn load_config() -> Config {
let mut config = get_config();
if !config.owl_path.exists() {
println!("Owl path {} does not exist", config.owl_path.display());
Expand All @@ -66,7 +67,9 @@ fn verify_config() -> bool {
config.owl_path = new_path;
save_config(config);
}
return true;

let new_config = get_config();
new_config
}

fn prompt_user_for_nest_path() -> PathBuf {
Expand Down Expand Up @@ -127,44 +130,35 @@ struct Cli {
enum Commands {
Link,
Sync,
Edit,
Setup { setup_name: String },
Update,
}

fn main() {
verify_config();
let config = load_config();
load_nest();

let cli = Cli::parse();
match cli.command {
Some(Commands::Link) => link_with_setups(),
Some(Commands::Sync) => {
println!("Syncing");
let owl_path = get_config().owl_path;

let owl_sync_script_path = Path::join(
Path::new(&owl_path),
Path::new("common/scripts/owl-sync.sh"),
);

println!(
"Running owl-sync.sh script at {}",
owl_sync_script_path.display()
);

// Run the owl-sync command
let mut cmd = std::process::Command::new(owl_sync_script_path);

cmd.spawn().expect("Unable to run owl-sync.sh");
}
Some(Commands::Edit) => println!("Editing"),
Some(Commands::Sync) => sync(&config),
Some(Commands::Setup { setup_name }) => run_setup(&setup_name),
Some(Commands::Update) => run_update(),
None => println!("No command"),
}
}

fn sync(config: &Config) {
println!("Syncing");

let owl_sync_script_path = Path::join(
&config.owl_path,
Path::new("common/scripts/owl-sync.sh"),
);

run_script(owl_sync_script_path);
}

#[derive(Debug, Deserialize)]
struct Setup {
name: String,
Expand All @@ -189,8 +183,9 @@ impl Setup {
}
}

fn run_script(script_path: &str) {
println!("Running script: {}", script_path);
fn run_script(script_path: PathBuf) {
let script_path = script_path.canonicalize().expect("Failed to canonicalize path");
println!("Running script: {}", script_path.display());

let mut cmd = Command::new("bash");
cmd.arg("-c").arg(script_path);
Expand Down Expand Up @@ -230,41 +225,39 @@ fn run_script(script_path: &str) {
}

fn run_setup_script(setup: &Setup) {
let owl_path = get_config().owl_path;

let config = get_config();
// print actions to user and have them select one
if setup.actions.is_empty() {
println!("No actions to run for {}", setup.name.green());
return;
}

println!("Select an action to run: ");
for (i, action) in setup.actions.iter().enumerate() {
println!("{}) {}", i, action);
}

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap().to_string();
let index: usize = input.trim().parse().unwrap();
let script_path = match setup.actions.len() {
1 => setup.actions[0].clone(),
_ => {
println!("Select an action to run: ");
for (i, action) in setup.actions.iter().enumerate() {
println!("{}) {}", i, action);
}
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap().to_string();
let index: usize = input.trim().parse().unwrap();

// this is relative to the setup directory
let action_path = setup.actions[index].clone();
// this is relative to the setup directory
setup.actions[index].clone()
}
};

let path_parts = [
Path::new(&owl_path),
Path::new(&config.owl_path),
Path::new("setups"),
Path::new(&setup.name),
Path::new(&action_path),
Path::new(&script_path),
];

let full_action_path = path_parts.iter().fold(PathBuf::new(), |acc, &part| acc.join(part));

// normalize the path
let full_action_path = full_action_path.canonicalize().expect("Failed to canonicalize path");

let cmd_str = full_action_path.to_str().expect("Failed to convert path to string");

run_script(cmd_str);
run_script(full_action_path);
}

fn run_setup_link(setup: &Setup) {
Expand Down Expand Up @@ -368,6 +361,5 @@ fn run_setup(setup_name: &str) {
}

fn run_update() {
let update_script_path = shellexpand::tilde("~/owl/setups/owl.sh").into_owned();
run_script(&update_script_path);
run_setup("owl");
}

0 comments on commit b5332a7

Please sign in to comment.