Plaster
New
List
Login
text
apl
aspx
asterisk
brainfuck
c
c++hdr
c++src
cassandra
ceylon
clojure
clojurescript
cmake
cobol
coffeescript
common-lisp
crystal
csharp
css
cypher-query
cython
d
dart
diff
django
dockerfile
dylan
ebnf
ecl
ecmascript
edn
eiffel
ejs
elm
erb
erlang
ez80
factor
fcl
feature
forth
fortran
fragment
gfm
go
gql
groovy
gss
haml
handlebars-template
haskell
haxe
hive
html
http
httpd-php
httpd-php-open
hxml
ini
java
javascript
json
jsp
jsx
julia
kotlin
latex
less
literate-haskell
lua
mariadb
markdown
mbox
mirc
mscgen
msgenny
mssql
mumps
mysql
n-triples
nesc
nginx-conf
nsis
objectivec
octave
oz
pascal
perl
pgp
pgp-keys
pgp-signature
pgsql
php
pig
plsql
properties
protobuf
puppet
python
q
rpm-changes
rpm-spec
rsrc
ruby
rustsrc
sas
sass
scala
scheme
scss
sieve
slim
smarty
solr
soy
sparql-query
spreadsheet
sql
squirrel
stex
styl
swift
systemverilog
tcl
textile
tiddlywiki
tiki
tlv
tornado
ttcn-asn
ttcn-cfg
turtle
twig
typescript
typescript-jsx
vb
vbscript
velocity
verilog
vertex
vhdl
vue
webidl
xml
xml-dtd
xquery
xu
yaml
z80
default
Visibility:
public
unlisted
private
(defpackage #:config.wifi (:use #:stumpwm #:cl) (:import-from #:config.helpers #:run-program #:run-program-safe #:with-destructured-alist) (:export #:wifi-status #:signal-strength)) (in-package #:config.wifi) (defun get-signal-strength () (let ((output (run-program "iwctl station wlan0 show | grep AverageRSSI"))) (second (str:split #\Space (str:collapse-whitespaces output) :omit-nulls t)))) (defun signal-strength () (handler-case (get-signal-strength) (condition () ""))) (defun connected-to-p (string) (str:starts-with-p "[0m" string)) (defun clean-string (string) (let ((split (str:split #\Space string :omit-nulls t))) (if (connected-to-p string) (fourth split) (first split)))) (defun scan () (run-program "iwctl station wlan0 scan")) (defun list-wifi () (let* ((out (run-program "iwctl station wlan0 get-networks")) (split (str:split #\Newline out :omit-nulls t)) (wanted (nthcdr 4 split)) (cleaned (mapcar #'clean-entry wanted))) (select-from-menu (current-screen) (mapcar (lambda (cleaned) (cons cleaned cleaned)) cleaned)))) (defun connect-to-wifi (&optional password) (flet ((without-pass (station) (format nil "iwctl station wlan0 connect ~A" station)) (with-pass (station) (let ((pass (read-one-line (current-screen) "Wifi Pass: " :password t))) (when (and pass (string/= pass "")) (format nil "iwctl station wlan0 connect ~A password ~A" station pass))))) (with-destructured-alist (station ignored) (list-wifi) (when station (let ((conn? (funcall (if password #'with-pass #'without-pass) station ))) (when conn? (run-program conn?))))))) (defun disconnect-wifi () (let ((c (format nil "iwctl station ~A disconnect" *station*))) (echo (run-program c)))) (defparameter *wifi-menu* `(("Connect w/p" . ,(lambda () (connect-to-wifi t))) ("Connect wo/p" . ,(lambda () (connect-to-wifi nil))) ("Disconnect" . disconnect-wifi) ("Scan" . scan) ("List networks" . display-wifi))) (defcommand display-wifi-menu () () (with-destructured-alist (key command) (select-from-menu (current-screen) ; screen *wifi-menu* "Wifi: ") (when command (funcall command)))) (define-key *root-map* (kbd "M-w") "display-wifi-menu")