Browse URL hacks

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Browse URL hacks

Max Mikhanosha-2
Went through my "things annoying me in StumpWM" list, and came out
with the following hacks.. Everyone probably has something similar,
but just thought I'll share.

Command: url <url>

If current group has a browser window, opens url as new tab. If
current group does not have a browser window, opens new browser window
in the current group, even if browser window exists in another group

Supports firefox and chromium

Command: google <word> [<word> ..]

Uses "url" command to google stuff, bind it to a key.

Command: browser

Raises browser window in current group or creates a new browser window.

Below shell scripts allow issuing same commands from command line.

--- cat url ---
exec stumpish url $*

--- cat google ---
exec stumpish google $*

;; Emacs integration (assumes above "url" script is in the PATH)
;; so clicking on URL's in emacs will use same commands

(defun my-browse-url (url &optional new-window)
  (interactive (browse-url-interactive-arg "URL: "))
  (start-process (concat "URL " url) nil "url" url))

(setq browse-url-browser-function 'my-browse-url
      w3m-goto-article-function 'my-browse-url
      mime-browse-url-function 'my-browse-url)

----- ~/.stumpwmrc code ------

;;; URL tools, to change browser change below var to chromium

(defvar *browser* "chromium")

(defcommand browser () ()
  "Start browser is already running, in which case focus it."
  (let* ((browser-name (or *browser* "firefox"))
         (browser-class (string-capitalize (file-namestring browser-name))))
    (run-or-raise browser-name `(:class ,browser-class))))

(defcommand url (url) ((:rest "URL"))
  "Open URL in the browser in the current group"
  (check-type url string)
  (unless (or
           (eql 0 (search "http://" url))
           (eql 0 (search "https://" url))
           (eql 0 (search "ftp://" url))
           (eql 0 (search "file://" url)))
    (setq url (cat "http://" url)))
  (let* ((browser-name (or *browser* "firefox"))
         (browser-class (string-capitalize (file-namestring browser-name)))
         (firefoxp (search "firefox" browser-name))
         (chromep (search "chrom" browser-name))
    (flet ((run-browser (&rest args)
             (run-prog browser-name :search t :args args :wait nil))
           (find-browser-window (&optional all-groups)
             (first (find-matching-windows
                     `(:class ,browser-class) all-groups nil))))
      (if firefoxp
          (cond ((setq window (find-browser-window))
                 ;; firefox opens new tab in the last active window, which
                 ;; could be in another group. Raise firefox window first
                 ;; so that tab will be opened on a window in the current
                 ;; group
                 (focus-window window)
                 (run-browser  "-remote"  (cat "openUrl(" url ")")))
                ((find-browser-window :all)
                 (run-browser  "-remote"  (cat "openUrl(" url ",new-window)")))
                 (run-browser url)))
          (cond ((setq window (find-browser-window))
                 (focus-window window)
                 (run-browser url))
                (chromep (run-browser  "--new-window" url))
                (t (run-browser url)))))))

(defcommand google (search) ((:rest "Search in Google for: "))
  "Search Google for stuff, uses URL command"
  (check-type search string)
  (setq search (substitute #\Space #\+ search))
  (url (cat "" search)))

Stumpwm-devel mailing list
[hidden email]
Reply | Threaded
Open this post in threaded view

Re: Browse URL hacks

Max Mikhanosha-2
Forgot one utility, above uses the following little shortcut:

(defun cat (&rest strings)
  "A shortcut for (concatenate 'string foo bar)."
  (apply 'concatenate 'string strings))

Stumpwm-devel mailing list
[hidden email]