stumpwm-devel
[Top][All Lists]
Advanced

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

Re: [STUMP] Sharing .stumpwmrc between computers


From: yggdrasil
Subject: Re: [STUMP] Sharing .stumpwmrc between computers
Date: Thu, 01 Dec 2011 01:08:13 +0100

> From: Stefan Reichör

> The following seems to work for me (assuming /etc/hostname holds the host 
> name)
> 
> (defun system-name ()
>  (with-open-file (hostname-file "/etc/hostname" :direction :input) (read 
> hostname-file)))

Thanks for a fast reply Stefan! This put me on track, but for a non-lisper it 
took some time to get it working... I sit on Fedora 16, so the hostname is in 
/etc/sysconfig/network as:

NETWORKING=yes
HOSTNAME=thehostname

I couldn't figure how to extract this in lisp (I never got 'read' to work and 
used 'read-line' which returns the full first line), but am sure some regex may 
do. Instead I resorted to 'run-shell-command' with 'hostname'. This returned 
the name with some junk on the end (nil? newline?), so I stripped it and that 
did the final trick. I am sure there may be more elegant ways to do this, but 
here's the code I got working;

;; Get system name (the last character is junk, probably a newline or nil, so 
crop it)
(defun system-name ()
  (let ((sysname (run-shell-command "hostname" t))) (subseq sysname 0 (- 
(length sysname) 1)))
  )

;; For testing, display the system-name if the system name is recognised as 
expected
(defcommand display-system-name () ()
  (when (string= (system-name) "thehostname")
      (echo-string (current-screen) (system-name)))
  )

;; Define a key shortcut to test retrieval and display of system-name
(define-key *root-map* (kbd "M-r")
"display-system-name"
)    

Again, many thanks!

Johnny



reply via email to

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