Save *input-history* on quitting StumpWM and reloading it again on start (#93)

Add Command History module
This commit is contained in:
Arjen Dijkstra 2018-01-18 04:04:17 +01:00 committed by Javier Olaechea
parent de3ce80c23
commit 81f64c8fb9
5 changed files with 63 additions and 0 deletions

View file

@ -78,3 +78,4 @@ to the world!
- [[./util/windowtags/README.org][windowtags]]
- [[./util/kbd-layouts/README.org][kbd-layouts]]
- [[./util/pinentry/README.org][pinentry]]
- [[./util/command-history/README.org][command-history]]

View file

@ -0,0 +1,13 @@
# command-history
*** Problem
After quiting StumpWM, you command history is gone.
This simple plugin saves the lisp =stumpwm::*input-history*= to =~/.stumpwm.d/history= and loads it again when starting StumpWM.
** Usage
Add this to your =.stumpwmrc=:
Load contrib module:
#+BEGIN_SRC lisp
(load-module "command-history")
#+END_SRC

View file

@ -0,0 +1,11 @@
;;;; command-history.asd
(asdf:defsystem #:command-history
:description "Save and load the stumpwm::*input-history* to a file"
:author "Arjen Dijkstra"
:license "GPLv3"
:version "0.0.1"
:serial t
:depends-on (#:stumpwm)
:components ((:file "package")
(:file "command-history")))

View file

@ -0,0 +1,34 @@
;;;; command-history.lisp
(in-package #:command-history)
(export '(*start-hook*
*quit-hook*))
(defvar *home-dir* (getenv "HOME"))
(defvar *command-history-file*
(merge-pathnames
(format nil "~A/.stumpwm.d/history" *home-dir*)))
(defun load-input-history ()
"Load *input-history* to file."
(with-open-file (in *command-history-file* :if-does-not-exist nil)
(when in
(with-standard-io-syntax
(setf stumpwm::*input-history* (read in))))))
(defun save-input-history ()
"Save current *input-history* to file."
(with-open-file (out *command-history-file*
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(with-standard-io-syntax
(print
(remove-duplicates stumpwm::*input-history* :test #'string= :from-end t)
out))))
(add-hook *start-hook* 'load-input-history)
(add-hook *quit-hook* 'save-input-history)

View file

@ -0,0 +1,4 @@
;;;; package.lisp
(defpackage #:command-history
(:use #:cl :stumpwm))