Hish 0.1.0.1 → 0.1.1.0
raw patch · 6 files changed
+116/−40 lines, 6 filesdep +directorydep +timedep ~MissingHdep ~basedep ~processPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: directory, time
Dependency ranges changed: MissingH, base, process, regex-tdfa
API changes (from Hackage documentation)
- Hish.SysInfo: shortDir :: [String] -> String
+ Hish.SysInfo: date :: String -> IO String
+ Hish.SysInfo: time :: String -> IO String
+ Hish.VCS: instance GHC.Show.Show Hish.VCS.Darcs
+ Hish.VCS: instance GHC.Show.Show Hish.VCS.Git
Files
- ChangeLog.md +21/−1
- Hish.cabal +13/−9
- README.md +3/−2
- src/Hish/SysInfo.hs +28/−3
- src/Hish/VCS.hs +7/−0
- src/hish.hs +44/−25
ChangeLog.md view
@@ -2,4 +2,24 @@ ## 0.0.1 -- 2015-10-16 -* First version. Released on an unsuspecting world.+* [+] show index/tree status (git only)+* [+] show branch name (git only)+* [+] show working tree (shortenable)++## 0.1.0 -- 2015-10-20++* [+] show user name+* [+] show host name+* [+] show tracking status (git only)+* [+] support ANSI color+* [m] improve index/tree status (git only)++## 0.1.0.1 -- 2015-10-20++* *none* (fixing version-number only)++## 0.1.1.0 -- 2015-10-20++* [+] show local time+* [+] support darcs (incompolete)+* [m] wrap/extract printing-functions from main
Hish.cabal view
@@ -1,5 +1,5 @@ Name: Hish-Version: 0.1.0.1+Version: 0.1.1.0 Author: Yun-Yan Chi Maintainer: jaiyalas@gmail.com License: BSD3@@ -20,10 +20,12 @@ default-language: Haskell2010 hs-source-dirs: src ghc-options: -w- build-depends: base >= 4 && < 5- , MissingH >= 1.2- , process >= 1.2- , regex-tdfa >= 1.2+ build-depends: base >= 4.8 && < 5+ , MissingH >= 1.3.0 && < 1.4+ , process >= 1.3.0 && < 1.4+ , regex-tdfa >= 1.2.1 && < 1.3+ , time >= 1.5.0 && < 1.6+ , directory >= 1.2.2 && < 1.3 exposed-modules: Hish.ANSICode Hish.SysInfo@@ -35,10 +37,12 @@ hs-source-dirs: src main-is: hish.hs ghc-options: -w- build-depends: base >= 4 && < 5- , MissingH >= 1.2- , process >= 1.2- , regex-tdfa >= 1.2+ build-depends: base >= 4.8 && < 5+ , MissingH >= 1.3.0 && < 1.4+ , process >= 1.3.0 && < 1.4+ , regex-tdfa >= 1.2.1 && < 1.3+ , time >= 1.5.0 && < 1.6+ , directory >= 1.2.2 && < 1.3 -- Source-Repository head Type: git
README.md view
@@ -10,6 +10,7 @@ ### Done ++ [X] show **local time** + [X] show **user name** + [X] show **host name** + [X] show **working directory**@@ -23,11 +24,11 @@ + *+n* - branch is *ahead* by n + *-n* - branch is *behind* by n + [X] Basic ANSI color++ [X] support *darcs* (but not implement correctly) ### Todo -+ [ ] support *darcs*-+ [ ] show *time*++ [ ] complete darcs supporting + [ ] implement *color theme* + [ ] show *SSH* info + [ ] use *config file*
src/Hish/SysInfo.hs view
@@ -1,11 +1,15 @@ module Hish.SysInfo (- -- * Get basic information+ -- * Basic information+ -- ** name uid , hostname+ -- ** working directory , pwd- , shortDir- -- * Get VCS-related information+ -- ** time and date+ , time+ , date+ -- ** version control system , status , branch -- * Primitive functions@@ -19,6 +23,9 @@ import Data.Char (isSpace) import qualified Data.String.Utils as S (split,replace,join) +import qualified Data.Time.LocalTime as LT (getZonedTime)+import Data.Time.Format as TF (formatTime, defaultTimeLocale)+ import Hish.VCS -- | return username@@ -45,6 +52,24 @@ . filter (/='\n') ) $ out otherwise -> return Nothing++-- | return time or date for given format+--+-- >>> time "%H:%M"+-- 13:15+--+-- >>> time "%Y-%b-%d"+-- 2015-Oct-20+time :: String -- ^ format (read "Data.Time.Format" for more detail)+ -> IO String+time format = do+ ztime <- LT.getZonedTime+ return $ TF.formatTime TF.defaultTimeLocale format ztime++-- | just an alias of 'time'+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, __~__,
src/Hish/VCS.hs view
@@ -31,6 +31,9 @@ -- | Unit type for presenting Git. data Git = Git +instance Show Git where+ show Git = "G"+ instance VCS Git where vcsAhead _ s = case (s =~ "ahead [0-9]+" :: String) of@@ -57,7 +60,11 @@ -- /UN-IMPLEMENTED/! data Darcs = Darcs +instance Show Darcs where+ show Darcs = "D"+ instance VCS Darcs where vcsAhead _ s = return "a" vcsBehind _ s = return "b" vcsCleanliness _ s = return "?"+ vcsCurrentBranch _ s = return "QQ"
src/hish.hs view
@@ -3,55 +3,74 @@ import Hish.ANSICode import qualified Hish.SysInfo as HS 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?+import System.Environment (getEnv -- String -> IO String+ ,setEnv -- String -> String -> IO ()+ ,lookupEnv -- String -> IO (Maybe String)+ )++++++++++++++++++++++++++++++++ -}+ _prompt_symbol = ">" _pwdWidth = 60 main :: IO () main = do+ 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 ()+ putStr $ applyANSI (_prompt_symbol++" ") $ mempty++--+printUserInfo :: IO ()+printUserInfo = do+ _ts <- HS.time "%H:%M"+ putStr $ applyANSI (_ts) $ fgBlackL <> mempty+ putStr $ applyANSI "(" $ fgBlackL <> mempty _un <- HS.uid case _un of Nothing -> return ()- Just un -> putStr $ applyANSI un $ fgBlackL <> mempty- --- _hn <- HS.hostname- case _hn of- Nothing -> return ()- Just hn -> putStr $ applyANSI ("@"++hn) $ fgBlackL <> mempty- --- putStr " "+ Just un -> putStr $ applyANSI (un) $ mempty+ putStr $ applyANSI ")" $ fgBlackL <> mempty+ -- _hn <- HS.hostname+ -- case _hn of+ -- Nothing -> return ()+ -- Just hn -> putStr $ applyANSI ("@"++hn) $ fgBlackL <> mempty+--+printWorkingTree :: IO ()+printWorkingTree = do _wd <- HS.pwd _pwdWidth case _wd of Nothing -> return () Just wd -> putStr $ applyANSI wd $ fgGreen <> mempty- --- putStr " "- --+--+printVCSInfo :: (Show a, VCS.VCS a) => a -> IO ()+printVCSInfo vcs = do+ _br <- HS.branch vcs+ (_st, _ah, _bh) <- HS.status vcs+ putStr $ show vcs putStr "["- --- _br <- HS.branch VCS.Git case _br of- Nothing -> return () Just br -> putStr $ applyANSI br $ fgWhiteL <> ESC_Bold <> mempty- (_st, _ah, _bh) <- HS.status VCS.Git- --+ Nothing -> return () case _st of Just "*" -> putStr $ applyANSI "*" $ ESC_Bold <> fgRed <> mempty Just "?" -> putStr $ applyANSI "?" $ ESC_Bold <> fgYellow <> mempty Just "#" -> putStr $ applyANSI "#" $ ESC_Bold <> fgGreen <> mempty _ -> putStr ""- -- case _ah of Nothing -> return () Just ah -> putStr $ applyANSI ("+"++ah) $ fgRedL <> mempty- --- case _ah of+ case _bh of Nothing -> return ()- Just ah -> putStr $ applyANSI ("-"++ah) $ fgGreenL <> mempty- --+ Just bh -> putStr $ applyANSI ("-"++bh) $ fgGreenL <> mempty putStr "]"- --- putStr $ applyANSI (_prompt_symbol++" ") $ mempty