(define-structure crunchy.run (export crunchy/find-executable crunchy/run-or-focus crunchy/run-or-toggle-iconify ) (open rep rep.io.files rep.regexp rep.system sawfish.wm.commands sawfish.wm.state.iconify sawfish.wm.util.display-window sawfish.wm.windows sawfish.wm.windows.subrs ) (defun crunchy/find-executable (prog) (catch 'out (let ((path (getenv "PATH")) (point 0) end tem) (while (< point (length path)) (setq end (if (string-match ":" path point) (match-start) (length path))) (setq tem (substring path point end)) (when (file-exists-p (expand-file-name prog tem)) (throw 'out (expand-file-name prog tem))) (setq point (1+ end)))) nil)) (defun crunchy/run-or-focus (wnd-name cmd) "Find an application and moves to the viewport or start a new instance." (let ((w (get-window-by-name-re wnd-name))) (when w (progn (crunchy-save-position) (display-window w))) (when (not w) (system (format nil "%s &" cmd))))) (define-command 'crunchy/run-or-focus crunchy/run-or-focus #:spec "%S\n%S" #:type '(and (labelled "Name:" (string "")) (labelled "Command:" (string "")))) (defun crunchy/run-or-toggle-iconify (wnd-name cmd) "toggle the iconify state" (let ((w (get-window-by-name-re wnd-name))) (when w (if (window-get w 'iconified) (uniconify-window w) (iconify-window w))) (when (not w) (system (format nil "%s &" cmd))))) (define-command 'crunchy/run-or-toggle-iconify crunchy/run-or-toggle-iconify #:spec "%S\n%S" #:type '(and (labelled "Name:" (string "")) (labelled "Command:" (string "")))) )