diff options
Diffstat (limited to '')
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/.envrc | 11 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/.gitignore | 6 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/Cargo.lock | 632 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/Cargo.toml | 16 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/README.md | 12 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/default.nix | 12 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/flake.lock | 147 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/flake.nix | 125 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/lf_make_map.nix | 12 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/cli.rs | 28 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs | 45 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs.old | 165 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/main.rs | 116 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/mapping/error.rs | 7 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree.rs | 103 | ||||
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/mapping/mod.rs | 122 | ||||
-rwxr-xr-x | sys/nixpkgs/pkgs/lf-make-map/update.sh | 5 |
17 files changed, 1564 insertions, 0 deletions
diff --git a/sys/nixpkgs/pkgs/lf-make-map/.envrc b/sys/nixpkgs/pkgs/lf-make-map/.envrc new file mode 100644 index 00000000..c8c56659 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/.envrc @@ -0,0 +1,11 @@ +use flake || use nix +watch_file flake.nix + +PATH_add ./target/debug +PATH_add ./target/release +PATH_add ./scripts + +if on_git_branch; then + echo && git status --short --branch && + echo && git fetch --verbose +fi diff --git a/sys/nixpkgs/pkgs/lf-make-map/.gitignore b/sys/nixpkgs/pkgs/lf-make-map/.gitignore new file mode 100644 index 00000000..cb87f36f --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/.gitignore @@ -0,0 +1,6 @@ +# build +/target +/result + +# dev env +.direnv diff --git a/sys/nixpkgs/pkgs/lf-make-map/Cargo.lock b/sys/nixpkgs/pkgs/lf-make-map/Cargo.lock new file mode 100644 index 00000000..d9fff1ac --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/Cargo.lock @@ -0,0 +1,632 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cc" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lf-make-map" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "log", + "stderrlog", + "thiserror", + "tokio", + "walkdir", +] + +[[package]] +name = "libc" +version = "0.2.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "stderrlog" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c910772f992ab17d32d6760e167d2353f4130ed50e796752689556af07dc6b" +dependencies = [ + "chrono", + "is-terminal", + "log", + "termcolor", + "thread_local", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tokio" +version = "1.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +dependencies = [ + "backtrace", + "num_cpus", + "pin-project-lite", + "tokio-macros", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/sys/nixpkgs/pkgs/lf-make-map/Cargo.toml b/sys/nixpkgs/pkgs/lf-make-map/Cargo.toml new file mode 100644 index 00000000..d11ca927 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "lf-make-map" +description = "An automatic lf cd mapping generator" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.82" +clap = { version = "4.5.4", features = ["derive", "env"] } +log = "0.4.21" +stderrlog = "0.6.0" +thiserror = "1.0.59" +tokio = { version = "1.37.0", features = ["fs", "macros", "rt-multi-thread"] } +walkdir = "2.5.0" diff --git a/sys/nixpkgs/pkgs/lf-make-map/README.md b/sys/nixpkgs/pkgs/lf-make-map/README.md new file mode 100644 index 00000000..0c57cede --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/README.md @@ -0,0 +1,12 @@ +# Lf make map + +> An automatic lf cd mapping generator + +Some text about the project. + +## Licence + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. diff --git a/sys/nixpkgs/pkgs/lf-make-map/default.nix b/sys/nixpkgs/pkgs/lf-make-map/default.nix new file mode 100644 index 00000000..8ff4c624 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/default.nix @@ -0,0 +1,12 @@ +[ + ( + final: prev: { + lf-make-map = import ./lf_make_map.nix { + inherit + (prev) + rustPlatform + ; + }; + } + ) +] diff --git a/sys/nixpkgs/pkgs/lf-make-map/flake.lock b/sys/nixpkgs/pkgs/lf-make-map/flake.lock new file mode 100644 index 00000000..ea926e53 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/flake.lock @@ -0,0 +1,147 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711681752, + "narHash": "sha256-LEg6/dmEFxx6Ygti5DO9MOhGNpyB7zdxdWtzv/FCTXk=", + "owner": "ipetkov", + "repo": "crane", + "rev": "ada0fb4dcce4561acb1eb17c59b7306d9d4a95f3", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711715736, + "narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "807c549feabce7eddbf259dbdcec9e0600a0660d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711851236, + "narHash": "sha256-EJ03x3N9ihhonAttkaCrqxb0djDq3URCuDpmVPbNZhA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "f258266af947599e8069df1c2e933189270f143a", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1680978846, + "narHash": "sha256-Gtqg8b/v49BFDpDetjclCYXm8mAnTrUzR0JnE2nv5aw=", + "owner": "nix-systems", + "repo": "x86_64-linux", + "rev": "2ecfcac5e15790ba6ce360ceccddb15ad16d08a8", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "x86_64-linux", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1711803027, + "narHash": "sha256-Qic3OvsVLpetchzaIe2hJqgliWXACq2Oee6mBXa/IZQ=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "1810d51a015c1730f2fe05a255258649799df416", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/flake.nix b/sys/nixpkgs/pkgs/lf-make-map/flake.nix new file mode 100644 index 00000000..dc8c24cc --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/flake.nix @@ -0,0 +1,125 @@ +{ + description = "An automatic lf cd mapping generator"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + + crane = { + url = "github:ipetkov/crane"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + + # inputs for following + systems = { + url = "github:nix-systems/x86_64-linux"; # only evaluate for this system + }; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + flake-utils = { + url = "github:numtide/flake-utils"; + inputs = { + systems.follows = "systems"; + }; + }; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + treefmt-nix, + crane, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + + nightly = false; + rust_minimal = + if nightly + then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal) + else pkgs.rust-bin.stable.latest.minimal; + rust_default = + if nightly + then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default) + else pkgs.rust-bin.stable.latest.default; + + cargo_toml = craneLib.cleanCargoToml {cargoToml = ./Cargo.toml;}; + pname = cargo_toml.package.name; + + craneLib = (crane.mkLib pkgs).overrideToolchain rust_minimal; + craneBuild = craneLib.buildPackage { + src = craneLib.cleanCargoSource ./.; + + doCheck = true; + }; + + manual = pkgs.stdenv.mkDerivation { + name = "${pname}-manual"; + inherit (cargo_toml.package) version; + + src = ./docs; + nativeBuildInputs = with pkgs; [pandoc]; + + buildPhase = '' + mkdir --parents $out/docs; + + pandoc "./${pname}.1.md" -s -t man > $out/docs/${pname}.1 + ''; + + installPhase = '' + install -D $out/docs/${pname}.1 $out/share/man/man1/${pname}; + ''; + }; + + treefmtEval = import ./treefmt.nix {inherit treefmt-nix pkgs;}; + in { + packages.default = pkgs.symlinkJoin { + inherit (cargo_toml.package) name; + + paths = [manual craneBuild]; + }; + + checks = { + inherit craneBuild; + formatting = treefmtEval.config.build.check self; + }; + + formatter = treefmtEval.config.build.wrapper; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + cocogitto + + rust_default + cargo-edit + + licensure + ]; + }; + }); +} +# vim: ts=2 + diff --git a/sys/nixpkgs/pkgs/lf-make-map/lf_make_map.nix b/sys/nixpkgs/pkgs/lf-make-map/lf_make_map.nix new file mode 100644 index 00000000..08fc6bb5 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/lf_make_map.nix @@ -0,0 +1,12 @@ +{ + rustPlatform, +}: +rustPlatform.buildRustPackage { + pname = "lf-make-map"; + version = "0.1.0"; + + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + }; +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/cli.rs b/sys/nixpkgs/pkgs/lf-make-map/src/cli.rs new file mode 100644 index 00000000..7650b39b --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/cli.rs @@ -0,0 +1,28 @@ +use std::path::PathBuf; + +use clap::{ArgAction, Parser}; + +/// An automatic lf cd mapping generator +#[derive(Parser, Debug)] +#[clap(author, version, about, long_about = None)] +#[command(next_line_help = true)] +pub struct Args { + /// The directory to treat as home + #[arg(long, short = 'n', env = "HOME")] + pub home_name: PathBuf, + + /// The directories to generate mappings for + pub relevant_directories: Vec<PathBuf>, + + /// The number of directories to generate mappings for, starting from each `relevant_directory` + #[arg(long, short, default_value = "2")] + pub depth: usize, + + /// Increase message verbosity + #[arg(long="verbose", short = 'v', action = ArgAction::Count)] + pub verbosity: u8, + + /// Silence all output + #[arg(long, short = 'q')] + pub quiet: bool, +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs b/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs new file mode 100644 index 00000000..48df027f --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs @@ -0,0 +1,45 @@ +use std::path::PathBuf; + +use anyhow::{Context, Result}; +use log::{debug, info, trace}; +use walkdir::{DirEntry, WalkDir}; + +use crate::mapping::{map_tree::MappingTree, Mapping}; + +pub struct MappingsGenerator { + mappings: MappingTree, + paths_to_process: Vec<PathBuf>, +} + +fn is_dir(entry: &DirEntry) -> bool { + entry.file_type().is_dir() +} + +impl MappingsGenerator { + pub async fn new( + directories_to_scan: Vec<PathBuf>, + max_depth: usize, + home_path: PathBuf, + ) -> Result<Self> { + let mut mappings = MappingTree::new(); + + for dir in directories_to_scan { + for dir2 in WalkDir::new(&dir) + .max_depth(max_depth) + .into_iter() + .filter_entry(|e| is_dir(e)) + { + let directory = + dir2.with_context(|| format!("Failed to read dir ('{}')", &dir.display()))?; + + trace!("Processed '{}'..", directory.path().display()); + + let mapping = Mapping::new(&home_path, directory.path().to_path_buf()); + mappings + .insert(&mapping.key.clone(), mapping) + .context("Failed to insert a key")?; + } + } + todo!() + } +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs.old b/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs.old new file mode 100644 index 00000000..406b1996 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs.old @@ -0,0 +1,165 @@ +use std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; + +use anyhow::{bail, Context, Result}; +use futures::{Stream, StreamExt, TryStreamExt}; +use log::info; +use tokio::{ + fs::{self, DirEntry}, + io, + sync::mpsc::{self, Receiver, Sender}, + task::JoinHandle, +}; +use tokio_stream::wrappers::{ReadDirStream, ReceiverStream}; + +pub struct MappingGenerator { + current_mappings: HashMap<String, PathBuf>, + paths_to_process: Vec<PathBuf>, +} + +pub struct MappingGeneratorHelper { + tx: Sender<(PathBuf, oneshotSender<PathBuf>)>, + handle: JoinHandle<()>, + done: Vec<PathBuf>, +} + +impl MappingGeneratorHelper { + pub fn new() -> Self { + let (rx, tx) = mpsc::channel(100); + + let handle = tokio::spawn(async move { + while let Some(dir) = rx.recv().await { + info!("processing '{}'..", dir.display()); + get_dir(dir); + } + }); + + Self { tx, handle } + } + + pub async fn process(&self, dir: PathBuf) -> Result<()> { + let (tx, rx) = + self.tx.send(dir).await?; + Ok(()) + } +} + +impl MappingGenerator { + pub async fn new(directories_to_scan: Vec<PathBuf>, depth: usize) -> Result<Self> { + let cleaned_directories: Vec<PathBuf> = directories_to_scan + .into_iter() + .map(check_dir) + .collect::<Result<_>>()?; + + let helper = MappingGeneratorHelper::new(); + + cleaned_directories + .into_iter() + .for_each(|dir| helper.process(dir)); + + info!( + "Will process:\n {}", + all_directories + .iter() + .map(|pat| pat.display().to_string()) + .collect::<Vec<_>>() + .join("\n ") + ); + Ok(Self { + current_mappings: HashMap::new(), + paths_to_process: all_directories, + }) + } +} + +fn check_dir(dir: PathBuf) -> Result<PathBuf> { + match dir.metadata() { + Ok(_) => Ok(dir), + Err(e) => bail!( + "'{}' is not a valid path; Error was: '{}'", + dir.display(), + e + ), + } +} + +pub async fn get_dir(dir: PathBuf, current_depth: usize, max_depth: usize) -> Result<Vec<PathBuf>> { + let (tx, rx) = mpsc::channel(100); + + let handle = tokio::spawn(async move { get_dir_recursive(dir, current_depth, max_depth, tx) }); + + let out = ReceiverStream::new(rx).collect::<Vec<PathBuf>>().await; + handle.await?; + Ok(out) +} + +async fn get_dir_recursive( + dir: PathBuf, + current_depth: usize, + max_depth: usize, + tx: Sender<PathBuf>, +) -> Result<()> { + if dir.is_dir() && current_depth != max_depth { + tx.send(dir).await?; + + match fs::read_dir(&dir).await { + Ok(directories) => { + let mut handles: Vec<JoinHandle<Result<(), anyhow::Error>>> = vec![]; + while let Some(entry) = directories + .next_entry() + .await + .with_context(|| format!("Failed to read directory: '{}'", dir.display()))? + { + let tx_new = tx.clone(); + handles.push(tokio::spawn(async move { + get_dir_recursive(entry.path(), current_depth + 1, max_depth, tx_new) + .await + .with_context(|| { + format!("Failed to get child directories to '{}'", dir.display()) + })?; + + Ok(()) + })); + } + + let out: Vec<_> = tokio_stream::iter(handles) + .then(|handle| async move { handle.await }) + .collect() + .await; + + // I have no idea what happened here to the type system + for i in out { + i?? + } + + Ok(()) + } + + Err(e) => { + bail!( + "Unable to read directory {}, skipping; error: {}", + dir.display(), + e + ); + } + } + } else { + return Ok(()); + } +} + +#[cfg(test)] +mod test { + use std::path::PathBuf; + + use super::get_dir; + + #[test] + fn test_get_dir() { + let dirs = get_dir(PathBuf::from("~/repos")); + let expected_dirs = vec![PathBuf::from("~/repos/rust")]; + assert_eq!(dirs, expected_dirs); + } +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/main.rs b/sys/nixpkgs/pkgs/lf-make-map/src/main.rs new file mode 100644 index 00000000..dbfe5ec7 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/main.rs @@ -0,0 +1,116 @@ +use anyhow::Context; +use clap::Parser; +use cli::Args; +use generator::MappingsGenerator; + +mod cli; +mod generator; +mod mapping; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let args = Args::parse(); + + stderrlog::new() + .module(module_path!()) + .quiet(args.quiet) + .show_module_names(false) + .color(stderrlog::ColorChoice::Auto) + .verbosity(args.verbosity as usize) + .timestamp(stderrlog::Timestamp::Off) + .init()?; + + // gen_lf_mappings(args.home_name, 0, args.relevant_directories); + let map = MappingsGenerator::new(args.relevant_directories, args.depth, args.home_name) + .await + .context("Failed to initialize mappings generator")?; + + Ok(()) +} + +// 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/sys/nixpkgs/pkgs/lf-make-map/src/mapping/error.rs b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/error.rs new file mode 100644 index 00000000..2a59ed64 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/error.rs @@ -0,0 +1,7 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum Error { + #[error("The node at key '{0}' already exists!")] + NodeExits(String), +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree.rs b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree.rs new file mode 100644 index 00000000..44165ed1 --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/map_tree.rs @@ -0,0 +1,103 @@ +use std::collections::HashMap; + +use super::{error, Mapping}; + +/// A prefix tree +pub struct MappingTree { + root: Node, +} + +#[derive(Clone)] +pub struct Node { + children: HashMap<char, Node>, + value: Option<Mapping>, + + /// The key needed to get to this node + location: String, +} + +impl MappingTree { + pub fn new() -> Self { + Self { + root: Node::new(String::new(), None), + } + } + + /// Returns the node at the key, otherwise None + pub fn get(&self, key: &str) -> Option<&Node> { + let mut current_node = &self.root; + for ch in key.chars() { + current_node = current_node.children.get(&ch)? + } + + Some(current_node) + } + /// Returns the node at the key, otherwise None. The node can be changed + pub fn get_mut(&mut self, key: &str) -> Option<&mut Node> { + let mut current_node = &mut self.root; + for ch in key.chars() { + current_node = current_node.children.get_mut(&ch)? + } + + Some(current_node) + } + + /// Returns the node at the key, otherwise the last node that matched. + pub fn try_get(&self, key: &str) -> &Node { + let mut current_node = &self.root; + for ch in key.chars() { + if let Some(node) = current_node.children.get(&ch) { + current_node = node; + } else { + return current_node; + } + } + + current_node + } + + pub fn insert(&mut self, key: &str, mapping: Mapping) -> Result<(), error::Error> { + let node = self.try_get(key).clone(); + if node.location.as_str() != key { + let needed_nodes_key = key.trim_start_matches(node.location.as_str()); + let needed_nodes_length = needed_nodes_key.chars().count(); + + let mut current_node = self + .get_mut(&node.location) + .expect("This should always exists"); + let mut current_location = node.location.clone(); + let mut counter = 0; + + for ch in needed_nodes_key.chars() { + current_location.push(ch); + + let next_node = if counter == needed_nodes_length { + Node::new(current_location.clone(), Some(mapping.clone())) + } else { + Node::new(current_location.clone(), None) + }; + + current_node.children.insert(ch, next_node); + current_node = current_node + .children + .get_mut(&ch) + .expect("Was just inserted"); + counter += 1; + } + } else { + return Err(error::Error::NodeExits(key.to_owned())); + } + + Ok(()) + } +} + +impl Node { + pub fn new(location: String, mapping: Option<Mapping>) -> Self { + Self { + children: HashMap::new(), + location, + value: mapping, + } + } +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/mapping/mod.rs b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/mod.rs new file mode 100644 index 00000000..7de1ca5d --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/mapping/mod.rs @@ -0,0 +1,122 @@ +use std::path::{Path, PathBuf}; + +use log::debug; + +pub mod error; +pub mod map_tree; + +#[derive(Debug, Clone)] +pub struct Mapping { + pub raw_path: PathBuf, + + pub keys: usize, + + pub key: String, +} +impl Mapping { + pub fn new(home_path: &Path, initial_path: PathBuf) -> Mapping { + let raw_path = initial_path + .strip_prefix(home_path) + .expect("Must always be under the `home_path`"); + + let key = Self::path_to_key(raw_path.to_str().expect("Should be a valid &str")); + + Self { + raw_path: raw_path.to_owned(), + keys: key.len(), + key, + } + } + + fn path_to_key(path: &str) -> String { + let key: String = path + .split('/') + .map(|part| part.chars().nth(0).expect("Must have a first element")) + .collect(); + debug!("'{}' -> '{}'", path, key); + key + } +} + +pub fn gen_hot_key(path: &Path, base_path: &Path, amount_of_chars: usize) -> String { + let path_filename_as_str = path + .file_name() + .expect("All paths here should have a file name") + .to_str() + .expect("The OSstr should be convertible"); + + let mut return_val = String::from("g"); + if path != base_path { + return_val.push( + base_path + .file_name() + .expect("All paths here should have a file name") + .to_str() + .expect("The OSstr should be convertible") + .chars() + .nth(0) + .expect("All names should have a first char"), + ); + } + if path_filename_as_str.contains("_") { + path_filename_as_str.split("_").for_each(|a| { + return_val.push( + a.chars() + .nth(0) + .expect("All names should have a first char"), + ) + }); + } else { + if path == base_path { + return_val.push( + path_filename_as_str + .chars() + .nth(0) + .expect("All names should have a first char"), + ); + } else { + for a in 0..amount_of_chars { + return_val.push(if let Some(b) = path_filename_as_str.chars().nth(a) { + b + } else { + path_filename_as_str + .chars() + .nth(0) + .expect("All names should have a first char") + }); + } + } + } + if path == base_path { + return_val.push('.'); + } + return_val +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn gen_hot_key_test() { + let gen1 = gen_hot_key( + Path::new("/home/dt/repos/java_script"), + Path::new("/home/dt/repos"), + 1, + ); + assert_eq!(gen1, "grjs".to_owned()); + } + #[test] + fn gen_hot_key_test_for_same_names() { + let gen1 = gen_hot_key(Path::new("/home/dt/repos/"), Path::new("/home/dt/repos"), 1); + assert_eq!(gen1, "gr.".to_owned()); + } + #[test] + fn gen_hot_key_test_for_non_underscore_name() { + let gen1 = gen_hot_key( + Path::new("/home/dt/repos/rust"), + Path::new("/home/dt/repos"), + 1, + ); + assert_eq!(gen1, "grr".to_owned()); + } +} diff --git a/sys/nixpkgs/pkgs/lf-make-map/update.sh b/sys/nixpkgs/pkgs/lf-make-map/update.sh new file mode 100755 index 00000000..b34dabfa --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/update.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +nix flake update +cargo update +[ "$1" = "upgrade" ] && cargo upgrade |