git-brunch 1.0.2.0 → 1.0.3.0
raw patch · 4 files changed
+55/−48 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- GitBrunch: Local :: Name
- GitBrunch: Remote :: Name
- GitBrunch: State :: Name -> List Name Branch -> List Name Branch -> State
- GitBrunch: [_focus] :: State -> Name
- GitBrunch: [_localBranches] :: State -> List Name Branch
- GitBrunch: [_remoteBranches] :: State -> List Name Branch
- GitBrunch: app :: App State e Name
- GitBrunch: appDraw :: State -> [Widget Name]
- GitBrunch: appHandleEvent :: State -> BrickEvent Name e -> EventM Name (Next State)
- GitBrunch: data Name
- GitBrunch: data State
- GitBrunch: drawBranchList :: Bool -> List Name Branch -> Widget Name
- GitBrunch: drawInstruction :: String -> String -> Widget n
- GitBrunch: drawListElement :: Bool -> Branch -> Widget Name
- GitBrunch: focusBranches :: Name -> State -> State
- GitBrunch: focusL :: Lens' State Name
- GitBrunch: focussedBranchesL :: Lens' State (List Name Branch)
- GitBrunch: initialState :: [Branch] -> State
- GitBrunch: localBranchesL :: Lens' State (List Name Branch)
- GitBrunch: navigate :: State -> Event -> EventM Name (Next State)
- GitBrunch: remoteBranchesL :: Lens' State (List Name Branch)
- GitBrunch: selectedBranch :: State -> Maybe Branch
Files
- README.md +21/−7
- git-brunch.cabal +12/−7
- src/Git.hs +6/−7
- src/GitBrunch.hs +16/−27
README.md view
@@ -4,26 +4,40 @@  +## Usage++Run `git-brunch` or `git brunch`.++## Git alias (optional)++```sh+git config --global alias.b brunch+```+ ## Installation -### Binary+### Download binary -Download from [releases](https://github.com/andys8/git-brunch/releases) and add to `PATH`.+Download from [releases](https://github.com/andys8/git-brunch/releases), rename to `git-brunch` and add to `PATH`. -### Stack+### Install with `stack` ```sh stack install --resolver=lts-14 git-brunch ``` -### From source+### Clone and install with `nix` ```sh git clone https://github.com/andys8/git-brunch.git cd git-brunch-stack install+nix-env -if default.nix ``` -## Usage+### Clone and install with `stack` from source -Run `git-brunch` or `git brunch`.+```sh+git clone https://github.com/andys8/git-brunch.git+cd git-brunch+stack install+```
git-brunch.cabal view
@@ -1,14 +1,16 @@-cabal-version: 1.12+cabal-version: 2.0 -- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: d70efa64b6a528e6d0a5907b591f7fa5b06d5bcb4e5bfcf949728db4d69a87e8+-- hash: 7c82c894fbea0ccfeedcbfed2d569c22a055ae960da4e1df61049777feaa0671 name: git-brunch-version: 1.0.2.0+version: 1.0.3.0+synopsis: git checkout command-line tool description: Please see the README on GitHub at <https://github.com/andys8/git-brunch#readme>+category: Git homepage: https://github.com/andys8/git-brunch#readme bug-reports: https://github.com/andys8/git-brunch/issues author: andys8@@ -24,7 +26,7 @@ type: git location: https://github.com/andys8/git-brunch -library+library git-brunch-lib exposed-modules: Git GitBrunch@@ -33,6 +35,7 @@ Paths_git_brunch hs-source-dirs: src+ ghc-options: -Wall build-depends: base >=4.7 && <5 , brick@@ -46,13 +49,15 @@ main-is: Main.hs other-modules: Paths_git_brunch+ autogen-modules:+ Paths_git_brunch hs-source-dirs: app- ghc-options: -threaded -O2 -rtsopts -with-rtsopts=-N+ ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 , brick- , git-brunch+ , git-brunch-lib , microlens , process , vector@@ -70,7 +75,7 @@ build-depends: base >=4.7 && <5 , brick- , git-brunch+ , git-brunch-lib , microlens , process , vector
src/Git.hs view
@@ -8,7 +8,6 @@ import System.Process import Data.List import Data.Char ( isSpace )-import Data.Either import System.Exit data Branch = BranchLocal String@@ -39,10 +38,10 @@ toBranches input = filter (not . isHead) $ toBranch <$> lines input toBranch :: String -> Branch-toBranch line = toBranch $ head $ words $ drop 2 line+toBranch line = toBranch' $ head $ words $ drop 2 line where isCurrent = "*" `isPrefixOf` line- toBranch name+ toBranch' name | isCurrent = BranchCurrent name | otherwise = case stripPrefix "remotes/" name of Just rest -> parseRemoteBranch rest@@ -53,13 +52,13 @@ checkout branch = toEither <$> execGitCheckout (branchName branch) where execGitCheckout name = readProcessWithExitCode "git" ["checkout", name] []- toEither (ExitSuccess , stdout, stderr) = Right $ dropWhile isSpace stdout- toEither (ExitFailure _, stdout, stderr) = Left $ dropWhile isSpace stderr+ toEither (ExitSuccess , stdout, _ ) = Right $ dropWhile isSpace stdout+ toEither (ExitFailure _, _ , stderr) = Left $ dropWhile isSpace stderr parseRemoteBranch :: String -> Branch-parseRemoteBranch str = BranchRemote remote branchName- where (remote, _ : branchName) = span ('/' /=) str+parseRemoteBranch str = BranchRemote remote name+ where (remote, _ : name) = span ('/' /=) str --- Helper
src/GitBrunch.hs view
@@ -1,29 +1,24 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-}-module GitBrunch where+module GitBrunch+ ( main+ )+where -import Control.Monad ( void ) import Data.Maybe ( fromMaybe )-import Data.Monoid-import Debug.Trace import qualified Graphics.Vty as V import Lens.Micro ( (^.) -- view , (.~) -- set , (%~) -- over , (&) , Lens'- , Lens , lens ) -import qualified Brick.AttrMap as A import qualified Brick.Main as M import Brick.Types ( Widget ) import Brick.Themes ( themeToAttrMap ) import qualified Brick.Types as T-import Brick.Util ( fg- , on- ) import qualified Brick.Widgets.Border as B import qualified Brick.Widgets.Border.Style as BS import qualified Brick.Widgets.Center as C@@ -31,7 +26,6 @@ , str , vBox , hBox- , vLimit , padLeft , withAttr , padRight@@ -41,7 +35,6 @@ ) import qualified Brick.Widgets.List as L import qualified Data.Vector as Vec-import Data.Maybe as Maybe import Data.List import Data.Char @@ -57,12 +50,12 @@ main = do branches <- Git.listBranches finalState <- M.defaultMain app (initialState branches)- print =<< checkout (selectedBranch finalState)+ printResult =<< checkoutBranch (selectedBranch finalState) where- print (Left e ) = putStr e- print (Right msg) = putStr msg- checkout (Just b) = Git.checkout b- checkout Nothing = pure $ Left "No branch selected."+ printResult (Left err) = putStr err+ printResult (Right msg) = putStr msg+ checkoutBranch (Just b) = Git.checkout b+ checkoutBranch Nothing = pure $ Left "No branch selected." app :: M.App State e Name@@ -90,7 +83,7 @@ ] ] where- toBranchList lens = state ^. lens & (\l -> drawBranchList (hasFocus l) l)+ toBranchList lens' = state ^. lens' & (\l -> drawBranchList (hasFocus l) l) hasFocus = (_focus state ==) . L.listName @@ -107,7 +100,7 @@ drawListElement :: Bool -> Branch -> Widget Name-drawListElement selected branch =+drawListElement _ branch = padLeft (T.Pad 1) $ padRight T.Max $ highlight branch $ str $ show branch where highlight (BranchCurrent _) = withAttr "current"@@ -181,15 +174,11 @@ -- Lens focussedBranchesL :: Lens' State (L.List Name Branch)-focussedBranchesL = lens- (\s -> case (^. focusL) s of- Local -> (^. localBranchesL) s- Remote -> (^. remoteBranchesL) s- )- (\s bs -> case (^. focusL) s of- Local -> (.~) localBranchesL bs s- Remote -> (.~) remoteBranchesL bs s- )+focussedBranchesL =+ let branchLens s = case s ^. focusL of+ Local -> localBranchesL+ Remote -> remoteBranchesL+ in lens (\s -> s ^. branchLens s) (\s bs -> (branchLens s .~ bs) s) localBranchesL :: Lens' State (L.List Name Branch)