My project is a command-line application in Haskell and uses the opt-parse applicative package to handle parsing of command line options.
I am trying to implement a functionality which can change the working directory of the shell from which the command was run.
For example, I want to do something like
$ program foo
and have the shell change to a specified directory my program has associated with the passed option foo
.
$ program foo
input 'foo'; now changing to directory '~/mydirectories/foodirectory'
[~/mydirectories/foodirectory]$
I attempted to implement this functionality using the setCurrentDirectory
function from the directory
package, however this does not appear to affect the working directory in the shell from which the directory is run; no change in the working directory appears. I am imagining that it is setting some kind of internal-to-the-program working directory, as I see no change in the shell from which the executable was run.
Is it possible to have my program change directories in this manner? Such directory-switching functionality would improve the convenience of using my application.
How can I implement directory-switching functionality from a command-line executable?