Skip to content

Commit

Permalink
Update ENV for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Frost-Lord committed Jul 17, 2023
1 parent 6f71b88 commit 8ba9e4b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
app/test.hs
app/test.exe
app/test.hi
app/test.o
test/test.exe
test/test.hi
test/test.o
code.txt
4 changes: 3 additions & 1 deletion HaskMate.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ cabal-version: 3.0
name: HaskMate
version: 0.1.0.0
-- synopsis:
synopsis: Haskell File Monitor
homepage: https://github.com/Frost-Lord/HaskMate
-- description:
license: MIT
license-file: LICENSE
author: Frost Lord
maintainer: [email protected]
-- copyright:
category: Math
category: System
build-type: Simple
extra-doc-files: CHANGELOG.md
-- extra-source-files:
Expand Down
Binary file modified Images/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 13 additions & 12 deletions app/HaskMate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import System.Directory (doesFileExist, getModificationTime, getCurrentDirectory
import System.Process (createProcess, proc, terminateProcess, waitForProcess, callCommand, ProcessHandle)
import Control.Concurrent.MVar (newEmptyMVar, putMVar, tryTakeMVar, MVar)
import Data.Time.Clock (getCurrentTime, UTCTime)

-- Path to your Haskell script
scriptPath = "app/test.hs"
scriptPath :: FilePath
import System.Environment (getArgs)

-- Delay between checks (in microseconds)
delay :: Int
Expand Down Expand Up @@ -56,11 +53,15 @@ monitorScript path lastModified handleMVar = do

main :: IO ()
main = do
currentDir <- getCurrentDirectory
let fullPath = currentDir ++ "/" ++ scriptPath
putStrLn $ green ++ projectName ++ white ++" Starting Haskellmon v0.1.0.0..."
putStrLn $ green ++ projectName ++ white ++" Running script in directory: " ++ fullPath
putStrLn $ green ++ projectName ++ white ++" Watching for file modifications. Press " ++ red ++ "Ctrl+C" ++ white ++ " to exit."
lastModified <- getLastModified fullPath
handleMVar <- newEmptyMVar
monitorScript fullPath lastModified handleMVar
args <- getArgs
case args of
(scriptPath:_) -> do
currentDir <- getCurrentDirectory
let fullPath = currentDir ++ "/" ++ scriptPath
putStrLn $ green ++ projectName ++ white ++" Starting HaskMate v1.0.0..."
putStrLn $ green ++ projectName ++ white ++" Running script in directory: " ++ fullPath
putStrLn $ green ++ projectName ++ white ++" Watching for file modifications. Press " ++ red ++ "Ctrl+C" ++ white ++ " to exit."
lastModified <- getLastModified fullPath
handleMVar <- newEmptyMVar
monitorScript fullPath lastModified handleMVar
[] -> putStrLn "Please provide a file to monitor as an argument." >> putStrLn "Example: HaskMate app/Main.hs"
48 changes: 48 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
$destinationDir = "$env:APPDATA\Haskmate"
$sourceExe1 = ".\Haskmate.exe"
$sourceExe2 = ".\dist-newstyle\build\x86_64-windows\ghc-9.6.2\HaskMate-0.1.0.0\x\HaskMate\build\HaskMate\Haskmate.exe"

# Check if Haskmate directory is already in the PATH environment variable
$existingPath = [Environment]::GetEnvironmentVariable("PATH", "User")
$hasHaskmatePath = $existingPath -like "*$destinationDir*"

# Create the Haskmate directory if it doesn't exist
if (-not (Test-Path $destinationDir)) {
New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null
}

# Check if Haskmate.exe already exists in the destination directory
$destinationExe = Join-Path -Path $destinationDir -ChildPath "Haskmate.exe"
if (Test-Path $destinationExe) {
Write-Host "Replacing existing Haskmate.exe in the Haskmate directory."
Remove-Item -Path $destinationExe -Force
}

# Copy the Haskmate executable to the destination directory
$sourcePath = $sourceExe1
if (-not (Test-Path $sourcePath)) {
Write-Host "Running from development environment."
$sourcePath = $sourceExe2
}

if (Test-Path $sourcePath) {
Copy-Item -Path $sourcePath -Destination $destinationExe -Force
} else {
Write-Host "Unable to find the Haskmate.exe file in the expected locations."
Write-Host "Please make sure the Haskmate executable is present and try again."
pause
exit
}

# Add the Haskmate directory to the PATH environment variable if not already present
if (-not $hasHaskmatePath) {
$newPath = $existingPath + ";" + $destinationDir
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
Write-Host "Haskmate directory added to the PATH environment variable."
}

# Display a message to confirm the setup
Write-Host "Haskmate setup complete."
Write-Host "Haskmate executable is located in: $destinationDir"
Write-Host "You can now run Haskmate from anywhere in the command prompt."
pause
3 changes: 3 additions & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
main :: IO ()
main = do
putStrLn "My script running!"

0 comments on commit 8ba9e4b

Please sign in to comment.