-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c97e910
Showing
17 changed files
with
923 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.stack-work | ||
*output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 1.0 | ||
|
||
* first release |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright Sibi Prabakaran (c) 2017 | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Author name here nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# tldr | ||
|
||
A fast client for tldr. | ||
|
||
We strive to be the fastest tldr-client with no compromises regarding features. | ||
|
||
This project is a fork of [tldr-hs](https://github.com/psibi/tldr-hs/). | ||
|
||
## Installation | ||
|
||
See Github releases: https://github.com/gutjuri/fast-tldr/releases | ||
|
||
Or | ||
|
||
1. [Install stack](https://docs.haskellstack.org/en/stable/README/#how-to-install) | ||
2. `stack install tldr` | ||
|
||
## Usage | ||
|
||
``` shellsession | ||
$ tldr --help | ||
tldr - Simplified and community-driven man pages | ||
|
||
Usage: tldr [-v|--version] ((-u|--update) | [-p|--platform PLATFORM] | ||
[-L|--language LOCALE] COMMAND | (-a|--about)) | ||
tldr Client program | ||
|
||
Available options: | ||
-h,--help Show this help text | ||
-v,--version Show version | ||
-u,--update Update offline cache of tldr pages | ||
-p,--platform PLATFORM Prioritize specfic platform while searching. Valid | ||
values include linux, osx, windows, sunos | ||
-L,--language LOCALE Preferred language for the page returned | ||
COMMAND name of the command | ||
--auto-update-interval DAYS | ||
Perform an automatic update if the cache is older | ||
than DAYS | ||
``` | ||
|
||
Or a much better example of the usage: | ||
|
||
``` shellsession | ||
$ tldr tldr | ||
tldr | ||
Simplified man pages. More information: https://tldr.sh. | ||
|
||
- Get typical usages of a command (hint: this is how you got here!): | ||
tldr {{command}} | ||
|
||
- Show the tar tldr page for linux: | ||
tldr -p {{linux}} {{tar}} | ||
|
||
- Get help for a git subcommand: | ||
tldr {{git checkout}} | ||
``` | ||
|
||
On the first run, this programme caches all available tldr pages. | ||
Since the number of available tldr pages rises quickly, it is recommended to regularly update the cache. | ||
Such an update can be run manually with `tldr --update`. | ||
Users of this client can enable automatic updates by running it with the option `--auto-update-interval DAYS` specified. | ||
The client will then check whether the cached version of the tldr pages is older than `DAYS` days and perform an update in that case. | ||
To enable this functionality permanently, users can put the line `alias tldr="tldr --auto-update-interval DAYS"` in their shell configuration file (e.g. `.bashrc`, `.zshrc`) with the desired update interval specified. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- Copyright (C) 2020 Juri Dispan | ||
-- | ||
-- This program is free software; you can redistribute it and/or modify it under | ||
-- the terms of the GNU General Public License as published by the Free Software | ||
-- Foundation; either version 2 of the License, or (at your option) any later | ||
-- version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, but WITHOUT | ||
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
-- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU General Public License along with | ||
-- this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
-- Place, Suite 330, Boston, MA 02111-1307 USA | ||
|
||
module Main where | ||
|
||
import Tldr.App ( appMain ) | ||
|
||
main :: IO () | ||
main = appMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: tldr | ||
version: '1.0' | ||
synopsis: fast tldr client | ||
description: Visit https://tldr.sh for details. | ||
category: Web, CLI | ||
author: Juri Dispan, Sibi Prabakaran | ||
maintainer: [email protected] | ||
copyright: 2020 Juri Dispan, Sibi Prabakaran | ||
license: GPL-2 | ||
github: gutjuri/fast-tldr | ||
|
||
extra-source-files: | ||
- README.md | ||
- CHANGELOG.md | ||
|
||
library: | ||
source-dirs: src | ||
dependencies: | ||
- base >=4.7 && <5 | ||
- text | ||
- bytestring | ||
- ansi-terminal | ||
- directory | ||
- filepath | ||
- semigroups | ||
- containers | ||
- http-conduit | ||
- zip-archive | ||
- time | ||
|
||
ghc-options: | ||
- -Wall | ||
- -O2 | ||
|
||
executables: | ||
tldr: | ||
main: Main.hs | ||
source-dirs: app | ||
dependencies: | ||
- tldr | ||
- base | ||
|
||
tests: | ||
tldr-test: | ||
main: Spec.hs | ||
source-dirs: test | ||
ghc-options: | ||
- -threaded | ||
- -rtsopts | ||
- -with-rtsopts=-N | ||
dependencies: | ||
- tldr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
-- Copyright (C) 2020 Juri Dispan | ||
-- | ||
-- This program is free software; you can redistribute it and/or modify it under | ||
-- the terms of the GNU General Public License as published by the Free Software | ||
-- Foundation; either version 2 of the License, or (at your option) any later | ||
-- version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, but WITHOUT | ||
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
-- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU General Public License along with | ||
-- this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
-- Place, Suite 330, Boston, MA 02111-1307 USA | ||
|
||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Tldr | ||
( renderPage | ||
) | ||
where | ||
|
||
import Data.Monoid ( (<>) ) | ||
import Data.Text hiding ( cons ) | ||
import System.Console.ANSI | ||
import qualified Data.Text as T | ||
import qualified Data.Text.IO as TIO | ||
|
||
renderHeading :: Text -> IO () | ||
renderHeading ln = do | ||
setSGR [SetColor Foreground Dull White] | ||
TIO.putStrLn $ "== " <> T.drop 2 ln <> " ==\n" | ||
|
||
renderDescription :: Text -> IO () | ||
renderDescription ln = do | ||
setSGR [SetColor Foreground Dull White] | ||
TIO.putStrLn $ T.drop 2 ln <> "\n" | ||
|
||
renderCommandDescription :: Text -> IO () | ||
renderCommandDescription ln = do | ||
setSGR [SetColor Foreground Dull Green] | ||
TIO.putStrLn $ T.drop 2 ln | ||
|
||
renderCommand :: Text -> IO () | ||
renderCommand ln = do | ||
setSGR [SetColor Foreground Dull Blue] | ||
TIO.putStrLn $ "\t" <> T.dropEnd 1 (T.drop 1 ln) <> "\n" | ||
|
||
renderLine :: Text -> IO () | ||
renderLine ln | "#" `T.isPrefixOf` ln = renderHeading ln | ||
| ">" `T.isPrefixOf` ln = renderDescription ln | ||
| "-" `T.isPrefixOf` ln = renderCommandDescription ln | ||
| "`" `T.isPrefixOf` ln = renderCommand ln | ||
| "" == ln = return () | ||
| otherwise = error "Malformed TLDR-Page" | ||
|
||
renderPage :: FilePath -> IO () | ||
renderPage fname = do | ||
text <- TIO.readFile fname | ||
mapM_ renderLine $ T.lines text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
-- Copyright (C) 2020 Juri Dispan | ||
-- | ||
-- This program is free software; you can redistribute it and/or modify it under | ||
-- the terms of the GNU General Public License as published by the Free Software | ||
-- Foundation; either version 2 of the License, or (at your option) any later | ||
-- version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, but WITHOUT | ||
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
-- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU General Public License along with | ||
-- this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
-- Place, Suite 330, Boston, MA 02111-1307 USA | ||
|
||
module Tldr.App | ||
( appMain | ||
) | ||
where | ||
|
||
import Data.List ( isPrefixOf ) | ||
import System.Environment ( getArgs ) | ||
import Tldr.App.Handler | ||
import Tldr.Types | ||
import Control.Monad | ||
import Text.Read | ||
|
||
setIfView :: ViewOptions -> Command -> Command | ||
setIfView (ViewOptions po lo aui) (ViewPage (ViewOptions po' lo' aui') ps) = | ||
ViewPage (ViewOptions (po `mplus` po') (lo `mplus` lo') (aui `mplus` aui')) ps | ||
setIfView _ x = x | ||
|
||
parseNoFlags :: [String] -> Command | ||
parseNoFlags = ViewPage (ViewOptions Nothing Nothing Nothing) | ||
|
||
addCommand :: String -> Command -> Command | ||
addCommand p (ViewPage vo ps) = ViewPage vo (p : ps) | ||
addCommand _ x = x | ||
|
||
parseOpts :: [String] -> Command | ||
parseOpts (x : _) | x `elem` ["-u", "--update"] = UpdateIndex | ||
parseOpts (x : _) | x `elem` ["-h", "--help"] = ShowHelp 0 | ||
parseOpts (x : y : xs) | x `elem` ["-L", "--language"] = | ||
setIfView (ViewOptions Nothing (Just y) Nothing) $ parseOpts xs | ||
parseOpts (x : y : xs) | x `elem` ["-p", "--platform"] = | ||
setIfView (ViewOptions (Just y) Nothing Nothing) $ parseOpts xs | ||
parseOpts (x : y : xs) | x `elem` ["-a", "--auto-update-interval"] = | ||
case readMaybe y of | ||
Nothing -> ShowHelp 1 | ||
updateInterval@(Just _) -> | ||
setIfView (ViewOptions Nothing Nothing updateInterval) $ parseOpts xs | ||
parseOpts ("--" : xs) = parseNoFlags xs | ||
parseOpts (x : xs) | not ("-" `isPrefixOf` x) = addCommand x $ parseOpts xs | ||
| otherwise = ShowHelp 1 | ||
parseOpts [] = ViewPage (ViewOptions Nothing Nothing Nothing) [] | ||
|
||
appMain :: IO () | ||
appMain = do | ||
args <- getArgs | ||
let opts = if null args then ShowHelp 1 else parseOpts args | ||
handleTldrOpts opts |
Oops, something went wrong.