aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrent Yorgey <byorgey@gmail.com>2007-11-27 23:42:58 +0100
committerBrent Yorgey <byorgey@gmail.com>2007-11-27 23:42:58 +0100
commitc9d8c414434c999414a7fdfa4e7e8e245d7049cf (patch)
tree6b05ec37c0a60c4d857bc76d6c084d5e6513c37d
parentf9555524b9c2d7542069d3c5cd8b8ad3d02fd3a5 (diff)
downloadXMonadContrib-c9d8c414434c999414a7fdfa4e7e8e245d7049cf.tar.gz
XMonadContrib-c9d8c414434c999414a7fdfa4e7e8e245d7049cf.tar.xz
XMonadContrib-c9d8c414434c999414a7fdfa4e7e8e245d7049cf.zip
AppendFile: initial import
XMonad.Prompt.AppendFile is a new module which provides a prompt for appending a single line of text to a file. I use it for quickly writing down ideas/todos/etc. to a special file when I can't be bothered to stop what I'm doing to write things down properly. darcs-hash:20071127224258-bd4d7-6695475026c9032a5f007ef924abb7dd3334181e.gz
-rw-r--r--XMonad/Prompt/AppendFile.hs66
-rw-r--r--xmonad-contrib.cabal1
2 files changed, 67 insertions, 0 deletions
diff --git a/XMonad/Prompt/AppendFile.hs b/XMonad/Prompt/AppendFile.hs
new file mode 100644
index 0000000..9493d15
--- /dev/null
+++ b/XMonad/Prompt/AppendFile.hs
@@ -0,0 +1,66 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonad.Prompt.AppendFile
+-- Copyright : (c) 2007 Brent Yorgey
+-- License : BSD-style (see LICENSE)
+--
+-- Maintainer : <byorgey@gmail.com>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- A prompt for appending a single line of text to a file. Useful for
+-- keeping a file of notes, things to remember for later, and so on---
+-- using a keybinding, you can write things down just about as quickly
+-- as you think of them, so it doesn't have to interrupt whatever else
+-- you're doing.
+--
+-- Who knows, it might be useful for other purposes as well!
+--
+-----------------------------------------------------------------------------
+
+module XMonad.Prompt.AppendFile (
+ -- * Usage
+ -- $usage
+
+ appendFilePrompt
+ ) where
+
+import XMonad.Core
+import XMonad.Prompt
+
+import System.IO
+import Control.Exception
+
+-- $usage
+--
+-- You can use this module by importing it, along with
+-- "XMonad.Prompt", into your ~\/.xmonad\/xmonad.hs file:
+--
+-- > import XMonad.Prompt
+-- > import XMonad.Prompt.AppendFile
+--
+-- and adding an appropriate keybinding, for example:
+--
+-- > , ((modMask x .|. controlMask, xK_n), appendFilePrompt defaultXPConfig "/home/me/NOTES")
+--
+-- For detailed instructions on editing your key bindings, see
+-- "XMonad.Doc.Extending#Editing_key_bindings".
+
+data AppendFile = AppendFile FilePath
+
+instance XPrompt AppendFile where
+ showXPrompt (AppendFile fn) = "Add to " ++ fn ++ ": "
+
+-- | Given an XPrompt configuration and a file path, prompt the user
+-- for a line of text, and append it to the given file.
+appendFilePrompt :: XPConfig -> FilePath -> X ()
+appendFilePrompt c fn = mkXPrompt (AppendFile fn)
+ c
+ (const (return []))
+ (doAppend fn)
+
+-- | Append a string to a file.
+doAppend :: FilePath -> String -> X ()
+doAppend fn s = io $ bracket (openFile fn AppendMode)
+ hClose
+ (flip hPutStrLn s)
diff --git a/xmonad-contrib.cabal b/xmonad-contrib.cabal
index 601ef0d..587f9d5 100644
--- a/xmonad-contrib.cabal
+++ b/xmonad-contrib.cabal
@@ -122,6 +122,7 @@ library
XMonad.Prompt.Window
XMonad.Prompt.Workspace
XMonad.Prompt.XMonad
+ XMonad.Prompt.AppendFile
XMonad.Util.Anneal
XMonad.Util.CustomKeys
XMonad.Util.Dmenu