Created
January 13, 2012 18:45
-
-
Save jollm/1608010 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; wicd helper commands for StumpWM. | |
;; | |
;; Copyright (C) 2012 Joseph Gay | |
;; | |
;; Maintainer: Joseph Gay | |
;; | |
;; This module is free software: you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation, either version 3 of the License, or | |
;; (at your option) any later version. | |
;; | |
;; This module is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; | |
;; You should have received a copy of the GNU General Public License | |
;; along with this software. If not, see <http://www.gnu.org/licenses/>. | |
;;; Usage: | |
;; | |
;; Just add the following line to your .stumpwmrc file: | |
;; | |
;; (load-module "wicd") | |
;; | |
;; Requires wicd-cli to be installed on the system | |
;; | |
;;; Code: | |
(in-package :stumpwm) | |
(defvar *wicd-current-network-color* 2 "Index of *colors* to use in menu for the currently connected network") | |
(defvar *wicd-wired-network-name* "wired" "What to call the wired network in the menu") | |
(defcommand wicd-disconnect () () | |
"disconnect wicd" | |
(run-shell-command "wicd-cli -x")) | |
(defcommand wicd-scan-and-connect () () | |
(message "Scanning for list of networks...") | |
(wicd-c (run-shell-command "wicd-cli --wireless -Sl" t))) | |
(defcommand wicd-connect () () | |
(message "Retrieving list of networks...") | |
(wicd-c (run-shell-command "wicd-cli --wireless -l" t))) | |
(defun wicd-c (wicd-cache-string) | |
"Allow the user to select a network from a list" | |
(let ((network (second (select-from-menu | |
(current-screen) | |
(build-wicd-network-list wicd-cache-string))))) | |
(when network (connect-wicd network)))) | |
(defun connect-wicd (network-number) | |
"connect wicd to the specified network" | |
(if (equalp network-number *wicd-wired-network-name*) | |
(run-shell-command "wicd-cli --wired -c") | |
(run-shell-command (concat "wicd-cli --wireless -c -n " network-number)))) | |
(defun build-wicd-network-list (wicd-cache-string) | |
(let ((current-essid (get-wicd-current-essid))) | |
(mapcar (lambda (v) (let ((essid (elt v 1)) | |
(num (elt v 0))) | |
(list (concat "^[" (if (equalp essid current-essid) (concat "^" (write-to-string *wicd-current-network-color*) "*") "") | |
essid "^] " | |
(unless (equalp essid *wicd-wired-network-name*) | |
(concat | |
(get-wicd-network-property num "encryption_method") " " | |
(get-wicd-network-property num "quality") "%"))) | |
(elt v 0)))) | |
(append `((,*wicd-wired-network-name* ,*wicd-wired-network-name*)) | |
(mapcar (lambda (s) (nth-value 1 (cl-ppcre:scan-to-strings "(\\d){1,2}\\s+\\S\\S(?::\\S\\S){5}\\s+\\d{1,2}\\s+(\\w+)" s))) | |
(rest (split-string wicd-cache-string))))))) | |
(defun get-wicd-network-property (network-number property) | |
(string-trim '(#\Space #\Newline #\Linefeed #\Tab) | |
(run-shell-command (concat "wicd-cli --wireless -p " property " -n " network-number) t))) | |
(defun get-wicd-current-essid () | |
(if (= 0 (length (run-shell-command "wicd-cli --wired -d" t))) | |
(let ((output (run-shell-command "wicd-cli --wireless -d" t))) | |
(unless (cl-ppcre:scan "^Invalid" output) | |
(elt (nth-value 1 (cl-ppcre:scan-to-strings "Essid: (\\S+)" (cl-ppcre:regex-replace-all "\\s+" output " "))) | |
0))) | |
*wicd-wired-network-name*)) | |
;;; End of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment