Misc: helix and ubuntu-setup

- Use shallow clone to install Helix
- Fix rust-configure panics when bash dotfiles don't exist
- Use tabs for Rust scripts
- Fix Helix version to 23.03
- Helix force install
- Helix LSP inlay hints key
- Other Ubuntu packages
This commit is contained in:
DuckDuckWhale 2023-04-01 23:12:02 -07:00
parent 5531ddb2d1
commit 38ec154801
Signed by: DuckDuckWhale
GPG Key ID: E4B9FC170FFD71CE
4 changed files with 88 additions and 47 deletions

View File

@ -1,4 +1,7 @@
#!/bin/sh -e
if [ "$1" = '-f' ]; then
force=true
fi
if ! command -v cargo > /dev/null; then
echo "Error: cargo not found"
exit 1
@ -7,7 +10,16 @@ if ! command -v c++ > /dev/null; then
echo "Error: c++ not found"
exit 1
fi
git clone https://github.com/helix-editor/helix helix-git
if [ -d ~/.config/helix ]; then
if [ "$force" = true ]; then
rm -rf ~/.config/helix
else
echo "Error: helix config files already exist; use -f to force erase and reinstall"
exit 1
fi
fi
rm -rf helix-git
git clone --depth 1 --branch 23.03 https://github.com/helix-editor/helix helix-git
cd helix-git
cargo install --locked --path helix-term
mkdir -p ~/.config/helix
@ -25,10 +37,13 @@ rulers = [101]
[editor.statusline]
left = ["mode", "spinner", "file-name"]
center = ["position-percentage"]
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending"]
right = [
"version-control", "diagnostics", "selections", "position", "file-encoding", "file-line-ending"
]
[keys.normal]
space.z = ":reflow 100"
space.i = ":toggle lsp.display-inlay-hints"
[editor.soft-wrap]
enable = true
@ -63,3 +78,4 @@ file-types = ["md"]
scope = "source.markdown"
roots = []
EOF
rm -rf helix-git

View File

@ -21,6 +21,10 @@ cat >> ~/.cargo/config.toml << 'EOF'
[registries.crates-io]
protocol = "sparse"
EOF
mkdir -p ~/.config/rustfmt
cat >> ~/.config/rustfmt/rustfmt.toml << 'EOF'
hard_tabs = true
EOF
mkdir -p ~/.local/bin
cat >> ~/.local/bin/rust-analyzer << 'EOF'
#!/bin/sh

View File

@ -5,11 +5,11 @@
//! dirs = "4.0.0"
//! ```
use anyhow::Context;
use anyhow::{anyhow, bail, Context};
use std::{
fs::{self, File},
io::{BufRead, BufReader},
io::{BufRead, BufReader, ErrorKind},
};
const ENV: &str = r#". "$HOME/.cargo/env""#;
@ -18,47 +18,67 @@ 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");
let login = BufReader::new(File::open(&login_path).context("failed to read ~/.bash_login")?);
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"
}
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")?;
let mut bashrc_path = home.clone();
bashrc_path.push(".bashrc");
let bashrc = BufReader::new(File::open(&bashrc_path).context("failed to read ~/.bashrc")?);
let mut empty = 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() && empty {
continue;
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"
}
empty = line.is_empty();
if line != ENV {
new_bashrc.push_str(&line);
new_bashrc.push('\n');
}
}
let mut empty = false;
let mut new_login = String::new();
for line in login.lines() {
let line = line.context("failed to read line in ~/.bash_login")?;
if line.is_empty() && empty {
continue;
}
empty = line.is_empty();
if line != ENV {
new_login.push_str(&line);
new_login.push('\n');
}
if line == "# custom" {
new_login.push('\n');
new_login.push_str(ENV);
new_login.push_str("\n\n");
empty = true;
}
}
fs::write(bashrc_path, &new_bashrc).context("failed to write new .bashrc")?;
fs::write(login_path, &new_login).context("failed to write new .bash_login")?;
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")?;
Ok(())
}

View File

@ -7,11 +7,12 @@ Here's my personal Ubuntu 22.10 setup. (Make sure to enable Wayland on Nvidia!)
- `sudo apt install curl ddcutil deja-dup earlyoom endeavour ffmpeg flatpak git gnome-boxes \
gnome-clocks gnome-software-plugin-flatpak gnome-sound-recorder gnome-weather goldendict \
gparted keepassxc mpv needrestart obs-studio ripgrep shadowsocks-libev sshfs synaptic tmux \
trash-cli ufw vim-gtk3 vlc wl-clipboard`
trash-cli ufw vim-gtk3 vlc wl-clipboard linux-tools-generic`
- Optional:
- `sudo apt install gnome-firmware gnome-games gnome-nettool gnome-packagekit gnome-passwordsafe \
gnome-shell-pomodoro gnome-usage gthumb mkvtoolnix-gui openjdk-17-jdk pulseeffectsqpdf ranger \
syncplay virtualbox-qt heif-gdk-pixbuf heif-thumbnailer asciinema`
- `sudo apt install arp-scan asciinema bookworm foliate gimp gnome-firmware gnome-games \
gnome-nettool gnome-packagekit gnome-passwordsafe gnome-shell-pomodoro gnome-usage gthumb \
heif-gdk-pixbuf heif-thumbnailer mkvtoolnix-gui openjdk-17-jdk pulseeffectsqpdf ranger \
syncplay virtualbox-qt`
- Remove all snaps:
- ```
# if this command fails, do the following then try again:
@ -80,6 +81,7 @@ Here's my personal Ubuntu 22.10 setup. (Make sure to enable Wayland on Nvidia!)
- `sudo apt install gnome-tweaks`
- Extensions
- `sudo apt install gnome-shell-extensions`
- Go to settings -> `Region & Language` and install `Chinese (simplified)`.
- GSConnect
- `sudo apt install gnome-shell-extension-gsconnect`
- UFW:
@ -92,7 +94,6 @@ Here's my personal Ubuntu 22.10 setup. (Make sure to enable Wayland on Nvidia!)
- Use Wayland for correct fractional scaling:
`sudo flatpak override --socket=wayland --env=MOZ_ENABLE_WAYLAND=1
org.mozilla.firefox`
- Go to settings -> `Region & Language` and install `Chinese (simplified)`.
- OBS Studio
- `$ sudo apt install qtwayland5`
- On Ubuntu <22.10, in `/usr/share/applications/com.obsproject.Studio.desktop`, replace