Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add windows to checkDirs #14

Merged
merged 1 commit into from Nov 18, 2018
Merged

Add windows to checkDirs #14

merged 1 commit into from Nov 18, 2018

Conversation

ghost
Copy link

@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
Owner

psibi commented Nov 18, 2018

Thanks!

@ghost
Copy link
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.

None yet

1 participant