Skip to content

Add windows to checkDirs#14

Merged
psibi merged 1 commit intomasterfrom
unknown repository
Nov 18, 2018
Merged

Add windows to checkDirs#14
psibi merged 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Nov 18, 2018

The problem

I noticed that checkDirs (in app/Main.hs) only contains the common, linux and osx directories, but not the windows directory:

checkDirs :: [String]
checkDirs = ["common", "linux", "osx"]

However, both stack and ghc have support for Windows; even though tldr-hs will compile on Windows, it won't use the Windows specific pages.
This PR aims to solve that problem.

The solution

The result is changing checkDirs from it's previously stated definition to:

checkDirs :: [String]
checkDirs = ["common", "linux", "osx", "windows"]

and changing getPagePath, from:

getPagePath :: String -> IO (Maybe FilePath)
getPagePath page = do
  homeDir <- getHomeDirectory
  let pageDir = homeDir </> tldrDirName </> "tldr" </> "pages"
      x@(f1:f2:f3:[]) = map (\x -> pageDir </> x </> page <.> "md") checkDirs
#if MIN_VERSION_base(4,7,0)
  f1' <- pageExists f1
  f2' <- pageExists f2
  f3' <- pageExists f3
  return $ f1' <|> f2' <|> f3'
#else
  pageExists f1 <|> pageExists f2 <|> pageExists f3
#endif

to:

getPagePath :: String -> IO (Maybe FilePath)
getPagePath page = do
  homeDir <- getHomeDirectory
  let pageDir = homeDir </> tldrDirName </> "tldr" </> "pages"
      x@(f1:f2:f3:f4:[]) = map (\x -> pageDir </> x </> page <.> "md") checkDirs
#if MIN_VERSION_base(4,7,0)
  f1' <- pageExists f1
  f2' <- pageExists f2
  f3' <- pageExists f3
  f4' <- pageExists f4
  return $ f1' <|> f2' <|> f3' <|> f4'
#else
  pageExists f1 <|> pageExists f2 <|> pageExists f3 <|> pageExists f4
#endif

Status

This solution works perfectly fine on my Ubuntu 18.04.1 machine:

> tldr assoc
assoc
Display or modify file extension associations.

 - Display all associated filetypes:
   assoc

 - Display the associated filetype for a specific extension:
   assoc {{.txt}}

 - Modify the associated filetype for a specific extension:
   assoc {{.txt}}={{txtfile}}
> tldr cls
cls
Clears the screen.

 - Clear the screen:
   cls
> tldr adduser
adduser
User addition utility.

 - Create a new user with a default home directory and prompt the user to set a password:
   adduser {{username}}

 - Create a new user without a home directory:
   adduser --no-create-home {{username}}

 - Create a new user with a home directory at the specified path:
   adduser --home {{path/to/home}} {{username}}

 - Create a new user with the specified shell set as the login shell:
   adduser --shell {{path/to/shell}} {{username}}

 - Create a new user belonging to the specified group:
   adduser --ingroup {{group}} {{username}}

(both assoc and cls are in the windows pages directory; adduser is merely used to show that pages from other directories still load).

@psibi psibi merged commit 4fe8cff into psibi:master Nov 18, 2018
@psibi
Copy link
Copy Markdown
Owner

psibi commented Nov 18, 2018

Thanks!

@ghost
Copy link
Copy Markdown
Author

ghost commented Nov 18, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant