From af17d6e0dc6cbdb1a1b26d2cb2c5c0937cafa782 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sun, 29 Dec 2024 15:41:24 -0800 Subject: [PATCH] Complete the "env" directive in firejail-mode.el --- elisp/firejail-mode.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/elisp/firejail-mode.el b/elisp/firejail-mode.el index 78430b4..c80bbb9 100644 --- a/elisp/firejail-mode.el +++ b/elisp/firejail-mode.el @@ -508,6 +508,21 @@ With NO-ABSOLUTE, don't complete absolute file names." (append (seq-take (nth ,index ,args) 2) (list (seq-difference ,evaled-vals ,present))))))) +(defun firejail--get-all-env-keys () + "Return the name of every current environment variable." + (mapcar (lambda (elt) + (if-let ((sep (cl-position ?= elt))) + (substring elt 0 sep) + elt)) + process-environment)) + +(defun firejail--complete-env (index args _directive) + "Complete the arg numbered INDEX in ARGS for an \"env\" directive." + (cl-destructuring-bind (start _end text) (nth index args) + (let ((sep-pos (or (cl-position ?= text) (length text)))) + (when (<= (point) (+ start sep-pos)) + (list start (+ start sep-pos) (firejail--get-all-env-keys)))))) + (defconst firejail-profile--keyword-handlers (let ((ht (make-hash-table :test 'equal))) (cl-flet* ((complete (args fun dirs) @@ -583,7 +598,8 @@ With NO-ABSOLUTE, don't complete absolute file names." (complete-all (firejail--complete-many-from-set '(mapcar 'number-to-string (number-sequence 0 (firejail--get-num-cpus)))) - "cpu")) + "cpu") + (complete 1 #'firejail--complete-env "env")) ht) "Hash table mapping firejail profile directives to their handler. Each handler is a function of three arguments. The first is the index of the