about summary refs log tree commit diff
path: root/tools/eaglemode
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@tvl.su>2024-08-27T21·47+0300
committertazjin <tazjin@tvl.su>2024-08-30T13·30+0000
commitd235fd99c2fad038b624a2bf5475325dc56d86c6 (patch)
treecdf52e90e27c18d32b2eadbd0f434f8314766559 /tools/eaglemode
parent0979379980ef9bcd019f07020455b73ac3816676 (diff)
feat(tools/eaglemode): add helper function for Eagle Mode commands r/8614
This generates the correct `.pl` files for adding Eagle Mode commands. This
commit does not yet contain the wiring for adding these into Eagle Mode
directly, which is a bit involved.

Change-Id: I7d88128ba3ddaebfbb618db45e8fa843a3f17dea
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12366
Tested-by: BuildkiteCI
Reviewed-by: emery <emery@dmz.rs>
Diffstat (limited to 'tools/eaglemode')
-rw-r--r--tools/eaglemode/default.nix57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/eaglemode/default.nix b/tools/eaglemode/default.nix
new file mode 100644
index 000000000000..32f117c9bf5f
--- /dev/null
+++ b/tools/eaglemode/default.nix
@@ -0,0 +1,57 @@
+# Helper functions for extending Eagle Mode with useful stuff.
+#
+# Eagle Mode's customisation usually expects people to copy the entire
+# configuration into their user folder, which we can automate fairly easily
+# using Nix, letting users choose whether to keep upstream config or not.
+{ depot, lib, pkgs, ... }:
+
+let
+  mkDesc = d: lib.concatMapStringsSep "\n"
+    (x: "# Descr =${x}")
+    (builtins.filter (s: s != "") (lib.splitString "\n" d));
+in
+rec {
+  # mkCommand creates an Eagle Mode command for the file browser.
+  #
+  # Commands are basically little Perl scripts with a command standard library
+  # available. They receive the user's selected target from Eagle Mode.
+  mkCommand =
+    {
+      # Name of the command.
+      name
+    , # User-facing description, displayed in Eagle Mode UI. Can be multi-line.
+      description
+    , # Verbatim Perl code of the command. Command library is already available.
+      code
+    , # Caption for the UI button (defaults to name).
+      caption ? name
+    , icon ? "terminal.tga"
+    , # TODO: what's a good default?
+      hotkey ? ""
+    , order ? 1.0
+    }: pkgs.writeTextDir "emFileMan/Commands/${name}.pl" (''
+      #!${pkgs.perl}/bin/perl
+      #[[BEGIN PROPERTIES]]
+      # Type = Command
+      # Interpreter = perl
+      # DefaultFor = directory
+      # Caption = ${caption}
+      # Order = ${toString order}
+      # Icon = ${icon}
+    ''
+    + (lib.optionalString (description != "") "${mkDesc description}\n")
+    + (lib.optionalString (hotkey != "") "# Hotkey = ${hotkey}\n")
+    + ''
+      #[[END PROPERTIES]]
+
+      use strict;
+      use warnings;
+      BEGIN { require "$ENV{'EM_DIR'}/res/emFileMan/scripts/cmd-util.pl"; }
+
+      ${if builtins.isString code
+        then code
+        else (if builtins.isPath code
+             then builtins.readFile code
+             else throw "code must be a string (literal code) or path to file")}
+    '');
+}