<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Prompt.Directory
-- Copyright   :  (C) 2007 <NAME>, <NAME>
-- License     :  BSD3
--
-- Maintainer  :
-- Stability   :  unstable
-- Portability :  unportable
--
-- A directory prompt for XMonad
--
-----------------------------------------------------------------------------

module XMonad.Prompt.Directory (
                             -- * Usage
                             -- $usage
                             directoryPrompt,
                             directoryPrompt',
                             directoryMultipleModes,
                             Dir
                              ) where

import XMonad
import XMonad.Prompt
import XMonad.Prompt.Shell ( compgenDirectories )

-- $usage
-- For an example usage see "XMonad.Layout.WorkspaceDir"

data Dir = Dir String (String -> X ())

instance XPrompt Dir where
    showXPrompt (Dir x _) = x
    completionFunction _ = getDirCompl (ComplCaseSensitive True)
    modeAction (Dir _ f) buf auto =
      let dir = if null auto then buf else auto
      in f dir

directoryPrompt :: XPConfig -> String -> (String -> X ()) -> X ()
directoryPrompt = directoryPrompt' (ComplCaseSensitive True)

directoryPrompt' :: ComplCaseSensitivity -> XPConfig -> String -> (String -> X ()) -> X ()
directoryPrompt' csn c prom f = mkXPrompt (Dir prom f) c (getDirCompl csn) f

-- | A @XPType@ entry suitable for using with @mkXPromptWithModes@.
directoryMultipleModes :: String            -- ^ Prompt.
                       -> (String -> X ())  -- ^ Action.
                       -> XPType
directoryMultipleModes p f = XPT (Dir p f)

getDirCompl :: ComplCaseSensitivity -> String -> IO [String]
getDirCompl csn s = filter notboring . lines <$> compgenDirectories csn s

notboring :: String -> Bool
notboring ('.':'.':_) = True
notboring ('.':_) = False
notboring _ = True
<commit_msg>Dir: ComplCaseSensitivity field (breaking change)<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Prompt.Directory
-- Copyright   :  (C) 2007 <NAME>, <NAME>
-- License     :  BSD3
--
-- Maintainer  :
-- Stability   :  unstable
-- Portability :  unportable
--
-- A directory prompt for XMonad
--
-----------------------------------------------------------------------------

module XMonad.Prompt.Directory (
                             -- * Usage
                             -- $usage
                             directoryPrompt,
                             directoryPrompt',
                             directoryMultipleModes,
                             directoryMultipleModes',
                             Dir
                              ) where

import XMonad
import XMonad.Prompt
import XMonad.Prompt.Shell ( compgenDirectories )

-- $usage
-- For an example usage see "XMonad.Layout.WorkspaceDir"

data Dir = Dir String ComplCaseSensitivity (String -> X ())

instance XPrompt Dir where
    showXPrompt (Dir x _ _) = x
    completionFunction (Dir _ csn _) = getDirCompl csn
    modeAction (Dir _ _ f) buf auto =
      let dir = if null auto then buf else auto
      in f dir

directoryPrompt :: XPConfig -> String -> (String -> X ()) -> X ()
directoryPrompt = directoryPrompt' (ComplCaseSensitive True)

directoryPrompt' :: ComplCaseSensitivity -> XPConfig -> String -> (String -> X ()) -> X ()
directoryPrompt' csn c prom f = mkXPrompt (Dir prom csn f) c (getDirCompl csn) f

-- | A @XPType@ entry suitable for using with @mkXPromptWithModes@.
directoryMultipleModes :: String            -- ^ Prompt.
                       -> (String -> X ())  -- ^ Action.
                       -> XPType
directoryMultipleModes = directoryMultipleModes' (ComplCaseSensitive True)

-- | Like @directoryMultipleModes@ with a parameter for completion case-sensitivity.
directoryMultipleModes' :: ComplCaseSensitivity -- ^ Completion case sensitivity.
                        -> String               -- ^ Prompt.
                        -> (String -> X ())     -- ^ Action.
                        -> XPType
directoryMultipleModes' csn p f = XPT (Dir p csn f)

getDirCompl :: ComplCaseSensitivity -> String -> IO [String]
getDirCompl csn s = filter notboring . lines <$> compgenDirectories csn s

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

{'fraction_non_alphanumeric': 0.16926906539941164, 'fraction_numerical': 0.0022629554197782305, 'mean_word_length': 1.5534373194685154, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5971086', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1155, 'n_words': 339}