From 95a16788e763e43c7d037b04ec2cde445435255d Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Thu, 4 Feb 2021 14:44:07 +0100 Subject: [PATCH] [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. --- org/config/emacs.org | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/org/config/emacs.org b/org/config/emacs.org index 986a6f4..cff97e0 100644 --- a/org/config/emacs.org +++ b/org/config/emacs.org @@ -1620,6 +1620,18 @@ giggles, I’ve made it so it is a powerline prompt. :foreground accent))))) #+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~ :PROPERTIES: :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 (defun phundrak/eshell-banner () (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) (s-split " " line t)) (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-column-width " " - (with-face (s-replace "\"" "" - (s-trim (shell-command-to-string "lsb_release -sd"))) + (with-face (s-trim os) :weight 'bold)) (s-pad-right right-pad "." "Kernel") (with-face (concat "Linux " operating-system-release)