stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[STUMP] [PATCH] make stumpwm cache programs in PATH for completion


From: Lionel Flandrin
Subject: [STUMP] [PATCH] make stumpwm cache programs in PATH for completion
Date: Sun, 27 Apr 2008 22:07:19 +0200

* new var *program-list* containing the list of programs found in the PATH.
* new command "rehash" to actualise it.
* programs-in-path now just lists the programs, no more "base" argument.
* instead, a new function "complete-program" is used for completion, returning
  the programs in *program-list* that match the base.
---
 user.lisp |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/user.lisp b/user.lisp
index 6a0b347..4b3217e 100644
--- a/user.lisp
+++ b/user.lisp
@@ -541,7 +541,7 @@ the 'date' command options except the following ones: %g, 
%G, %j, %N,
   "Switch to the window last focused."
   (other-window (current-group)))
 
-(defun programs-in-path (base &optional full-path (path (split-string (getenv 
"PATH") ":")))
+(defun programs-in-path (&optional full-path (path (split-string (getenv 
"PATH") ":")))
   "Return a list of programs in the path that start with @var{base}. if
 @var{full-path} is @var{t} then return the full path, otherwise just
 return the filename. @var{path} is by default the @env{PATH}
@@ -554,15 +554,28 @@ each directory seperated by a colon."
    nconc (loop
           for file in (directory (merge-pathnames (make-pathname :name :wild) 
dir))
           for namestring = (file-namestring file)
-          when (and (string= base namestring
-                             :end1 (min (length base)
-                                        (length namestring))
-                             :end2 (min (length base)
-                                        (length namestring)))
-                    (pathname-is-executable-p file))
-          collect (if full-path
-                      (namestring file)
-                      namestring))))
+           when (pathname-is-executable-p file)
+           collect (if full-path
+                       (namestring file)
+                       namestring))))
+
+(defvar *program-list* '()
+  "list containing the programs in the path, used for completion")
+(defcommand rehash (&optional (path (split-string (getenv "PATH")
+                                            ":"))) ()
+    "put the list of programs in the path in @var{*programs-list*}"
+  (setf *program-list* (programs-in-path nil path)))
+
+(defun complete-program (base)
+  "return the list of programs in @var{*program-list*} whose names begin
+with base. If @var{*program-list*} is nil, run @code{rehash} first."
+  (or *program-list* (rehash))
+  (remove-if-not #'(lambda (p)
+                    (string= base p
+                             :end1 (min (length base)
+                                        (length p))
+                             :end2 (min (length base)
+                                        (length p))))  *program-list*))
 
 (defcommand run-shell-command (cmd &optional collect-output-p) ((:shell 
"/bin/sh -c "))
   "Run the specified shell command. If @var{collect-output-p} is @code{T}
@@ -972,7 +985,7 @@ string between them."
 
 (define-stumpwm-type :shell (input prompt)
   (or (argument-pop-rest input)
-      (completing-read (current-screen) prompt 'programs-in-path)))
+      (completing-read (current-screen) prompt 'complete-program)))
 
 (define-stumpwm-type :rest (input prompt)
   (or (argument-pop-rest input)
-- 
1.5.3.8





reply via email to

[Prev in Thread] Current Thread [Next in Thread]