commit a63c0c6d0a6bd30baaa68195e4398977d8bbf2dd Author: jasmine Date: Sat Sep 14 04:28:20 2024 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6123b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.direnv/ +.envrc +dist-newstyle/ diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yaml new file mode 100644 index 0000000..800edfa --- /dev/null +++ b/.stylish-haskell.yaml @@ -0,0 +1,3 @@ +steps: + - imports: + align: file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b1a5d3f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for teleios + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..65cd219 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2024 sajenim + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..8972e8f --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,63 @@ +{-# LANGUAGE MultiWayIf #-} + +import Data.List.Split (splitOn) +import System.Directory (setCurrentDirectory) +import System.Exit (exitSuccess) +import System.IO +import System.Process (callCommand) + +prompt :: IO () +prompt = do + input <- moshReadLine promptStringOne + moshExecute input + prompt + +moshReadLine :: String -> IO String +moshReadLine ps1 = do + putStr ps1 + hFlush stdout + getLine + +moshExecute :: String -> IO () +moshExecute input = do + if + | command == "exit" -> exitSuccess + | command == "help" -> moshHelp + | command == "cd" -> changeDirectory path + | otherwise -> callCommand input + where + command = head (splitOn " " input) + path = last (splitOn " " input) + +changeDirectory :: FilePath -> IO () +changeDirectory path = do + setCurrentDirectory path + +moshHelp :: IO () +moshHelp = do + putStrLn "---------------------" + putStrLn "MoSH -- Monadic Shell" + putStrLn "Author: sajenim" + putStrLn "---------------------" + putStrLn "Type program names and arguments, and hit enter." + putStrLn "" + putStrLn "The following are built in:" + putStr (unlines (prepend " " builtinCommands)) + putStrLn "" + putStrLn "Use the man command for information on other programs" + +builtinCommands :: [String] +builtinCommands = [ "cd" + , "help" + , "exit" + ] + +promptStringOne :: String +promptStringOne = "> " + +prepend :: String -> [String] -> [String] +prepend s = map (s ++) + +main :: IO () +main = do + prompt diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..627b759 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1723221148, + "narHash": "sha256-7pjpeQlZUNQ4eeVntytU3jkw9dFK3k1Htgk2iuXjaD8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "154bcb95ad51bc257c2ce4043a725de6ca700ef6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ea07437 --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + description = "A basic flake with a shell"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ghc cabal-install haskell-language-server]; + }; + }); +} diff --git a/mosh.cabal b/mosh.cabal new file mode 100644 index 0000000..25c26b0 --- /dev/null +++ b/mosh.cabal @@ -0,0 +1,28 @@ +cabal-version: 3.0 +name: mosh +version: 0.1.0.0 +-- synopsis: +-- description: +license: MIT +license-file: LICENSE +author: sajenim +maintainer: its.jassy@pm.me +-- copyright: +build-type: Simple +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable teleios + import: warnings + main-is: Main.hs + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.18.2.1, + process, + directory, + split + hs-source-dirs: app + default-language: Haskell2010