psibi / tldr-hs

Haskell tldr client
BSD 3-Clause "New" or "Revised" License
92 stars 14 forks source link

Add windows to checkDirs #14

Closed ghost closed 5 years ago

ghost commented 5 years ago

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 commented 5 years ago

Thanks!

ghost commented 5 years ago

Glad that I could help. On Nov 18 2018, at 10:22 pm, Sibi notifications@github.com wrote:

Thanks! — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub (https://link.getmailspring.com/link/1542579288.local-056ff2ab-0b30-v1.5.2-31660462@getmailspring.com/0?redirect=https%3A%2F%2Fgithub.com%2Fpsibi%2Ftldr-hs%2Fpull%2F14%23issuecomment-439688836&recipient=cmVwbHkrMDI0OGYyNmQ2OGY4OTlmMTA4NjczYWNmYjg4NDI4N2FlZTc0OGM0ZmU5YTE4NmY3OTJjZjAwMDAwMDAxMTgwOTFiODg5MmExNjljZTE2YzNlNjliQHJlcGx5LmdpdGh1Yi5jb20%3D), or mute the thread (https://link.getmailspring.com/link/1542579288.local-056ff2ab-0b30-v1.5.2-31660462@getmailspring.com/1?redirect=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAkjybUpS1Gib3wTko4AnkX6cp-QjL17Zks5uwVEIgaJpZM4Yn0x_&recipient=cmVwbHkrMDI0OGYyNmQ2OGY4OTlmMTA4NjczYWNmYjg4NDI4N2FlZTc0OGM0ZmU5YTE4NmY3OTJjZjAwMDAwMDAxMTgwOTFiODg5MmExNjljZTE2YzNlNjliQHJlcGx5LmdpdGh1Yi5jb20%3D).