;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*- ;; ;; Copyright (c) 2010-2022 Sameer Rahmani ;; ;; Author: Sameer Rahmani ;; URL: https://devheroes.codes/FG42/FG42 ;; Version: 3.0.0 ;; ;; 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 . ;; ;;; Commentary: ;;; Code: (require 'fg42/modeline) (require 'fg42/statusbar) (defmacro fg42/percentage-face (value err warn) "Return the correct face with repect to VALUE and the given thresholds ERR adn WARN" `(cond ((> ,value ,err) 'error) ((> ,value ,warn) 'warning) (t 'success))) (defbar-unit fg42/statusbar-battery 30 "B--" (format "B%s" (string-trim (with-temp-buffer (insert-file-contents "/sys/class/power_supply/BAT0/capacity") (buffer-string))))) (defbar-unit fg42/statusbar-memory 3 "M--S--" (let* ((struct (string-trim (shell-command-to-string "free -k|tail -n 2|awk '{printf(\"%s,%s,\", $3, $2)}'"))) (vals (mapcar #'cl-parse-integer (butlast (split-string struct ",")))) ;; TODO: Check for division by zero (m (* 100 (/ (float(car vals)) (cadr vals)))) ;; TODO: Check for division by zero (s (* 100 (/ (float(caddr vals)) (cadddr vals)))) (x )) (format "M%sS%s" (propertize (format "%02d" m) 'face (fg42/percentage-face m 90 75)) (propertize (format "%02d" s) 'face (fg42/percentage-face s 90 75))))) (defface fg42/statusbar-project-face '((t :inherit font-lock-type-face :bold t)) "Project name face on status bar" :group 'fg42/statusbar) (defface fg42/statusbar-buffer-name-face '((t :inherit font-lock-variable-name-face)) "Buffer name face on status line" :group 'fg42/statusbar) (defun fg42/statusbar-project-name () (when-flag projectile (projectile-project-name))) (defun fg42/statusbar-buffer-and-project () (format "%s:%s" (propertize (fg42/statusbar-project-name) 'face 'fg42/statusbar-project-face) (propertize (buffer-name) 'face 'fg42/statusbar-buffer-name-face))) ;; (defvar fg42/statusbar-git-branch "-") ;; (defvar fg42/statusbar--last-branch "-") ;; (defun fg42/statusbar-update-git-branch() ;; (message "eeoeeeeee") ;; (setq fg42/statusbar-git-branch ;; (shell-command-to-string "git symbolic-ref --short HEAD"))) ;; (defun fg42/statusbar-setup-git-branch-updater () ;; ;;(add-function :after after-focus-change-function #'fg42/statusbar-update-git-branch) ;; (add-hook 'window-configuration-change-hook (lambda () (message "window-configuration-change-hook"))) ;; (add-hook 'window-state-change-hook (lambda () (message "window-state-change-hook"))) ;; (advice-add :after 'ace-select-window #'fg42/statusbar-update-git-branch) ;; 'fg42/statusbar-git-branch) (defmode-line fg42/statusbar-default (list :brief (list ;;'(buffer-name) ;;'fg42/statusbar-battery "|" '(substring-no-properties (vc-mode vc-mode)) "|" '(fg42/statusbar-buffer-and-project) "|" 'fg42/statusbar-memory "|" '(format-mode-line "%03l:%02c") ;;'(format-time-string "%m-%d %H:%M") ;; (let ((bar (format "%s" fg42/statusbar-memory))) (add-text-properties 0 (string-width bar) (cons 'face (cons '(:size 0.3) (or (get-text-property 0 'face bar) 'default-face))) bar) ;; bar) ) :long " ") ;; No GUI ) ;; The default modeline for FG42 WM that is compatible with ;; the FG42's status bar only (defmode-line fg42/statusbar-default-wm (progn ;; We are in the graphical world (require 'all-the-icons) ;;(format "%s|%s|%s|%s|%s") (list :brief (list ;;'(buffer-name) ;;'fg42/statusbar-battery 'fg42/statusbar-memory '(format-mode-line "%03l:%02c") ;;'(format-time-string "%m-%d %H:%M") ;; (let ((bar (format "%s" fg42/statusbar-memory))) (add-text-properties 0 (string-width bar) (cons 'face (cons '(:size 0.3) (or (get-text-property 0 'face bar) 'default-face))) bar) ;; bar) ) :long " ")) ;; No GUI ) (provide 'fg42/modeline/statusbar-default) ;;; statusbar-default.el ends here