packages feed

Hish 0.1.1.0 → 0.1.2.0

raw patch · 6 files changed

+105/−38 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Hish.SysInfo: isRepo :: VCS a => a -> IO Bool
+ Hish.VCS: branchArgs :: VCS a => a -> [String]
+ Hish.VCS: branchCmd :: VCS a => a -> String
+ Hish.VCS: installed :: VCS a => a -> IO Bool
+ Hish.VCS: statusArgs :: VCS a => a -> [String]
+ Hish.VCS: statusCmd :: VCS a => a -> String

Files

ChangeLog.md view
@@ -23,3 +23,8 @@ * [+] show local time * [+] support darcs (incompolete) * [m] wrap/extract printing-functions from main++## 0.1.2.0  -- 2015-10-20++* [m] implement supporting of darcs+* [+] check executability of vcs 
Hish.cabal view
@@ -1,5 +1,5 @@ Name:                   Hish-Version:                0.1.1.0+Version:                0.1.2.0 Author:                 Yun-Yan Chi Maintainer:             jaiyalas@gmail.com License:                BSD3
README.md view
@@ -10,25 +10,26 @@  ### Done ++ [X] Basic ANSI color + [X] show **local time** + [X] show **user name** + [X] show **host name** + [X] show **working directory**   + will be shortened if too long++ [X] support version control system+   + git (fully supported)+   + darcs (darcs has no branch; tracking status is not supported) + [X] show **branch name (git only)**-+ [X] show **index/tree status (git only)**++ [X] show **index/tree status (git and darcs)**   + *\** - dirty   + *?* - clean *but still having untracked files*   + *#* - clean + [X] show **tracking status (git only)**   + *+n* - branch is *ahead* by n   + *-n* - branch is *behind* by n-+ [X] Basic ANSI color-+ [X] support *darcs* (but not implement correctly)  ### Todo -+ [ ] complete darcs supporting + [ ] implement *color theme* + [ ] show *SSH* info + [ ] use *config file*
src/Hish/SysInfo.hs view
@@ -12,6 +12,7 @@   -- ** version control system   , status   , branch+  , isRepo   -- * Primitive functions   , simpleCmd   , argedCmd@@ -19,13 +20,12 @@  import qualified System.Process as SP import System.Exit (ExitCode (..))-import Data.List (lines,unlines)-import Data.Char (isSpace)-import qualified Data.String.Utils as S (split,replace,join)-+import Data.List (lines)+import qualified Data.String.Utils as S (split,replace)+-- import qualified Data.Time.LocalTime as LT (getZonedTime) import Data.Time.Format as TF (formatTime, defaultTimeLocale)-+-- import Hish.VCS  -- | return username@@ -36,6 +36,8 @@ hostname :: IO (Maybe String) hostname = argedCmd (Just . init) "hostname" ["-s"] +{- ========================================== -}+ -- | return current working directory pwd :: Int -- ^ threshold of shortening     -> IO (Maybe String)@@ -53,6 +55,21 @@       ) $ out     otherwise -> return Nothing +-- | concating the given list of name into a path.+-- Notice that, this function will __NOT__ add root, __/__, or home, __~__,+-- to the leftmost position. For example,+--+-- >>> pwdShorten ["A","B","C"]+-- "A/B/C"+--+shortDir :: [String] -- ^ a list of folder name+           -> String+shortDir [] = ""+shortDir [l] = l+shortDir (x:xs) = (head x) : '/' : shortDir xs++{- ========================================== -}+ -- | return time or date for given format -- -- >>> time "%H:%M"@@ -70,19 +87,7 @@ date :: String -> IO String date = time ---- | concating the given list of name into a path.--- Notice that, this function will __NOT__ add root, __/__, or home, __~__,--- to the leftmost position. For example,------ >>> pwdShorten ["A","B","C"]--- "A/B/C"----shortDir :: [String] -- ^ a list of folder name-           -> String-shortDir [] = ""-shortDir [l] = l-shortDir (x:xs) = (head x) : '/' : shortDir xs+{- ========================================== -}  -- | get current status. status :: VCS a => a        -- ^ version control system@@ -90,7 +95,7 @@               Maybe String,               Maybe String) -- ^ (cleanliness, ahead, behind) status vcs = do-   maybeText <- argedCmd (Just . id) "git" ["status","--porcelain","-sb"]+   maybeText <- argedCmd (Just . id) (statusCmd vcs) (statusArgs vcs)    case maybeText of       Nothing -> return          ( Nothing@@ -104,7 +109,17 @@ -- | get current name of git-branch branch :: VCS a => a -- ^ version control system        -> IO (Maybe String)  -- ^ current branch name-branch vcs =  argedCmd (vcsCurrentBranch vcs) "git" ["branch"]+branch vcs =  argedCmd (vcsCurrentBranch vcs) (branchCmd vcs) (branchArgs vcs)++-- | using status to verifying the existence of repository+isRepo :: VCS a => a -> IO Bool+isRepo vcs = do+   (code,_,_) <- exeCmd (statusCmd vcs) (statusArgs vcs) ""+   case code of+      ExitFailure _ -> return False+      ExitSuccess   -> return True++{- ========================================== -}  exeCmd :: String        -> [String]
src/Hish/VCS.hs view
@@ -11,7 +11,7 @@ import Text.Regex.TDFA ((=~)) import qualified Data.String.Utils as S (replace) import qualified Data.List as DL (lines)-+import System.Directory (findExecutable)  -- | Every version control system provides functions as follows --@@ -27,6 +27,16 @@    --       * __*__ - /dirty/    vcsCleanliness :: a -> String -> Maybe String    vcsCurrentBranch :: a -> String -> Maybe String+   -- | get command for revealing branch+   branchCmd :: a -> String+   -- | get arguments for revealing branch+   branchArgs :: a -> [String]+   -- | get command for revealing status+   statusCmd :: a -> String+   -- | get arguments for revealing status+   statusArgs :: a -> [String]+   -- | is this vcs installed (= executable)+   installed :: a -> IO Bool  -- | Unit type for presenting Git. data Git = Git@@ -55,6 +65,17 @@       . head       . filter ((=='*').head)       . lines+   --+   branchCmd  _ = "git"+   branchArgs _ = ["branch"]+   statusCmd  _ = "git"+   statusArgs _ = ["status","--porcelain","-sb"]+   --+   installed _ = do+      ext <- findExecutable "git"+      case ext of+         Nothing -> return False+         Just _  -> return True  -- | Unit type for presenting Darcs. -- /UN-IMPLEMENTED/!@@ -64,7 +85,25 @@    show Darcs = "D"  instance VCS Darcs where-   vcsAhead _ s = return "a"-   vcsBehind _ s = return "b"-   vcsCleanliness _ s = return "?"-   vcsCurrentBranch _ s = return "QQ"+   vcsCleanliness _ ("No changes!") = Just "#"+   vcsCleanliness _ s = let body = map head $ DL.lines s in+      if ((filter (/='a') body)=="") then Just "?" else Just "*"+   -- darcs is so hard to find ahead/behind+   vcsAhead _ s = do+      return ""+   vcsBehind _ s = do+      return ""+   vcsCurrentBranch _ s =+      -- darcs has no the concept of branch+      return ""+   --+   branchCmd Darcs = "darcs"+   branchArgs Darcs = ["whatsnew"]+   statusCmd Darcs = "darcs"+   statusArgs Darcs = ["whatsnew","-l"]+   --+   installed _ = do+      ext <- findExecutable "darcs"+      case ext of+         Nothing -> return False+         Just _  -> return True
src/hish.hs view
@@ -5,8 +5,6 @@ import qualified Hish.VCS as VCS -- for manipulating ANSI code import Data.Monoid (mempty,(<>))--- for checking the existence of vcs-import System.Directory (doesDirectoryExist)  {- +++++++++++++++++++++++++++++++ -- Is this helpful?@@ -24,10 +22,10 @@    printUserInfo    printWorkingTree    putStr " "-   existGit <- doesDirectoryExist ".git"-   if existGit   then printVCSInfo VCS.Git   else return ()-   existDarcs <- doesDirectoryExist "_darcs"-   if existDarcs then printVCSInfo VCS.Darcs else return ()+   --+   safePrintVCS VCS.Git+   safePrintVCS VCS.Darcs+   --    putStr $ applyANSI (_prompt_symbol++" ") $ mempty  --@@ -69,8 +67,17 @@       _ -> putStr ""    case _ah of       Nothing -> return ()-      Just ah -> putStr $ applyANSI ("+"++ah) $ fgRedL <> mempty+      Just ah -> putStr $ applyANSI (if ah=="" then "" else "+"++ah) $ fgRedL <> mempty    case _bh of       Nothing -> return ()-      Just bh -> putStr $ applyANSI ("-"++bh) $ fgGreenL <> mempty+      Just bh -> putStr $ applyANSI (if bh=="" then "" else "-"++bh) $ fgGreenL <> mempty    putStr "]"+--+safePrintVCS :: (Show a, VCS.VCS a) => a -> IO ()+safePrintVCS vcs = do+   b1 <- VCS.installed vcs+   case b1 of+      True -> do+         b2 <- HS.isRepo vcs+         if b2 then printVCSInfo vcs else return ()+      False -> return ()