shift 0.2.1.0 → 0.2.1.1
raw patch · 3 files changed
+25/−62 lines, 3 filesdep −data-default
Dependencies removed: data-default
Files
- README.md +0/−33
- shift.cabal +3/−4
- src/Teleport.hs +22/−25
README.md view
@@ -15,36 +15,3 @@ ```bash alias go="source $HOME/.local/bin/teleport" ```--## Code--[tokei](https://github.com/Aaronepower/tokei) output for previous package:--```--------------------------------------------------------------------------------- Language Files Lines Code Comments Blanks--------------------------------------------------------------------------------- Cabal 1 60 53 1 6- Haskell 4 383 248 51 84- Markdown 2 22 22 0 0- Shell 1 11 7 3 1- YAML 1 29 5 16 8--------------------------------------------------------------------------------- Total 9 505 335 71 99---------------------------------------------------------------------------------```--For the forked package:--```--------------------------------------------------------------------------------- Language Files Lines Code Comments Blanks--------------------------------------------------------------------------------- Cabal 1 51 48 0 3- Haskell 3 213 167 9 37- Markdown 1 23 23 0 0- YAML 1 6 6 0 0--------------------------------------------------------------------------------- Total 6 293 244 9 40---------------------------------------------------------------------------------```
shift.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: shift-version: 0.2.1.0+version: 0.2.1.1 license: MIT license-file: LICENSE copyright: 2010 Siddharth Bhat, 2017-2018 Vanessa McHale@@ -29,7 +29,7 @@ default-language: Haskell2010 other-extensions: DeriveAnyClass DeriveGeneric OverloadedStrings RecordWildCards- ghc-options: -fwarn-unused-imports+ ghc-options: -fwarn-unused-imports -Wall build-depends: base >=4.7 && <5, turtle -any,@@ -41,5 +41,4 @@ microlens -any, bytestring -any, ansi-terminal -any,- system-fileio -any,- data-default -any+ system-fileio -any
src/Teleport.hs view
@@ -10,7 +10,7 @@ import Data.Binary import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BSL-import Data.Default+import Data.Functor (($>)) import Data.List import Data.Maybe import qualified Data.Text as T@@ -19,13 +19,16 @@ import Filesystem as P import qualified Filesystem.Path.CurrentOS as P import GHC.Generics-import Lens.Micro hiding (argument)+import Lens.Micro import Options.Applicative import Paths_shift import Prelude hiding (FilePath) import System.Console.ANSI import System.Environment-import Turtle hiding (find, header, (&))+import Turtle (ExitCode (ExitFailure), FilePath,+ cd, die, echo, exit, fromString,+ home, realpath, testdir, testfile,+ unsafeTextToLine, (</>), (<>)) data AddOptions = AddOptions { folderPath :: Maybe String, addname :: String }@@ -44,21 +47,18 @@ -- an abstract entity representing a point to which we can warp to data WarpPoint = WarpPoint { _name :: String , _absFolderPath :: String }- deriving (Default, Generic, Binary)+ deriving (Generic, Binary) -- the main data that is loaded from config newtype WarpData = WarpData { _warpPoints :: [WarpPoint] }- deriving (Default, Generic, Binary)+ deriving (Generic, Binary) +defaultWarpData :: WarpData+defaultWarpData = WarpData []+ warpPoints :: Lens' WarpData [WarpPoint] warpPoints f s = fmap (\x -> s { _warpPoints = x }) (f (_warpPoints s)) -name :: Lens' WarpPoint String-name f s = fmap (\x -> s { _name = x}) (f (_name s))--absFolderPath :: Lens' WarpPoint String-absFolderPath f s = fmap (\x -> s { _absFolderPath = x}) (f (_absFolderPath s))- main :: IO () main = execParser opts >>= run where versionInfo = infoOption ("teleport version: " ++ showVersion version) (short 'v' <> long "version" <> help "Show version")@@ -73,7 +73,7 @@ loadWarpData :: FilePath -> IO WarpData loadWarpData configFilePath = testfile configFilePath >>= \exists -> if exists then decodeWarpData configFilePath- else saveWarpData configFilePath def >> pure def+ else saveWarpData configFilePath defaultWarpData $> defaultWarpData saveWarpData :: FilePath -> WarpData -> IO () saveWarpData configFilePath warpData =@@ -84,10 +84,6 @@ warpDataPath = home >>= \homeFolder -> pure (homeFolder </> ".warpdata") -readFolderPath :: String -> ReadM FilePath-readFolderPath = f . fromText . T.pack- where f path = if P.valid path then pure path else readerError ("invalid path: " <> show path)- warpnameParser :: Parser String warpnameParser = argument str (metavar "NAME"@@ -126,7 +122,7 @@ colorWhen :: IO () -> IO () colorWhen act = do useColor <- fromMaybe "1" <$> lookupEnv "CLICOLOR"- if useColor /= "0" then act else pure def+ if useColor /= "0" then act else mempty warpPointPrint :: WarpPoint -> IO () warpPointPrint warpPoint = do@@ -144,20 +140,21 @@ (die . T.pack $ "expected folder, not file: " ++ show path) dieIfFolderNotFound :: FilePath -> IO ()-dieIfFolderNotFound path = foldr (>>) (pure def)+dieIfFolderNotFound path = sequence_ [ flip when (needFolderNotFileError path) =<< testfile path , flip unless (folderNotFoundError path) =<< testdir path ] dieWarpPointExists :: WarpPoint -> IO ()-dieWarpPointExists warpPoint = foldr (>>) (pure def)+dieWarpPointExists warpPoint = sequence_ [ setErrorColor , putStrLn $ "warp point " <> _name warpPoint <> " already exists:\n"- , warpPointPrint warpPoint ]+ , warpPointPrint warpPoint+ ] runAdd :: AddOptions -> IO () runAdd AddOptions{..} = do dieIfFolderNotFound . P.decode . encodeUtf8 . T.pack . fromMaybe "./" $ folderPath- print "folder exists, loading warp data..."+ putStrLn "folder exists, loading warp data..." warpData <- loadWarpData =<< warpDataPath _absFolderPath <- realpath . P.decode . encodeUtf8 . T.pack . fromMaybe "./" $ folderPath let existingWarpPoint = find ((==addname) . _name) (_warpPoints warpData)@@ -165,7 +162,7 @@ Just warpPoint -> dieWarpPointExists warpPoint Nothing -> do putStrLn "creating warp point: \n"- let newWarpPoint = def & name .~ addname & absFolderPath .~ P.encodeString _absFolderPath+ let newWarpPoint = WarpPoint addname (P.encodeString _absFolderPath) warpPointPrint newWarpPoint let newWarpData = over warpPoints (newWarpPoint:) warpData flip saveWarpData newWarpData =<< warpDataPath@@ -176,8 +173,8 @@ forM_ (_warpPoints warpData) warpPointPrint dieWarpPointNotFound :: String ->IO ()-dieWarpPointNotFound w = setErrorColor >> (die . T.pack)- (w <> " warp point not found")+dieWarpPointNotFound wStr = setErrorColor >> (die . T.pack)+ (wStr <> " warp point not found") runRemove :: RemoveOptions -> IO () runRemove RemoveOptions{..} = do@@ -206,5 +203,5 @@ run (Add addOpt) = runAdd addOpt run Display = runDisplay run (Remove removeOpt) = runRemove removeOpt-run (Replace str) = runRemove (RemoveOptions str) *> runAdd (AddOptions Nothing str)+run (Replace strR) = runRemove (RemoveOptions strR) *> runAdd (AddOptions Nothing strR) run (Goto gotoOpt) = runGoto gotoOpt