stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [STUMP] Best of the modelines


From: Sébastien Vauban
Subject: Re: [STUMP] Best of the modelines
Date: Fri, 13 Nov 2009 14:48:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

Hi,

Sébastien Vauban wrote:
> I'd be interested by knowing what awesome feature you've put in your modeline.
>
> I know we can put all the things from contribs, adding colors and information
> like the currently played song; but do you have anything else that's
> interesting and could be shared with us?  Monitoring?  Application or network
> status?  Etc?

I now have this:

--8<---------------cut here---------------start------------->8---
(defun current-date ()
  "Returns the date formatted as `2009-11-12 Thu 17:21:43'."
  (run-shell-command "YMDd=`date '+%F %a'`; HMS=`date '+%H:%M:%S'`; echo -n 
$YMDd ^B$HMS^b" t))

(defun current-ip ()
  "Returns the IP address in CIDR notation."
  (run-shell-command
   "IP_ADDRESS=`ifconfig | grep 'inet addr:' | head -n 1 | sed 
's/.*addr:\\([0-9.]*\\).*/\\1/'`; NETMASK=`ifconfig | grep 'inet addr:' | head 
-n 1 | sed 's/.*Mask:\\([0-9.]*\\).*/\\1/'`; NETWORK=`ipcalc -n -b $IP_ADDRESS 
$NETMASK | grep Network | awk '{print $2}'`; echo -n IP:$IP_ADDRESS`echo 
$NETWORK | sed 's/.*\\(\\/.*\\)/\\1/g' | tr -d '[:cntrl:]'`"
   t))

(defun current-gw ()
  "Returns the default gateway."
  (run-shell-command
   "echo -n Gw:`ip route show | grep default | awk '{print $3}' | tr -d 
'[:cntrl:]'`"
   t))

(setf *screen-mode-line-format*
      (list
       ;; date
       "^6*" '(:eval (current-date))
       ;; cpu | mem | battery
       " | %c %C %f %t | %M | %B"
       ;; ip and gw
       " | " '(:eval (current-ip)) " " '(:eval (current-gw))
       ;; net | wifi
       " | %l | %I"
       '(:eval (run-shell-command "echo" t))
       "^2*" "[^B%n^b] %W%48"))
--8<---------------cut here---------------end--------------->8---

That gives me the current IP address with its mask (in CIDR notation), and the
default gateway.

Though, I must say I would have to check if this whole thing does not take too
much processing power...

Seb

PS- You need to install `ipcalc' for this to work.

-- 
Sébastien Vauban





reply via email to

[Prev in Thread] Current Thread [Next in Thread]