I want to use a command line file path with Drush (see #185373: Review code snippets). Since drush is a command line tool, this seems like a reasonable thing to do. Currently, drush does a chdir(), and all paths are relative to the Drupal root. However, I am running drush from one of my sites directories, and the path should be DRUPAL_ROOT/sites/example.com/. There are options to figuring out what file a user intended to use... such as getting the conf_path() and looking for it relative to that one. But since the current working directory is so pivotal to figuring out a file path, and since Drush is a command line tool, I was thinking that it made sense to just save this variable for anyone that wanted to use it.

Does it make sense to store the CWD before changing it?

CommentFileSizeAuthor
#3 297611.patch575 bytesdouggreen
oldpwd.patch612 bytesdouggreen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

douggreen’s picture

Title: Allow command line partial path arguments by storing the directory » Command line path arguments need the current directory
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

OK. I think CWD is more consistent than PWD and I would even prefix so it is DRUSH_OLDCWD.

douggreen’s picture

FileSize
575 bytes

I used OLDPWD, because that's what the shell uses, but here's a patch using DRUPAL_OLDCWD.

moshe weitzman’s picture

Status: Reviewed & tested by the community » Fixed

Committed a slightly different fix. Get the value using drupal_get_context('DRUSH_OLDCWD').

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Gogowitsch’s picture

Component: Code » Base system (internal API)
Issue summary: View changes

Here comes a note for future googlers:

In Drush 9, you typically extend the class DrushCommands. In your custom command, you can use the following to get the directory from which Drush was called:
$this->getConfig()->cwd()