diff options
Diffstat (limited to '')
17 files changed, 568 insertions, 167 deletions
diff --git a/pkgs/by-name/lf/lf-make-map/Cargo.lock b/pkgs/by-name/lf/lf-make-map/Cargo.lock index 3f959f3b..c6a44974 100644 --- a/pkgs/by-name/lf/lf-make-map/Cargo.lock +++ b/pkgs/by-name/lf/lf-make-map/Cargo.lock @@ -78,21 +78,27 @@ checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "bitflags" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a" [[package]] name = "bumpalo" -version = "3.20.2" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" [[package]] name = "cc" -version = "1.2.60" +version = "1.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" +checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" dependencies = [ "find-msvc-tools", "shlex", @@ -119,9 +125,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.6.0" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" dependencies = [ "clap_builder", "clap_derive", @@ -141,9 +147,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.6.0" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" dependencies = [ "heck", "proc-macro2", @@ -170,12 +176,70 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags", + "document-features", + "mio", + "parking_lot", + "rustix", + "signal-hook", + "signal-hook-mio", +] + +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -230,10 +294,12 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "js-sys" -version = "0.3.95" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" dependencies = [ + "cfg-if", + "futures-util", "once_cell", "wasm-bindgen", ] @@ -253,6 +319,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "crossterm", "keymaps", "log", "stderrlog", @@ -261,15 +328,48 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.185" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litrs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" + +[[package]] +name = "lock_api" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] [[package]] name = "log" -version = "0.4.29" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +checksum = "113b30b4cd05f7c06868fdb2854f66a7b9fece9a48425351cd532e810d74024f" + +[[package]] +name = "mio" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] [[package]] name = "num-traits" @@ -293,6 +393,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] name = "proc-macro2" version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -311,6 +440,28 @@ dependencies = [ ] [[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] name = "rustversion" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -326,10 +477,59 @@ dependencies = [ ] [[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] name = "shlex" -version = "1.3.0" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75a19a7a740b25bc7944bdee6172368f988763b744e3d4dfe753f6b4ece40cc" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "stderrlog" @@ -422,10 +622,16 @@ dependencies = [ ] [[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] name = "wasm-bindgen" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" dependencies = [ "cfg-if", "once_cell", @@ -436,9 +642,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -446,9 +652,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" dependencies = [ "bumpalo", "proc-macro2", @@ -459,9 +665,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.118" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" dependencies = [ "unicode-ident", ] diff --git a/pkgs/by-name/lf/lf-make-map/Cargo.toml b/pkgs/by-name/lf/lf-make-map/Cargo.toml index 63d6287e..272e62b9 100644 --- a/pkgs/by-name/lf/lf-make-map/Cargo.toml +++ b/pkgs/by-name/lf/lf-make-map/Cargo.toml @@ -18,8 +18,9 @@ edition = "2024" [dependencies] anyhow = "1.0.102" -clap = { version = "4.6.0", features = ["derive", "env"] } +clap = { version = "4.6.1", features = ["derive", "env"] } +crossterm = {version = "0.29.0", default-features = false, features = ["events"]} keymaps = "1.2.0" -log = "0.4.29" +log = "0.4.31" stderrlog = "0.6.0" walkdir = "2.5.0" diff --git a/pkgs/by-name/lf/lf-make-map/flake.lock b/pkgs/by-name/lf/lf-make-map/flake.lock deleted file mode 100644 index 9aaa1a94..00000000 --- a/pkgs/by-name/lf/lf-make-map/flake.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1775888245, - "narHash": "sha256-nwASzrRDD1JBEu/o8ekKYEXm/oJW6EMCzCRdrwcLe90=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "13043924aaa7375ce482ebe2494338e058282925", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/pkgs/by-name/lf/lf-make-map/flake.lock.license b/pkgs/by-name/lf/lf-make-map/flake.lock.license deleted file mode 100644 index eae6a84c..00000000 --- a/pkgs/by-name/lf/lf-make-map/flake.lock.license +++ /dev/null @@ -1,9 +0,0 @@ -nixos-config - My current NixOS configuration - -Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> -SPDX-License-Identifier: GPL-3.0-or-later - -This file is part of my nixos-config. - -You should have received a copy of the License along with this program. -If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. diff --git a/pkgs/by-name/lf/lf-make-map/flake.nix b/pkgs/by-name/lf/lf-make-map/flake.nix index 8ce8ff0f..2d1e93a2 100644 --- a/pkgs/by-name/lf/lf-make-map/flake.nix +++ b/pkgs/by-name/lf/lf-make-map/flake.nix @@ -10,13 +10,13 @@ { description = "An automatic lf cd mapping generator"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - }; + inputs = {}; - outputs = {nixpkgs, ...}: let + outputs = {...}: let system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages."${system}"; + sources = import ../../../../npins/full.nix {}; + + pkgs = (sources.loadFlake "nixpkgs").legacyPackages."${system}"; in { devShells."${system}".default = pkgs.mkShell { packages = [ diff --git a/pkgs/by-name/lf/lf-make-map/src/cli.rs b/pkgs/by-name/lf/lf-make-map/src/cli.rs index 70746984..25a5a626 100644 --- a/pkgs/by-name/lf/lf-make-map/src/cli.rs +++ b/pkgs/by-name/lf/lf-make-map/src/cli.rs @@ -50,6 +50,12 @@ pub enum Command { #[command(flatten)] options: CommandOptions, }, + + /// Perform interactive selection, and then cd-there. + Interactive { + #[command(flatten)] + options: CommandOptions, + }, } #[derive(Debug, Parser)] diff --git a/pkgs/by-name/lf/lf-make-map/src/main.rs b/pkgs/by-name/lf/lf-make-map/src/main.rs index d5d934e1..1576c1dd 100644 --- a/pkgs/by-name/lf/lf-make-map/src/main.rs +++ b/pkgs/by-name/lf/lf-make-map/src/main.rs @@ -39,6 +39,7 @@ fn main() -> anyhow::Result<()> { let relevant_directories = match &args.command { Command::Visualize { options } => &options.relevant_directories, Command::Generate { options } => &options.relevant_directories, + Command::Interactive { options } => &options.relevant_directories, }; for dir in relevant_directories { @@ -99,6 +100,7 @@ fn main() -> anyhow::Result<()> { match args.command { Command::Visualize { .. } => println!("{}", mappings.0), Command::Generate { .. } => println!("{}", mappings.to_lf_mappings(args.home_name)), + Command::Interactive { .. } => mappings.interactive_start(args.home_name)?, } Ok(()) @@ -144,90 +146,3 @@ because it can't be turned to a string ) }) } - -// fn gen_lf_mappings(home_name: PathBuf, char_num: usize, rel_dirs: Vec<PathBuf>) { -// let mut mappings_vec = vec![]; -// let mut index_counter = 0; -// rel_dirs.iter().for_each(|rel_dir| { -// mappings_vec.push(vec![Mapping::new( -// &gen_hot_key(rel_dir, rel_dir, char_num), -// rel_dir, -// rel_dir, -// None, -// )]); -// get_dir(rel_dir.to_owned()).iter().for_each(|path| { -// mappings_vec[index_counter].push(Mapping::new( -// &gen_hot_key( -// path, -// path.parent().expect("All paths here should have parents"), -// char_num, -// ), -// path, -// &path -// .parent() -// .expect("All paths here should have parents") -// .to_owned(), -// None, -// )); -// }); -// index_counter += 1; -// }); -// print_mappings(&mappings_vec, home_name); -// mappings_vec -// .into_iter() -// .for_each(|rel_dir_mapping: Vec<Mapping>| { -// let mut hash_map = sort_mapping_by_hot_key(rel_dir_mapping.clone()); -// //dbg!(hash_map); -// hash_map.insert("gsi".to_owned(), vec![rel_dir_mapping[0].clone()]); -// }); -// } -// -// fn sort_mapping_by_hot_key(mut mappings: Vec<Mapping>) -> HashMap<String, Vec<Mapping>> { -// mappings.sort_by_key(|mapping| mapping.hot_key.clone()); -// -// let mut filtered_mappings: HashMap<String, Vec<Mapping>> = HashMap::new(); -// mappings.iter().for_each(|mapping| { -// filtered_mappings.insert(mapping.hot_key.clone(), vec![]); -// }); -// //dbg!(&mappings); -// -// let mut index_counter = 1; -// mappings.iter().for_each(|mapping| { -// if mappings.len() > index_counter { -// let next_mapping = &mappings[index_counter]; -// let vec = filtered_mappings -// .get_mut(&mapping.hot_key) -// .expect("This existst as it has been initialized"); -// -// if &next_mapping.hot_key == &mapping.hot_key { -// vec.push(mapping.clone()); -// vec.push(next_mapping.clone()); -// } else { -// vec.push(mapping.clone()); -// } -// -// let new_vec = vec.to_owned(); -// filtered_mappings.insert(mapping.hot_key.to_owned(), new_vec); -// } -// -// index_counter += 1; -// }); -// filtered_mappings -// } -// -// fn print_mappings(mappings: &Vec<Vec<Mapping>>, home_name: PathBuf) { -// for mapping in mappings { -// mapping.iter().for_each(|map| { -// println!( -// "{} = \"cd {}\";", -// map.hot_key, -// map.path -// .display() -// .to_string() -// .replace(home_name.to_str().expect("This should be UTF-8"), "~") -// ); -// }); -// -// println!("# -------------"); -// } -// } diff --git a/pkgs/by-name/lf/lf-make-map/src/mapping/interactive.rs b/pkgs/by-name/lf/lf-make-map/src/mapping/interactive.rs new file mode 100644 index 00000000..b8ac27d2 --- /dev/null +++ b/pkgs/by-name/lf/lf-make-map/src/mapping/interactive.rs @@ -0,0 +1,172 @@ +// nixos-config - My current NixOS configuration +// +// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +// SPDX-License-Identifier: GPL-3.0-or-later +// +// This file is part of my nixos-config. +// +// You should have received a copy of the License along with this program. +// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. + +use std::{io::stderr, path::PathBuf}; + +use anyhow::Result; +use crossterm::{ + cursor::{MoveToRow, MoveUp}, + event::{ + Event, KeyEventKind, KeyModifiers, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, + PushKeyboardEnhancementFlags, read, + }, + execute, + style::Print, + terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}, +}; + +use crate::mapping::map_key::MapKey; + +use super::MappingsTrie; + +enum Status { + Done(PathBuf), + Stop, +} + +impl MappingsTrie { + pub fn interactive_start(&self, home_path: PathBuf) -> Result<()> { + terminal::enable_raw_mode()?; + execute!( + stderr(), + EnterAlternateScreen, + PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES), + MoveToRow(0) + )?; + + let output = self.interactive_start_inner(home_path); + + execute!(stderr(), LeaveAlternateScreen, PopKeyboardEnhancementFlags)?; + terminal::disable_raw_mode()?; + + match output? { + Status::Done(path_buf) => { + println!("{}", path_buf.display()) + } + Status::Stop => (), + } + + Ok(()) + } + + fn interactive_start_inner(&self, home_path: PathBuf) -> Result<Status> { + macro_rules! done { + ($state:ident, $last_length:ident) => {{ + let value = match self.0.get(&$state).expect("Is some").value() { + Some(value) => value, + None => return Ok(Status::Stop), + }; + + let path = home_path.join(&value.path); + + terminal::disable_raw_mode()?; + execute!( + stderr(), + MoveUp($last_length as u16), + Clear(ClearType::FromCursorDown), + Print(format!("{}\n", path.display())) + )?; + terminal::enable_raw_mode()?; + + return Ok(Status::Done(path)); + }}; + } + + let mut state: Vec<MapKey> = vec![]; + let mut last_length: usize = 1; + while let (trie, matched) = self.0.try_get(&state) + && matched == state + { + if trie.value().is_some() { + done!(state, last_length); + } else { + if let Some(last) = state.last_mut() + && let Some(mlast) = matched.last() + { + last.resolution = mlast.resolution; + mlast.part_path.clone_into(&mut last.part_path); + } + } + + { + terminal::disable_raw_mode()?; + let string = trie.to_string(); + execute!( + stderr(), + MoveUp(last_length as u16), + Clear(ClearType::FromCursorDown), + Print(format!( + "Current state: {}\n", + self.current_progress(home_path.display().to_string(), &state) + )), + Print(&string) + )?; + last_length = string.lines().count() + 1; + terminal::enable_raw_mode()?; + } + + if let Event::Key(event) = read()? + && event.kind == KeyEventKind::Press + { + match event.code { + crossterm::event::KeyCode::Backspace => { + state.pop(); + } + crossterm::event::KeyCode::Enter => done!(state, last_length), + crossterm::event::KeyCode::Esc => break, + crossterm::event::KeyCode::Char(char) => { + if event.modifiers == KeyModifiers::CONTROL && char == 'c' { + break; + } else { + state.push(MapKey { + key: char, + resolution: 0, + part_path: String::new(), + }); + } + } + + crossterm::event::KeyCode::Left + | crossterm::event::KeyCode::Right + | crossterm::event::KeyCode::Up + | crossterm::event::KeyCode::Down + | crossterm::event::KeyCode::Home + | crossterm::event::KeyCode::End + | crossterm::event::KeyCode::PageUp + | crossterm::event::KeyCode::PageDown + | crossterm::event::KeyCode::Tab + | crossterm::event::KeyCode::BackTab + | crossterm::event::KeyCode::Delete + | crossterm::event::KeyCode::Insert + | crossterm::event::KeyCode::F(_) + | crossterm::event::KeyCode::Null + | crossterm::event::KeyCode::CapsLock + | crossterm::event::KeyCode::ScrollLock + | crossterm::event::KeyCode::NumLock + | crossterm::event::KeyCode::PrintScreen + | crossterm::event::KeyCode::Pause + | crossterm::event::KeyCode::Menu + | crossterm::event::KeyCode::KeypadBegin + | crossterm::event::KeyCode::Media(_) + | crossterm::event::KeyCode::Modifier(_) => (), + } + } + } + + Ok(Status::Stop) + } + + fn current_progress(&self, home_path: String, state: &[MapKey]) -> String { + state + .iter() + .map(|mk| &mk.part_path) + .fold(home_path, |acc, part| format!("{acc}/{part}")) + } +} diff --git a/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs b/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs index 5fd046fb..d90eb963 100644 --- a/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs +++ b/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs @@ -87,7 +87,6 @@ impl MapKey { generated_chars.extend( (0..(new_resolution - self.part_path.len())) - .into_iter() .map(|_| self.part_path.chars().last().expect("This will exists")), ); @@ -110,14 +109,14 @@ impl MapKey { } pub fn display(values: &[Self]) -> String { - values.iter().map(|value| value.key.clone()).collect() + values.iter().map(|value| value.key).collect() } fn part_path_to_key(part: &str, number_of_chars: usize) -> String { fn make(pat: char, part: &str, number_of_chars: usize) -> String { let mut acc = String::new(); - if !part.split(pat).all(|part| part.len() > 0) { + if !part.split(pat).all(|part| !part.is_empty()) { panic!( "\ Can't turn this path '{}' to a mapping. @@ -152,6 +151,13 @@ This should not happen, please report the bug!", make('_', part, number_of_chars) } else if part.contains('-') && !part.starts_with('-') && !part.ends_with('-') { make('-', part, number_of_chars) + } else if part.starts_with('.') { + // HACK: Special case for directories like ~/.config ~/.local and so on. + // We just drop the starting '.' and it's easier to type. <2026-06-02> + part.chars() + .skip(1) + .take(number_of_chars) + .collect::<String>() } else { part.chars().take(number_of_chars).collect::<String>() }; diff --git a/pkgs/by-name/lf/lf-make-map/src/mapping/mod.rs b/pkgs/by-name/lf/lf-make-map/src/mapping/mod.rs index 21392388..b733990e 100644 --- a/pkgs/by-name/lf/lf-make-map/src/mapping/mod.rs +++ b/pkgs/by-name/lf/lf-make-map/src/mapping/mod.rs @@ -14,6 +14,7 @@ use log::{Level, debug, log_enabled, trace}; use map_key::MapKey; pub mod lf_mapping; +pub mod interactive; pub mod map_key; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] diff --git a/pkgs/by-name/lf/lf-make-map/tests/base.sh b/pkgs/by-name/lf/lf-make-map/tests/base.sh index c7694985..d860cf84 100755 --- a/pkgs/by-name/lf/lf-make-map/tests/base.sh +++ b/pkgs/by-name/lf/lf-make-map/tests/base.sh @@ -18,7 +18,7 @@ execute_make_maps() { } fd . cases --max-depth 1 --type directory | while read -r case; do - echo "Executing '$case/test.sh'" + echo "Executing '${case}test.sh'" # shellcheck source=/dev/null LOCATION="$case/test.sh" . "$case/test.sh" diff --git a/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs/output.old b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs/output.old new file mode 100644 index 00000000..49307bc6 --- /dev/null +++ b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs/output.old @@ -0,0 +1,13 @@ +map gc. cd "/tmp/tmp.DfcgjemfCG/.config" +map gca. cd "/tmp/tmp.DfcgjemfCG/.config/apzu" +map gcl. cd "/tmp/tmp.DfcgjemfCG/.config/lahmu" +map gct. cd "/tmp/tmp.DfcgjemfCG/.config/tiamat" +map gd. cd "/tmp/tmp.DfcgjemfCG/documents" +map gda. cd "/tmp/tmp.DfcgjemfCG/documents/apzu" +map gdl. cd "/tmp/tmp.DfcgjemfCG/documents/lahmu" +map gdt. cd "/tmp/tmp.DfcgjemfCG/documents/tiamat" +map gl. cd "/tmp/tmp.DfcgjemfCG/.local" +map gln. cd "/tmp/tmp.DfcgjemfCG/.local/nvim" +map glsh. cd "/tmp/tmp.DfcgjemfCG/.local/share" +map glst. cd "/tmp/tmp.DfcgjemfCG/.local/state" + diff --git a/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs/test.sh b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs/test.sh new file mode 100755 index 00000000..d3df848c --- /dev/null +++ b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs/test.sh @@ -0,0 +1,49 @@ +#! /usr/bin/env sh + +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. + +mkFile() { + t="$1" + + mkdir --parents "$(dirname "$t")" + echo "TEST_FILE" >"$t" +} + +# We need to hard code this, so that our output matches the golden sample. +base="/tmp/tmp.DfcgjemfCG" +test="$(mktemp --directory -t lf_make_temp_test_XXXXX)" + +if [ -d "$base" ]; then + rm --recursive "$base" +fi +mkdir "$base" + +cleanup() { + rm --recursive "$base" "$test" +} +trap cleanup EXIT + +mkFile "$base/.local/share/file1.txt" +mkFile "$base/.local/state/file1.txt" +mkFile "$base/.local/nvim/log.LOG" +mkFile "$base/.local/.tog/TOG.LOG" + +mkFile "$base/.config/apzu/file2.txt" +mkFile "$base/.config/tiamat/file2.txt" +mkFile "$base/.config/lahmu/file2.txt" + +mkFile "$base/documents/apzu/file2.txt" +mkFile "$base/documents/tiamat/file2.txt" +mkFile "$base/documents/lahmu/file2.txt" + +execute_make_maps --home-name "$base" --depth 100 generate "$base/.local" "$base/.config" "$base/documents" >"$test/output.new" + +diff "$test/output.new" "$(dirname "$LOCATION")/output.old" diff --git a/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs_duplicates/output.old b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs_duplicates/output.old new file mode 100644 index 00000000..f7523ba3 --- /dev/null +++ b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs_duplicates/output.old @@ -0,0 +1,17 @@ +map gca. cd "/tmp/tmp.DfcgjemfCG/cats" +map gcaa. cd "/tmp/tmp.DfcgjemfCG/cats/apzu" +map gcal. cd "/tmp/tmp.DfcgjemfCG/cats/lahmu" +map gcat. cd "/tmp/tmp.DfcgjemfCG/cats/tiamat" +map gco. cd "/tmp/tmp.DfcgjemfCG/.config" +map gcoa. cd "/tmp/tmp.DfcgjemfCG/.config/apzu" +map gcol. cd "/tmp/tmp.DfcgjemfCG/.config/lahmu" +map gcot. cd "/tmp/tmp.DfcgjemfCG/.config/tiamat" +map gd. cd "/tmp/tmp.DfcgjemfCG/documents" +map gda. cd "/tmp/tmp.DfcgjemfCG/documents/apzu" +map gdl. cd "/tmp/tmp.DfcgjemfCG/documents/lahmu" +map gdt. cd "/tmp/tmp.DfcgjemfCG/documents/tiamat" +map gl. cd "/tmp/tmp.DfcgjemfCG/.local" +map gln. cd "/tmp/tmp.DfcgjemfCG/.local/nvim" +map glsh. cd "/tmp/tmp.DfcgjemfCG/.local/share" +map glst. cd "/tmp/tmp.DfcgjemfCG/.local/state" + diff --git a/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs_duplicates/test.sh b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs_duplicates/test.sh new file mode 100755 index 00000000..33447e54 --- /dev/null +++ b/pkgs/by-name/lf/lf-make-map/tests/cases/dot_dirs_duplicates/test.sh @@ -0,0 +1,53 @@ +#! /usr/bin/env sh + +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. + +mkFile() { + t="$1" + + mkdir --parents "$(dirname "$t")" + echo "TEST_FILE" >"$t" +} + +# We need to hard code this, so that our output matches the golden sample. +base="/tmp/tmp.DfcgjemfCG" +test="$(mktemp --directory -t lf_make_temp_test_XXXXX)" + +if [ -d "$base" ]; then + rm --recursive "$base" +fi +mkdir "$base" + +cleanup() { + rm --recursive "$base" "$test" +} +trap cleanup EXIT + +mkFile "$base/.local/share/file1.txt" +mkFile "$base/.local/state/file1.txt" +mkFile "$base/.local/nvim/log.LOG" +mkFile "$base/.local/.tog/TOG.LOG" + +mkFile "$base/.config/apzu/file2.txt" +mkFile "$base/.config/tiamat/file2.txt" +mkFile "$base/.config/lahmu/file2.txt" + +mkFile "$base/documents/apzu/file2.txt" +mkFile "$base/documents/tiamat/file2.txt" +mkFile "$base/documents/lahmu/file2.txt" + +mkFile "$base/cats/apzu/file2.txt" +mkFile "$base/cats/tiamat/file2.txt" +mkFile "$base/cats/lahmu/file2.txt" + +execute_make_maps --home-name "$base" --depth 100 generate "$base/.local" "$base/.config" "$base/documents" "$base/cats" >"$test/output.new" + +diff "$test/output.new" "$(dirname "$LOCATION")/output.old" diff --git a/pkgs/by-name/lf/lf-make-map/tests/cases/simple/test.sh b/pkgs/by-name/lf/lf-make-map/tests/cases/simple/test.sh index 22f97009..97ee0cb9 100755 --- a/pkgs/by-name/lf/lf-make-map/tests/cases/simple/test.sh +++ b/pkgs/by-name/lf/lf-make-map/tests/cases/simple/test.sh @@ -14,11 +14,9 @@ base="/tmp/tmp.DfcgjemfCG" test="$(mktemp --directory -t lf_make_temp_test_XXXXX)" -[ -d "$base" ] && { - echo "$base already exists!" - exit 1 -} - +if [ -d "$base" ]; then + rm --recursive "$base" +fi mkdir "$base" cleanup() { diff --git a/pkgs/by-name/lf/lf-make-map/update.sh b/pkgs/by-name/lf/lf-make-map/update.sh index 23d90a86..188771c4 100755 --- a/pkgs/by-name/lf/lf-make-map/update.sh +++ b/pkgs/by-name/lf/lf-make-map/update.sh @@ -10,5 +10,5 @@ # You should have received a copy of the License along with this program. # If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. -[ "$1" = "upgrade" ] && cargo upgrade -cargo update +[ "$1" = "upgrade" ] && cargo upgrade --incompatible allow --pinned allow --recursive true +cargo update --recursive |
