Compare commits

...

2 Commits

Author SHA1 Message Date
Nathan Dwarshuis 54651e2fe9 ADD cache for sudo 2024-08-09 12:09:42 -04:00
Nathan Dwarshuis 442dbafaba FIX typo 2024-08-09 12:08:15 -04:00
4 changed files with 16 additions and 9 deletions

View File

@ -732,9 +732,16 @@ runMountSudoMaybe' useSudo cmd args environ =
-- runSudoMount rootpass cmd args stdin = runSudoMount' rootpass cmd args stdin [] -- runSudoMount rootpass cmd args stdin = runSudoMount' rootpass cmd args stdin []
runSudoMount' :: MonadIO m => T.Text -> T.Text -> [T.Text] -> [(T.Text, T.Text)] -> m MountResult runSudoMount' :: MonadIO m => T.Text -> T.Text -> [T.Text] -> [(T.Text, T.Text)] -> m MountResult
runSudoMount' rootpass cmd args environ = runMount "sudo" args' rootpass runSudoMount' rootpass cmd args environ = do
-- This needs Default timestamp_type=global in sudoers to have any effect
-- since these are all separate shells
isCached <- isJust <$> readCmdSuccess "sudo" ["-n", "true"] ""
if isCached then run else do
cacheSuccess <- isJust <$> readCmdSuccess "sudo" ["-S", "true"] rootpass
if cacheSuccess then run else return $ MountError "Could not cache password"
where where
args' = ["-S"] ++ environ' ++ [cmd] ++ args run = runMount "sudo" args' ""
args' = ["-n"] ++ environ' ++ [cmd] ++ args
environ' = fmap (\(k, v) -> T.concat [k, "=", v]) environ environ' = fmap (\(k, v) -> T.concat [k, "=", v]) environ
eitherToMountResult :: Either (Int, T.Text, T.Text) T.Text -> MountResult eitherToMountResult :: Either (Int, T.Text, T.Text) T.Text -> MountResult

View File

@ -47,7 +47,7 @@ let CIFSData =
, default = , default =
{ cifsSudo = False { cifsSudo = False
, cifsPassword = None PasswordConfig , cifsPassword = None PasswordConfig
, cifsOpts = CIFSOpts::{=} , cifsOpts = Some CIFSOpts::{=}
} }
} }

View File

@ -69,8 +69,8 @@ hotkeyMsg hs = ["-mesg", T.intercalate " | " $ fmap hotkeyMsg1 hs]
hotkeyArgs :: [Hotkey c] -> [T.Text] hotkeyArgs :: [Hotkey c] -> [T.Text]
hotkeyArgs hks = hotkeyArgs hks =
(hotkeyMsg hks) hotkeyMsg hks
++ (concatMap (uncurry hotkeyBinding) $ take 19 $ zip [1 ..] hks) ++ concatMap (uncurry hotkeyBinding) (take 19 $ zip [1 ..] hks)
data RofiMenu c = RofiMenu data RofiMenu c = RofiMenu
{ groups :: ![RofiGroup c] { groups :: ![RofiGroup c]
@ -129,7 +129,7 @@ selectAction rm = do
-- keybindings are labeled 1-19 and thus need to be explicitly -- keybindings are labeled 1-19 and thus need to be explicitly
-- indexed, and the program itself tells the world which key was -- indexed, and the program itself tells the world which key was
-- pressed via return code (any possible integer) -- pressed via return code (any possible integer)
((V.fromList $ hotkeys rm) V.!? (n - 10)) (V.fromList (hotkeys rm) V.!? (n - 10))
runRofi :: (MonadIO m, HasRofiConf c) => c -> RofiMenu c -> m () runRofi :: (MonadIO m, HasRofiConf c) => c -> RofiMenu c -> m ()
runRofi c = runRIO c . selectAction runRofi c = runRIO c . selectAction
@ -171,7 +171,7 @@ readCmdEither'
-> m (Either (Int, T.Text, T.Text) T.Text) -> m (Either (Int, T.Text, T.Text) T.Text)
readCmdEither' cmd args input environ = readCmdEither' cmd args input environ =
resultToEither resultToEither
<$> (liftIO $ readCreateProcessWithExitCode p (T.unpack input)) <$> liftIO (readCreateProcessWithExitCode p (T.unpack input))
where where
e = case environ of e = case environ of
[] -> Nothing [] -> Nothing

View File

@ -16,8 +16,8 @@ notify icon summary body =
liftIO $ liftIO $
void $ void $
spawnProcess "notify-send" $ spawnProcess "notify-send" $
maybe args (\b -> args ++ [b]) $ maybe args ((\b -> args ++ [b]) . T.unpack)
fmap T.unpack body body
where where
args = ["-i", show icon, T.unpack summary] args = ["-i", show icon, T.unpack summary]