-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Prompt.File
-- Copyright   :  (C) 2007 Andrea Rossato, David Roundy
-- License     :  BSD3
--
-- Maintainer  :
-- Stability   :  unstable
-- Portability :  unportable
--
-- A file prompt for XMonad
--
-----------------------------------------------------------------------------

module XMonad.Prompt.File (
                             -- * Usage
                             -- $usage
                             filePrompt
                              ) where

import XMonad
import XMonad.Prompt
import XMonad.Util.Run ( runProcessWithInput )

-- $usage
-- Works the same as XMonad.Prompt.Directory. For an example usage see "XMonad.Layout.WorkspaceDir"

data File = File String

instance XPrompt File where
    showXPrompt (File x) = x

filePrompt :: XPConfig -> String -> (String -> X ()) -> X ()
filePrompt c prom = mkXPrompt (File prom) c getFileCompl

getFileCompl :: String -> IO [String]
getFileCompl s = (filter notboring . lines) `fmap`
                 runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n")

notboring :: String -> Bool
notboring ('.':'.':_) = True
notboring ('.':_) = False
notboring _ = True
