Skip to content

Instantly share code, notes, and snippets.

@aleperaltabazas
Last active November 4, 2019 19:50
Show Gist options
  • Select an option

  • Save aleperaltabazas/4ada1f9dd677623c2ffbc7ac6ec76cee to your computer and use it in GitHub Desktop.

Select an option

Save aleperaltabazas/4ada1f9dd677623c2ffbc7ac6ec76cee to your computer and use it in GitHub Desktop.
"Che google, cómo hago para hacer plata?"
#!/usr/bin/runhaskell
import Control.Monad
import Data.Char
import System.Process
import System.Environment
import Data.List.Split
google = "google"
yt = "youtube"
lower :: String -> String
lower string = map toLower string
runShell :: String -> IO String
runShell command = readCreateProcess (shell command) ""
runAndIgnore :: String -> IO ()
runAndIgnore command = (runShell command) >>= (\_ -> return ())
che :: String -> String -> IO ()
che "google" query = firefox ("https://www.google.com/search?q=" ++ query)
che "youtube" query = firefox ("https://www.youtube.com/results?search_query=" ++ query)
che _ _ = exit "No such app supported"
firefox :: String -> IO ()
firefox url = runAndIgnore ("firefox " ++ url)
main :: IO ()
main = do
args <- getArgs
if (checkArgs args) then
exit "Error: require at least one argument to run"
else
runProgram args
checkArgs :: [String] -> Bool
checkArgs = (< 1) . length
runProgram :: [String] -> IO ()
runProgram [arg] = do
putStrLn (arg ++ ": Yes?")
command <- fmap lower getLine
che arg (joinQuery . (splitOn " ") $ command)
runProgram (arg:args) = che arg (joinQuery args)
joinQuery :: [String] -> String
joinQuery [x] = x
joinQuery (x:xs) = x ++ "+" ++ (joinQuery xs)
exit :: String -> IO ()
exit message = do
putStrLn message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment