2023-03-20 05:14:45 +00:00
|
|
|
#!/usr/bin/env rust-script
|
|
|
|
//! ```cargo
|
|
|
|
//! [dependencies]
|
Misc: SSH, Vim, Helix, Ubuntu, setup, shells, ...
- SSH config: disable password and send COLORTERM
- Vim: use <space>u instead of <space>w
- Helix:
- Update for bug fixes after 23.10
- Install bash completions, desktop file, and icon
- Fix bufferline and inlay hints color
- Reenable auto pairs since smart tabs is a thing now
- Ubuntu:
- Update to 23.10
- Change naming convention
- Add podman and qemu-user-static
- Setup:
- Update install and swap config
- Add fish, Pods, Steam
- Fix CJK font config path
- Remove Firefox Wayland override now that it's the default
- Shells: configure fish
- Manual:
- Configure starship
- Use cargo locked install
- Remove sparse protocol config now that it's the default
- Fix failure when fish config directory is not found
- tmux: fix truecolor support for Alacritty
2023-09-27 23:48:38 +00:00
|
|
|
//! anyhow = "1.0.75"
|
|
|
|
//! dirs = "5.0.1"
|
2023-03-20 05:14:45 +00:00
|
|
|
//! ```
|
|
|
|
|
2023-04-02 06:12:02 +00:00
|
|
|
use anyhow::{anyhow, bail, Context};
|
2023-03-20 05:14:45 +00:00
|
|
|
|
|
|
|
use std::{
|
|
|
|
fs::{self, File},
|
2023-04-02 06:12:02 +00:00
|
|
|
io::{BufRead, BufReader, ErrorKind},
|
2023-03-20 05:14:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const ENV: &str = r#". "$HOME/.cargo/env""#;
|
Misc: SSH, Vim, Helix, Ubuntu, setup, shells, ...
- SSH config: disable password and send COLORTERM
- Vim: use <space>u instead of <space>w
- Helix:
- Update for bug fixes after 23.10
- Install bash completions, desktop file, and icon
- Fix bufferline and inlay hints color
- Reenable auto pairs since smart tabs is a thing now
- Ubuntu:
- Update to 23.10
- Change naming convention
- Add podman and qemu-user-static
- Setup:
- Update install and swap config
- Add fish, Pods, Steam
- Fix CJK font config path
- Remove Firefox Wayland override now that it's the default
- Shells: configure fish
- Manual:
- Configure starship
- Use cargo locked install
- Remove sparse protocol config now that it's the default
- Fix failure when fish config directory is not found
- tmux: fix truecolor support for Alacritty
2023-09-27 23:48:38 +00:00
|
|
|
// until the release of https://github.com/rust-lang/rustup/pull/3506/files
|
Misc: setup, fish, auto, helix, starship, system
- Setup: add Fedora guides, Signal, Dynamic Desktop, and Flatseal
- Shells: fix $() on older fish versions and unalias batcat on Fedora
- Auto:
- Detect git dependency
- Add .clang-format for C/C++ family
- Add full-setup script
- Helix: update to 24.03, add text width, rulers, and fix reflow
- Rust: fix fish env
- Starship: fix config path
- System: rename mac fnmode scripts and update sshd_config
2024-02-04 23:35:36 +00:00
|
|
|
const ENV_FISH: &str = r#"set -x PATH "$HOME/.cargo/bin" $PATH"#;
|
2023-03-20 05:14:45 +00:00
|
|
|
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
|
|
let home = dirs::home_dir().context("can't find home directory")?;
|
|
|
|
let mut login_path = home.clone();
|
|
|
|
login_path.push(".bash_login");
|
2023-04-02 06:12:02 +00:00
|
|
|
let login = match File::open(&login_path) {
|
|
|
|
Ok(file) => {
|
|
|
|
let login = BufReader::new(file);
|
|
|
|
let mut skip = false;
|
|
|
|
let mut new_login = String::new();
|
|
|
|
let mut removed = false;
|
|
|
|
let mut added = false;
|
|
|
|
for line in login.lines() {
|
|
|
|
let line = line.context("failed to read line in ~/.bash_login")?;
|
|
|
|
if line.is_empty() && skip {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
skip = line.is_empty();
|
|
|
|
if line == ENV {
|
|
|
|
removed = true;
|
|
|
|
} else {
|
|
|
|
new_login.push_str(&line);
|
|
|
|
new_login.push('\n');
|
|
|
|
}
|
|
|
|
if line == "# custom" && !added {
|
|
|
|
added = true;
|
|
|
|
new_login.push('\n');
|
|
|
|
new_login.push_str(ENV);
|
|
|
|
new_login.push_str("\n\n");
|
|
|
|
skip = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if removed && !added {
|
|
|
|
bail!("would remove \"{ENV}\" and not add it back");
|
|
|
|
}
|
|
|
|
new_login.trim().to_owned() + "\n"
|
2023-03-20 05:14:45 +00:00
|
|
|
}
|
2023-04-02 06:12:02 +00:00
|
|
|
Err(e) if e.kind() == ErrorKind::NotFound => format!("# custom\n\n{ENV}\n"),
|
|
|
|
Err(e) => bail!(anyhow!(e).context("failed to read ~/.bash_login")),
|
|
|
|
};
|
|
|
|
fs::write(login_path, &login).context("failed to write new ~/.bash_login")?;
|
2023-03-20 05:14:45 +00:00
|
|
|
|
2023-04-02 06:12:02 +00:00
|
|
|
let mut bashrc_path = home.clone();
|
|
|
|
bashrc_path.push(".bashrc");
|
|
|
|
let bashrc = match File::open(&bashrc_path) {
|
|
|
|
Ok(file) => {
|
|
|
|
let bashrc = BufReader::new(file);
|
|
|
|
let mut skip = false;
|
|
|
|
let mut new_bashrc = String::new();
|
|
|
|
for line in bashrc.lines() {
|
|
|
|
let line = line.context("failed to read line in ~/.bashrc")?;
|
|
|
|
if line.is_empty() && skip {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
skip = line.is_empty();
|
|
|
|
if line != ENV {
|
|
|
|
new_bashrc.push_str(&line);
|
|
|
|
new_bashrc.push('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new_bashrc.trim().to_owned() + "\n"
|
2023-03-20 05:14:45 +00:00
|
|
|
}
|
2023-04-02 06:12:02 +00:00
|
|
|
Err(e) if e.kind() == ErrorKind::NotFound => "# custom\n".to_owned(),
|
|
|
|
Err(e) => bail!(anyhow!(e).context("failed to read ~/.bashrc")),
|
|
|
|
};
|
|
|
|
fs::write(bashrc_path, &bashrc).context("failed to write new ~/.bashrc")?;
|
2023-03-20 05:14:45 +00:00
|
|
|
|
Misc: SSH, Vim, Helix, Ubuntu, setup, shells, ...
- SSH config: disable password and send COLORTERM
- Vim: use <space>u instead of <space>w
- Helix:
- Update for bug fixes after 23.10
- Install bash completions, desktop file, and icon
- Fix bufferline and inlay hints color
- Reenable auto pairs since smart tabs is a thing now
- Ubuntu:
- Update to 23.10
- Change naming convention
- Add podman and qemu-user-static
- Setup:
- Update install and swap config
- Add fish, Pods, Steam
- Fix CJK font config path
- Remove Firefox Wayland override now that it's the default
- Shells: configure fish
- Manual:
- Configure starship
- Use cargo locked install
- Remove sparse protocol config now that it's the default
- Fix failure when fish config directory is not found
- tmux: fix truecolor support for Alacritty
2023-09-27 23:48:38 +00:00
|
|
|
let mut config_fish_path = dirs::config_dir().context("can't find config directory")?;
|
|
|
|
config_fish_path.push("fish");
|
|
|
|
fs::create_dir_all(&config_fish_path)?;
|
|
|
|
config_fish_path.push("config.fish");
|
|
|
|
let config_fish = match File::open(&config_fish_path) {
|
|
|
|
Ok(file) => {
|
|
|
|
let config_fish = BufReader::new(file);
|
|
|
|
let mut skip = false;
|
|
|
|
let mut new_config_fish = String::new();
|
|
|
|
for line in config_fish.lines() {
|
|
|
|
let line = line.context("failed to read line in config.fish")?;
|
|
|
|
if line.is_empty() && skip {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
skip = line.is_empty();
|
|
|
|
if line != ENV_FISH {
|
|
|
|
new_config_fish.push_str(&line);
|
|
|
|
new_config_fish.push('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new_config_fish.trim().to_owned() + "\n"
|
|
|
|
}
|
|
|
|
Err(e) if e.kind() == ErrorKind::NotFound => String::new(),
|
|
|
|
Err(e) => bail!(anyhow!(e).context("failed to read config.fish")),
|
|
|
|
};
|
|
|
|
fs::write(config_fish_path, &config_fish).context("failed to write new config.fish")?;
|
|
|
|
|
2023-03-20 05:14:45 +00:00
|
|
|
Ok(())
|
|
|
|
}
|