Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see the current working directory in WinGHCi

I've started to teach myself Haskell, and for that I've installed The Haskell Platform for Windows. I'm using WinGHCi as of now. I learned that it has command :cd which is used to change directory. But the question is, how would I know which directory I'm currently in? Without knowing that first why would I want to change directory. I searched a lot but couldn't find the answer.

Please tell me if there is a way to know the current working directory. Preferably I would like to configure the command prompt itself to show the current directory, pretty much like Linux's Console.


Following @Daniel's suggestion, I did these:

  • Since I worked on Windows 7, there is no .ghci file (I think it is for Unix-like OS), so I created a file ghci.conf in C:\Users\Apelles\AppData\Roaming\ghc folder, as it is instructed here.
  • Copy pasted the script from Daniel's answer to ghci.conf.
  • Then I started ghci.exe which is the console-like window. I noticed that it loaded few more modules than it usually used to load before. Here is the snapshot:

enter image description here

As you can see it loads more modules, and the last line says,

Can't parse prompt string. Use Haskell syntax.

What does it mean? Which line is causing problem (from the following script)?

let cur fill = do { cwd <- System.Directory.getCurrentDirectory; return (":set prompt \"" ++ cwd ++ fill ++ " \""); } :def doprompt (\_ -> cur ">") :def mycd (\dir -> System.Directory.setCurrentDirectory dir >> cur ">") :doprompt 

Also, if I rename ghci.conf file to some random name, and then start ghci.exe, it loads these modules: enter image description here

As I said before, it loads less number of modules, which means with ghci.conf, ghci.exe does something successfully, but fails at some point. How to fix that?

like image 970
Nawaz Avatar asked Jun 28 '12 17:06

Nawaz


People also ask

How do I find my working directory?

R is always pointed at a directory on your computer. You can find out which directory by running the getwd (get working directory) function; this function has no arguments. To change your working directory, use setwd and specify the path to the desired folder.

What command is used to show the current working directory?

The pwd command can be used to determine the present working directory.

How do I use current working directory?

To list the files in the current directory use the dir command, and if you want to change the current directory, use the cd command. You can use the chdir command by itself to print the current directory in MS-DOS and the Windows command line.

How do I find my working directory in Windows?

If you want to know the current location, in which folder or directory you are while using Windows CMD (Command Line Interface), you can make use of cd command, Command: cd - This command can be used to displays the name of or to change the current directory.


2 Answers

System.Directory.getCurrentDirectory from the directory package.

like image 158
jp093121 Avatar answered Sep 28 '22 16:09

jp093121


I am not sure if this is the "right" way to do it, but since :! allows shell commands, you can also get it with the appropriate shell command (of your OS) for reading out the directory or the content (so cd, ls and the likes). For example, you can write:

:! cd 

It depends what do you need the directory for. If you just want to print it out in your console, then this can help.

All the best!

like image 28
Бојан Матовски Avatar answered Sep 28 '22 17:09

Бојан Матовски