add fancy laptop prompt
This commit is contained in:
parent
e5f81ad604
commit
a3181aa210
1 changed files with 75 additions and 0 deletions
75
snippets/avas-laptop-prompt.rls
Normal file
75
snippets/avas-laptop-prompt.rls
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#!/bin/relish
|
||||
|
||||
;; relish: versatile lisp shell
|
||||
;; Copyright (C) 2021 Aidan Hahn
|
||||
;;
|
||||
;; This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;; AVA'S LAPTOP PROMPT
|
||||
;; This file contains a shell prompt configuration that outputs current dir
|
||||
;; username, and percentages for all batteries on the system.
|
||||
;; -> requires CFG_RELISH_POSIX=true and userlib.
|
||||
|
||||
(def _batteries 'paths to batteries powering system'
|
||||
(lambda ()
|
||||
(let ((power-srcs-dir '/sys/class/power_supply')
|
||||
(power-srcs
|
||||
(split (load-to-string find /sys/class/power_supply -printf "%p ")
|
||||
" "))
|
||||
(pwr-list ())
|
||||
(pwr-iter (pop power-srcs)))
|
||||
(while (gt? (len pwr-iter) 1)
|
||||
(let ((src (car pwr-iter))
|
||||
(rem (cdr pwr-iter))
|
||||
(match (substr? src "BAT")))
|
||||
(if match
|
||||
(set (q pwr-list) (cons pwr-list src))
|
||||
())
|
||||
(set (q pwr-iter) (pop rem))))
|
||||
pwr-list)))
|
||||
|
||||
(def display-batteries 'display battery capacity'
|
||||
(lambda ()
|
||||
(let ((bat-iter (pop (_batteries)))
|
||||
(display ""))
|
||||
(while (gt? (len bat-iter) 1)
|
||||
(let ((bat (car bat-iter))
|
||||
(rem (cdr bat-iter))
|
||||
(b-perc (load-to-string head -c -1 (concat bat "/capacity")))
|
||||
(b-cap-raw (load-to-string head -c -1 (concat bat "/energy_full")))
|
||||
(b-cap (div (int b-cap-raw) 1000000)))
|
||||
(set (q display) (concat display "[" b-cap "Wh: " b-perc "%" "]"))
|
||||
(set (q bat-iter) (pop rem))))
|
||||
display)))
|
||||
|
||||
(def getcwd 'gets pwd basename'
|
||||
(lambda ()
|
||||
(let ((cwd (load-to-string pwd))
|
||||
(dir-raw (load-to-string basename cwd))
|
||||
;; pull out newlines
|
||||
(dir (dq (cdr (dq (cdr (dq (split dir-raw ""))))))))
|
||||
(reduce (lambda (x y) (concat x y))
|
||||
(cdr dir)))))
|
||||
|
||||
(def CFG_RELISH_R_PROMPT 'display battery info'
|
||||
()
|
||||
(display-batteries))
|
||||
|
||||
(def CFG_RELISH_L_PROMPT 'display user and dir (git info in future)'
|
||||
()
|
||||
(concat
|
||||
"[" USER "] "
|
||||
(getcwd) " "
|
||||
;; add more prompt elements here
|
||||
))
|
||||
Loading…
Add table
Add a link
Reference in a new issue