rofi-extras/app/rofi-bw.hs

46 lines
1.6 KiB
Haskell
Raw Normal View History

2020-05-01 23:44:36 -04:00
--------------------------------------------------------------------------------
2023-02-13 22:19:49 -05:00
-- rofi-bw - a rofi prompt for a bitwarden vault
2020-05-01 23:44:36 -04:00
--
-- This is basically a wrapper around the 'bw' command, which is assumed to be
-- properly configured before running this command. This shows a system of
-- menus that allows easy lookup of data associated with a vault entry. For now
-- only lookups (no edits or creation) are supported, and only logins can be
-- searched. Any searched entry can be copied to the clipboard
--
-- In order to manage the session keys, this utility is split into a daemon and
-- client (the former holds the session keys between calls with the latter).
-- They communicate via dbus.
--
-- Most of the heavy-lifting code for this executable is in Bitwarden.Internal
-- to allow parts of this greater rofi library to use the DBus API
2020-05-01 23:44:36 -04:00
2020-04-23 23:32:29 -04:00
module Main (main) where
2023-02-13 22:19:49 -05:00
import Bitwarden.Internal
import RIO
import qualified RIO.Text as T
2023-02-22 23:02:04 -05:00
import Rofi.IO
2023-02-22 22:44:44 -05:00
import UnliftIO.Environment
2020-04-23 23:32:29 -04:00
main :: IO ()
2023-02-22 22:44:44 -05:00
main = runSimpleApp $ runChecks >> getArgs >>= parse
2020-04-23 23:32:29 -04:00
2020-05-02 00:13:45 -04:00
-- TODO check if daemon is running when running client
2023-02-22 22:44:44 -05:00
parse :: HasLogFunc c => [String] -> RIO c ()
2023-02-13 22:19:49 -05:00
parse ["-d", t] = case readMaybe t of Just t' -> runDaemon t'; _ -> usage
2023-02-13 23:31:50 -05:00
parse ("-c" : args) = runClient $ fmap T.pack args
2023-02-13 22:19:49 -05:00
parse _ = usage
2020-04-23 23:32:29 -04:00
2023-02-22 22:44:44 -05:00
usage :: (HasLogFunc c, MonadReader c m, MonadUnliftIO m) => m ()
2023-02-13 22:19:49 -05:00
usage =
2023-02-22 22:44:44 -05:00
logInfo $
displayBytesUtf8 $
encodeUtf8 $
T.unlines
[ "daemon mode: rofi-bw -d TIMEOUT"
, "client mode: rofi-bw -c [ROFI-ARGS]"
]
2020-04-23 23:32:29 -04:00
2023-02-22 22:44:44 -05:00
runChecks :: (HasLogFunc c, MonadReader c m, MonadUnliftIO m) => m ()
2023-02-22 23:02:04 -05:00
runChecks = checkExe "bw"