Commits

Colin Woodbury committed 642d6bf

pacman-color problems sorted out - Should fix #42

- Goes like this:
Is $PACMAN set?
-> Take its value.
No? Is pacman-color installed?
-> Use pacman-color.
No?
-> Use pacman.

  • Participants
  • Parent commits 4975fb0

Comments (0)

Files changed (2)

File Aura/Pacman.hs

 defaultCmd :: String
 defaultCmd = "pacman"
 
+pacmanColorCmd :: String
+pacmanColorCmd = "pacman-color"
+
 pacmanConfFile :: FilePath
 pacmanConfFile = "/etc/pacman.conf"
 
 packageCacheContents c = filter dots `liftM` ls c
     where dots p = p `notElem` [".",".."]
 
-getPacmanCmd :: Environment -> Pacman
-getPacmanCmd env = case getEnvVar "PACMAN" env of
-                     Nothing  -> pacmanCmd defaultCmd
-                     Just cmd -> pacmanCmd cmd
+-- I'm sad that I had to make this Monadic. And a lot uglier.
+getPacmanCmd :: Environment -> IO Pacman
+getPacmanCmd env = pacmanCmd `liftM` getPacmanCmd' env
+
+getPacmanCmd' :: Environment -> IO String
+getPacmanCmd' env = case getEnvVar "PACMAN" env of
+                     Just cmd -> return cmd
+                     Nothing  -> do
+                       installed <- pacmanSuccess ["-Qq",pacmanColorCmd]
+                       if installed
+                          then return pacmanColorCmd
+                          else return defaultCmd
 
 getPacmanConf :: IO String
 getPacmanConf = readFile pacmanConfFile
       auraFlags' = filter (`notElem` settingsFlags) auraFlags
       pacOpts'   = pacOpts ++ reconvertFlags auraFlags dualFlagMap
   settings <- getSettings language auraFlags
-  unless (Debug `notElem` auraFlags) $ displaySettings settings
+  unless (Debug `notElem` auraFlags) $ debugOutput settings
   exitStatus <- executeOpts settings (auraFlags', nub input, nub pacOpts')
   exitWith exitStatus
 
 getSettings lang auraFlags = do
   confFile    <- getPacmanConf
   environment <- getEnvironment
+  pmanCommand <- getPacmanCmd environment
   return $ Settings { environmentOf   = environment
                     , langOf          = lang
-                    , pacman          = getPacmanCmd environment
+                    , pacman          = pmanCommand
                     , ignoredPkgsOf   = getIgnoredPkgs confFile
                     , cachePathOf     = getCachePath confFile
                     , logFilePathOf   = getLogFilePath confFile
                     , mustConfirm     = getConfirmation auraFlags
                     , mayHotEdit      = getHotEdit auraFlags }
 
-displaySettings :: Settings -> IO ()
-displaySettings ss = do
+debugOutput :: Settings -> IO ()
+debugOutput ss = do
   let yn a = if a then "Yes!" else "No."
       env  = environmentOf ss
-      pac  = case getEnvVar "PACMAN" env of Nothing -> "pacman"; Just c -> c
+  pmanCommand <- getPacmanCmd' env
   mapM_ putStrLn [ "User              => " ++ getUser' env
                  , "True User         => " ++ getTrueUser env
                  , "Using Sudo?       => " ++ yn (varExists "SUDO_USER" env)
                  , "Language          => " ++ show (langOf ss)
-                 , "Pacman Command    => " ++ pac
+                 , "Pacman Command    => " ++ pmanCommand
                  , "Ignored Pkgs      => " ++ unwords (ignoredPkgsOf ss)
                  , "Pkg Cache Path    => " ++ cachePathOf ss
                  , "Log File Path     => " ++ logFilePathOf ss