Add completion for file names
Check for an empty file name before executing
This commit is contained in:
		
							parent
							
								
									92b8549db8
								
							
						
					
					
						commit
						d5f792b3d4
					
				| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
 | 
			
		||||
(define *cache* #f)
 | 
			
		||||
 | 
			
		||||
(define (executables-in-path)
 | 
			
		||||
  (or *cache*
 | 
			
		||||
      (begin 
 | 
			
		||||
        (set! *cache* (executables-in-path-list (thread-fluid exec-path-list)))
 | 
			
		||||
        *cache*)))
 | 
			
		||||
 | 
			
		||||
(define (executables-in-path-list path-list)
 | 
			
		||||
  (append-map! dir-executables path-list))
 | 
			
		||||
 | 
			
		||||
(define (dir-executables dir)
 | 
			
		||||
  (if (file-readable? dir)
 | 
			
		||||
      (map file-name-nondirectory 
 | 
			
		||||
           (filter executable? (glob (string-append dir "/*"))))
 | 
			
		||||
      '()))
 | 
			
		||||
 | 
			
		||||
(define (executable? name)
 | 
			
		||||
  (with-errno-handler
 | 
			
		||||
   ((errno packet)
 | 
			
		||||
    (else #f))
 | 
			
		||||
   (let ((info (file-info name)))
 | 
			
		||||
     (and (file-info-executable? info)
 | 
			
		||||
          (file-info-regular? info)))))
 | 
			
		||||
| 
						 | 
				
			
			@ -79,6 +79,13 @@
 | 
			
		|||
	utils)
 | 
			
		||||
  (files button))
 | 
			
		||||
 | 
			
		||||
(define-structure file-name-completion
 | 
			
		||||
  (export executables-in-path)
 | 
			
		||||
  (open scheme-with-scsh
 | 
			
		||||
        srfi-1
 | 
			
		||||
        thread-fluids)
 | 
			
		||||
  (files file-name-completion))
 | 
			
		||||
 | 
			
		||||
;; *** key-grab ******************************************************
 | 
			
		||||
 | 
			
		||||
(define-structure key-grab
 | 
			
		||||
| 
						 | 
				
			
			@ -215,7 +222,7 @@
 | 
			
		|||
	utils key-grab
 | 
			
		||||
	manager
 | 
			
		||||
	move-wm split-wm switch-wm
 | 
			
		||||
	prompt)
 | 
			
		||||
	prompt file-name-completion)
 | 
			
		||||
  (files root-manager))
 | 
			
		||||
 | 
			
		||||
(define-structure main
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -316,8 +316,9 @@
 | 
			
		|||
	    (exec (prompt (root-wm:dpy root-wm) (wm:window cm)
 | 
			
		||||
			  (get-option-value (root-wm:options root-wm)
 | 
			
		||||
					    'execute-question)
 | 
			
		||||
			  #f exec-complete)))
 | 
			
		||||
       (if exec
 | 
			
		||||
			  #f (finite-complete (executables-in-path)))))
 | 
			
		||||
       (and exec
 | 
			
		||||
            (not (string=? exec ""))
 | 
			
		||||
            (run (sh -c ,(string-append exec " &"))))))
 | 
			
		||||
    ((attach)
 | 
			
		||||
     (let* ((cm (root-wm:current-manager root-wm))
 | 
			
		||||
| 
						 | 
				
			
			@ -366,10 +367,6 @@
 | 
			
		|||
	     (else (warn "unknown binding command" command))))
 | 
			
		||||
	 (warn "unhandled root message" msg)))))
 | 
			
		||||
 | 
			
		||||
(define (exec-complete str pos)
 | 
			
		||||
  ;; TODO
 | 
			
		||||
  (cons str pos))
 | 
			
		||||
 | 
			
		||||
(define (finite-complete strings)
 | 
			
		||||
  (lambda (str pos)
 | 
			
		||||
    (let* ((s (substring str 0 pos))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue