about summary refs log tree commit diff stats
path: root/pkgs/by-name/lf/lf-make-map/src/mapping/lf_mapping.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-27 21:40:18 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-27 21:40:18 +0200
commit8fbac3c232691c18c410ad7e80f4f2108b3a8163 (patch)
tree0595206851f56db233261ab87c9973408770724e /pkgs/by-name/lf/lf-make-map/src/mapping/lf_mapping.rs
parentpkgs/lf-make-map: Reduce flake to a simple dev shell (diff)
downloadnixos-config-8fbac3c232691c18c410ad7e80f4f2108b3a8163.zip
pkgs/lf-make-map: Use trinitrix's keymaps library
The library was largely modelled after the previously used
`MappingTrie`. Thus using that results in code deduplication.
Diffstat (limited to 'pkgs/by-name/lf/lf-make-map/src/mapping/lf_mapping.rs')
-rw-r--r--pkgs/by-name/lf/lf-make-map/src/mapping/lf_mapping.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/pkgs/by-name/lf/lf-make-map/src/mapping/lf_mapping.rs b/pkgs/by-name/lf/lf-make-map/src/mapping/lf_mapping.rs
new file mode 100644
index 00000000..f8a6182e
--- /dev/null
+++ b/pkgs/by-name/lf/lf-make-map/src/mapping/lf_mapping.rs
@@ -0,0 +1,35 @@
+// 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::path::PathBuf;
+
+use crate::mapping::MapKey;
+
+use super::MappingsTrie;
+
+impl MappingsTrie {
+    pub fn to_lf_mappings(&self, home_path: PathBuf) -> String {
+        let mut raw = self
+            .0
+            .iter()
+            .map(|(key, value)| {
+                format!(
+                    "map g{} cd \"{}\"\n",
+                    MapKey::display(&key),
+                    home_path.join(&value.path).display()
+                )
+            })
+            .collect::<Vec<String>>();
+
+        raw.sort();
+
+        raw.into_iter().collect()
+    }
+}