mirror of
https://forge.katzen.cafe/schrottkatze/nix-configs.git
synced 2026-09-02 02:47:29 +02:00
aaa
This commit is contained in:
parent
393a0a3ea5
commit
43b0c0d9b1
10 changed files with 20 additions and 2229 deletions
2053
Cargo.lock
generated
2053
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
1
justfile
1
justfile
|
|
@ -6,6 +6,7 @@ init-live:
|
|||
test: init-live
|
||||
sudo nixos-rebuild test --flake . --log-format multiline
|
||||
|
||||
buid: build
|
||||
build: init-live
|
||||
sudo nixos-rebuild switch --flake . --log-format multiline
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ let
|
|||
# stolen: https://github.com/MultisampledNight/core/blob/678f176cb24f5dc4b5dc629cfd3e643487be01bb/system/packages/layaway/default.nix#L7-L25
|
||||
layaway = pkgs.rustPlatform.buildRustPackage rec {
|
||||
pname = "layaway";
|
||||
version = "0.2.0";
|
||||
version = "0.2.1";
|
||||
|
||||
src = pkgs.fetchFromGitHub {
|
||||
src = pkgs.fetchFromCodeberg {
|
||||
owner = "MultisampledNight";
|
||||
repo = pname;
|
||||
rev = "v${version}";
|
||||
rev = "e3c25e8c887c61f22b7bf321d71f1d74f8ec960f";
|
||||
hash = "sha256-SzAuVFEy56svasO3+1p6ysBRrIQd0UZX++/P4ZuwWm0=";
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -38,5 +38,5 @@
|
|||
};
|
||||
|
||||
# TODO: Proper switch
|
||||
users.defaultUserShell = pkgs.elvish;
|
||||
users.defaultUserShell = pkgs.nushell;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs, ... }:
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
# Needed for nu_scripts background_task
|
||||
services.pueue = {
|
||||
|
|
@ -17,8 +17,7 @@
|
|||
target = ".config/nushell/shell-startup.nu";
|
||||
};
|
||||
programs.nushell = {
|
||||
enable = false;
|
||||
# package = config.users.defaultUserShell;
|
||||
enable = true;
|
||||
configFile.source = ./nu/config.nu;
|
||||
envFile.source = ./nu/env.nu;
|
||||
extraConfig = ''
|
||||
|
|
|
|||
|
|
@ -1,8 +1,17 @@
|
|||
alias gnix = cd ~/nix-configs/;
|
||||
alias grepo = cd ~/Documents/repos/;
|
||||
|
||||
alias wh = wormhole-rs;
|
||||
|
||||
alias b = broot;
|
||||
|
||||
alias gg = gitui;
|
||||
alias ga = git add;
|
||||
alias gc = git commit;
|
||||
alias gca = git commit --all;
|
||||
alias gp = git push;
|
||||
alias gl = git pull;
|
||||
alias gs = git status;
|
||||
alias clip = xclip -selection c;
|
||||
|
||||
alias cr = cargo run;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ def glog [
|
|||
}
|
||||
|
||||
# open typst IDE ish setup
|
||||
def typed [
|
||||
def typed_legacy [
|
||||
name: string
|
||||
] {
|
||||
const DEFAULT_TYPST_FILE = "#import \"@local/typst-configs:0.1.0\": generic, sf;\n#show: generic.with();"
|
||||
|
|
@ -44,7 +44,7 @@ def typed [
|
|||
} else if ($"($name).pdf" | path exists) {
|
||||
typst compile $"($name).typ"
|
||||
}
|
||||
mprocs --names Editor,Viewer,Notify $"hx '($name).typ'" $"while true; do mupdf-x11 '($name).pdf' && break; done" $"bash -c 'while inotifywait -e modify \'($name).pdf\' ; do pkill -HUP mupdf; done'"
|
||||
mprocs --names Editor,Viewer,Notify $"hx '($name).typ'" $"while true; do mupdf '($name).pdf' && break; done" $"bash -c 'while inotifywait -e modify \'($name).pdf\' ; do pkill -HUP mupdf; done'"
|
||||
}
|
||||
|
||||
# figure out when the next event is
|
||||
|
|
@ -93,7 +93,7 @@ def "dp ccchh" [] {
|
|||
}
|
||||
|
||||
def "dp gay" [] {
|
||||
layaway "dp3 + edp1/bottom,center + dp5/right,top"
|
||||
layaway "dp3 + edp1/bottom,center + dp5/left,top"
|
||||
# manual fix for lack of frequency in layaway, else monitor just turns off
|
||||
swaymsg "output DP-3 position 0 0 scale 1 transform normal resolution 1920x1080@60Hz"
|
||||
bars "LEN G27c-10"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
chrono = "0.4.38"
|
||||
clap = { version = "4.5.4", features = ["derive", "env"] }
|
||||
clap = { workspace = true, features = ["derive", "env"] }
|
||||
owo-colors = "4.0.0"
|
||||
temp-file = "0.1.8"
|
||||
termsize = "0.1.9"
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "typed"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap.workspace = true
|
||||
crossterm = "0.29.0"
|
||||
notify = "8"
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
#![feature(lock_value_accessors)]
|
||||
use std::{
|
||||
io,
|
||||
path::Path,
|
||||
process::{Command, exit},
|
||||
sync::{
|
||||
Arc, Condvar, Mutex,
|
||||
atomic::{AtomicBool, AtomicU32, Ordering},
|
||||
mpsc::channel,
|
||||
},
|
||||
thread::{self},
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use notify::{Event, RecursiveMode, Watcher};
|
||||
|
||||
use crate::cli::Cli;
|
||||
|
||||
mod cli {
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Cli {
|
||||
pub path: String,
|
||||
#[arg(short, long, env)]
|
||||
pub editor: Option<String>,
|
||||
#[arg(short, long, env)]
|
||||
pub viewer: Option<String>,
|
||||
#[arg(short, long)]
|
||||
pub no_edit: bool,
|
||||
}
|
||||
}
|
||||
|
||||
// TODOs:
|
||||
// - create empty file if file doesnt exist
|
||||
// - compile to pdf
|
||||
// - always ensure pdf exists
|
||||
// - delete pdf by default on program close
|
||||
fn main() -> std::io::Result<()> {
|
||||
let args = Cli::parse();
|
||||
|
||||
let pdf_path = format!("{}.pdf", args.path);
|
||||
let typ_path = format!("{}.typ", args.path);
|
||||
|
||||
let mupdf_pid = Arc::new(AtomicU32::new(0));
|
||||
let editor_pid = Arc::new(AtomicU32::new(0));
|
||||
let pair = Arc::new((Mutex::new(false), Condvar::new()));
|
||||
|
||||
let pdf_path_ = pdf_path.clone();
|
||||
let mupdf_pid_ = Arc::clone(&mupdf_pid);
|
||||
let viewer = args.viewer.unwrap_or("mupdf-x11".to_string());
|
||||
|
||||
let pair_mupdf = pair.clone();
|
||||
thread::spawn(move || {
|
||||
let mut mupdf = Command::new(&viewer);
|
||||
mupdf.arg(&pdf_path_);
|
||||
|
||||
loop {
|
||||
let Ok(mut mupdf) = mupdf.spawn() else {
|
||||
break;
|
||||
};
|
||||
|
||||
mupdf_pid_.store(mupdf.id(), Ordering::Relaxed);
|
||||
let wait_res = mupdf.wait();
|
||||
if let Ok(status) = wait_res
|
||||
&& status.success()
|
||||
{
|
||||
// we exited!
|
||||
crossterm::terminal::disable_raw_mode().unwrap();
|
||||
// we can unwrap here, because crashing doesnt matter when we're exiting anyway, it'll just be less clean
|
||||
pair_mupdf.0.set(true).unwrap();
|
||||
pair_mupdf.1.notify_all();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let pdf_path_ = pdf_path.clone();
|
||||
let mupdf_pid_ = Arc::clone(&mupdf_pid);
|
||||
thread::spawn(move || {
|
||||
let (tx, rx) = channel::<notify::Result<Event>>();
|
||||
let mut watcher = notify::recommended_watcher(tx).unwrap();
|
||||
|
||||
let _ = watcher.watch(Path::new(&pdf_path_), RecursiveMode::NonRecursive);
|
||||
|
||||
loop {
|
||||
let p = rx.recv();
|
||||
|
||||
match p {
|
||||
Ok(Ok(e)) if e.kind.is_modify() || e.kind.is_create() => {
|
||||
let mupdf_pid = mupdf_pid_.load(Ordering::Relaxed);
|
||||
if mupdf_pid != 0 {
|
||||
let mut kill = Command::new("kill");
|
||||
|
||||
let _ = kill.arg("-1").arg(mupdf_pid.to_string()).spawn();
|
||||
}
|
||||
}
|
||||
Ok(Ok(e)) if e.kind.is_remove() => {
|
||||
let _ = watcher.watch(Path::new(&pdf_path_), RecursiveMode::NonRecursive);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// the editor?
|
||||
let pair_editor = pair.clone();
|
||||
let editor_pid_ = editor_pid.clone();
|
||||
if let Some(editor) = args.editor
|
||||
&& !args.no_edit
|
||||
{
|
||||
thread::spawn(move || {
|
||||
let Ok(mut editor) = Command::new(editor).arg(&typ_path).spawn() else {
|
||||
pair_editor.0.set(true).unwrap();
|
||||
pair_editor.1.notify_all();
|
||||
return;
|
||||
};
|
||||
editor_pid_.store(editor.id(), Ordering::Relaxed);
|
||||
let _ = editor.wait();
|
||||
// we know the editor exited here!
|
||||
pair_editor.0.set(true).unwrap();
|
||||
pair_editor.1.notify_all();
|
||||
});
|
||||
}
|
||||
|
||||
let (done, cvar) = &*pair;
|
||||
// result doesnt matter.
|
||||
// poisoned? we exit
|
||||
// done? we exit
|
||||
// we'll complain about the poison tho
|
||||
let res = done
|
||||
.lock()
|
||||
.and_then(|lock| cvar.wait_while(lock, |done| !*done));
|
||||
|
||||
let mupdf_pid = mupdf_pid.load(Ordering::Relaxed);
|
||||
let mupdf_killer = Command::new("kill")
|
||||
.arg("-9")
|
||||
.arg(mupdf_pid.to_string())
|
||||
.spawn();
|
||||
let editor_pid = editor_pid.load(Ordering::Relaxed);
|
||||
if editor_pid != 0 {
|
||||
let editor_killer = Command::new("kill")
|
||||
.arg("-9")
|
||||
.arg(editor_pid.to_string())
|
||||
.spawn();
|
||||
let _ = editor_killer.unwrap().wait();
|
||||
}
|
||||
let _ = mupdf_killer.unwrap().wait();
|
||||
|
||||
println!("goodbye :3");
|
||||
if res.is_err() {
|
||||
println!("the waiter was poisoned btw :(")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Reference in a new issue