[Emacs] Add function `phundrak/file-to-string', remove shell command

Add function `phundrak/file-to-string' which reads the content of a
file to a string.

Eshell banner makes one less shell command and makes it a bit more
distro-agnostic, although still very Linux-centered.
This commit is contained in:
Lucien Cartier-Tilet 2021-02-04 14:44:07 +01:00
parent 527380e5ff
commit 95a16788e7
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -1620,6 +1620,18 @@ giggles, Ive made it so it is a powerline prompt.
:foreground accent))))) :foreground accent)))))
#+END_SRC #+END_SRC
*** ~phundrak/file-to-string~
:PROPERTIES:
:CUSTOM_ID: User-Configuration-Custom-functions-macros-and-variables-phundrak-file-to-string-efab0fba
:END:
#+BEGIN_SRC emacs-lisp
(defun phundrak/file-to-string (FILE)
"Returns the content of `FILE' as a string"
(with-temp-buffer
(insert-file-contents FILE)
(buffer-string)))
#+END_SRC
*** ~phundrak/find-org-files~ *** ~phundrak/find-org-files~
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: Custom-functions-phundrak-find-org-files-a8fd200f :CUSTOM_ID: Custom-functions-phundrak-find-org-files-a8fd200f
@ -2182,6 +2194,12 @@ And we can now build our banner! Here is our function that does exactly that:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun phundrak/eshell-banner () (defun phundrak/eshell-banner ()
(let* ((partitions (phundrak/get-mounted-partitions)) (let* ((partitions (phundrak/get-mounted-partitions))
(os (replace-regexp-in-string
".*\"\\(.+\\)\""
"\\1"
(car (-filter (lambda (line)
(s-contains? "PRETTY_NAME" line))
(s-lines (phundrak/file-to-string "/etc/os-release"))))))
(memory (-map (lambda (line) (memory (-map (lambda (line)
(s-split " " line t)) (s-split " " line t))
(s-split "\n" (s-split "\n"
@ -2199,8 +2217,7 @@ And we can now build our banner! Here is our function that does exactly that:
(s-pad-right left-pad "." "OS") (s-pad-right left-pad "." "OS")
(s-pad-right left-column-width (s-pad-right left-column-width
" " " "
(with-face (s-replace "\"" "" (with-face (s-trim os)
(s-trim (shell-command-to-string "lsb_release -sd")))
:weight 'bold)) :weight 'bold))
(s-pad-right right-pad "." "Kernel") (s-pad-right right-pad "." "Kernel")
(with-face (concat "Linux " operating-system-release) (with-face (concat "Linux " operating-system-release)