packages feed

greenclip 4.2.0 → 4.3.0

raw patch · 2 files changed

+22/−2 lines, 2 filesdep +base16-bytestringdep +cryptohash-md5

Dependencies added: base16-bytestring, cryptohash-md5

Files

greenclip.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           greenclip-version:        4.2.0+version:        4.3.0 synopsis:       Simple clipboard manager to be integrated with rofi description:    Simple clipboard manager to be integrated with rofi - Please see README.md category:       Linux Desktop@@ -40,6 +40,8 @@     , directory     , wordexp     , tomland+    , base16-bytestring+    , cryptohash-md5     , X11 >= 1.6   other-modules:       Clipboard
src/Main.hs view
@@ -14,10 +14,14 @@ import           Protolude.Conv        (toS)  import           Control.Monad.Catch   (MonadCatch, catchAll)+import qualified Crypto.Hash.MD5       as H import           Data.Binary           (decodeFile, encode) import qualified Data.ByteString       as B+import qualified Data.ByteString.Base16 as BB+import qualified Data.ByteString.Char8 as BC import           Data.List             (dropWhileEnd) import qualified Data.Text             as T+import qualified Data.Text.Encoding    as TE import           Data.Vector           (Vector) import qualified Data.Vector           as V import           Lens.Micro@@ -36,7 +40,7 @@ import qualified Clipboard             as Clip  -data Command = DAEMON | PRINT | COPY Text | CLEAR | HELP deriving (Show, Read)+data Command = DAEMON | PRINT | COPY Text | CLEAR | PRUNE FilePath | HELP deriving (Show, Read)  data Config = Config   { maxHistoryLength           :: Int@@ -92,6 +96,17 @@     writeH storePath = B.writeFile storePath . toS . encode . V.toList  +pruneHistory :: (MonadIO m, MonadReader Config m) => FilePath -> m ()+pruneHistory path = do+  targets <- liftIO $ BC.lines <$> readFile path+  history <- getHistory+  storeHistory $ V.filter (go targets) history+  where+    go ts (Clip.Selection _ (Clip.UTF8 x)) = hashText x `notElem` ts+    go _  _                                = False+    hashText = BB.encode . H.hash . TE.encodeUtf8++ appendToHistory :: (MonadIO m, MonadReader Config m) => Clip.Selection -> ClipHistory -> m (ClipHistory, ClipHistory) appendToHistory sel history' = do   trimSelection <- view $ to trimSpaceFromSelection@@ -289,6 +304,7 @@ parseArgs :: [Text] -> Command parseArgs ("daemon":_)   = DAEMON parseArgs ["clear"]      = CLEAR+parseArgs ["prune", p]   = PRUNE $ T.unpack p parseArgs ["print"]      = PRINT parseArgs ["print", sel] = COPY sel parseArgs _              = HELP@@ -300,6 +316,7 @@     DAEMON   -> runReaderT runDaemon cfg     PRINT    -> runReaderT printHistoryForRofi cfg     CLEAR    -> runReaderT (storeHistory mempty) cfg+    PRUNE p  -> runReaderT (pruneHistory p) cfg     -- Should rename COPY into ADVERTISE but as greenclip is already used I don't want to break configs     -- of other people     COPY sel -> runReaderT (advertiseSelection sel) cfg@@ -307,6 +324,7 @@                           "Available commands\n" <>                           "daemon: Spawn the daemon that will listen to selections\n" <>                           "print:  Display all selections history\n" <>+                          "prune FILE: Remove selections in list of md5 hashes in FILE\n" <>                           "clear:  Clear history\n" <>                           "help:   Display this message\n"