See #543550: Drush interactive mode. Not available in drush-3.0-rc3, but currently checked in to drush-HEAD, and will be included in drush-3.0-rc4 and drush-3.0-stable.

"drush cli" is implemented by running a bash subshell that is customized for drush use, and therefore is limited to environments where bash is available (Linux, cygwin.)

Patches containing bash customizations for drush would be welcome.

Comments

Yoran’s picture

Thanks for the notice but if I dropped my own development about this shell, this is for the very reason I found more efficient not to follow the "sub-shell" path. For me, subshells will never be the right_shell_for_everyone and will always reduce possibilities and introduces caveats.

As an example (no critic here, just example), with the RC4 CLI :
- it can't load local script (using "source script" or ". script")
- it lost autocompletion because on any unix system you more that 200 commands beginning with 's' (when searching to complete the drush command "status").
- it lost (this can be solved) master bash settings (like all previous macro)
- it's conflicting with native commands (how do I do a realy rsync when drush also have a rsync command...)

I speak quietly about the dead-end of this new feature as I figure this out for my own shell. Drush is a great tool but I definitely think that "drush cli" is not the way to go.

greg.1.anderson’s picture

There are definitely advantages and disadvantages to this technique, and I definitely appreciate your frank feedback. Regarding conflicts, you can always get to the "real" rsync via /bin/rsync (or whatever the path to the real tool is), but my thought is that it would be easy to control-d out to a regular bash shell for doing non-Drupal tasks, and then pop back into drush cli when you want -- or just keep two terminals open. Maybe we should consider insuring that drush commands don't interfere with shell commands (drush rsync was orignally drush sync, for example).

There are some issues that will never be overcome with the subshell just based on the nature of the technique. If you want to autocomplete only drush commands, or if you want to run a drush shell on a system that does not have bash, then drush cli won't get you there. I definitely encourage you to keep working on your own shell to provide the features that a bash subshell simply can't if that's the way you prefer to go.

I think the other issues you mention can be fixed in time. We're definitely at the experimental stage right now, and talked about not putting drush cli into 3.0-stable, but decided to go ahead and let people give it a try. I think we can get pretty close to an 'ideal' shell, and the appeal of the subshell technique is that it leverages the power of bash without requiring a lot of new code.

Thanks again for the feedback.

Yoran’s picture

I really don't wont to be boring about this, but the more I think about this, the more I'm convicted drush-cli will bring more problem than solutions. I just had an other situation when speaking with people on my web site about the power of ZSH compared with Bash (an article about implementing custom auto-completion with bash). At the end of the day, it's all matter of tastes, by the fact is that bash is not the only shell in the arena and your cli implementation will have to be compatible with all of them as you just can't tell people "ok, now you're in a drush subshell now, forget about you zsh or whatever, you'll love bash again, I promise " ;-)

Each bash provide solid auto-completion kind of API, local functions, and all features needed to provide a nice drush experience. On the drush side, the only miss is a set of functions to provide informations to *sh functions (ex. list of commands, parameters for a command, etc...) in order to bring drush auto-completion that drush-cli is actually missing. In my own shell-bash binding, I had to add a some of those custom commands in order to make the magic work and they are so simple.

So why not providing drush-cli as a module and integrating such "API" *sh commands in the core ?

greg.1.anderson’s picture

Not at all boring; I appreciate your viewpoints, and the points you make are valid.

I used bash for drush cli because I use bash as my shell. It would also be possible to use the same technique with zsh and other shells with similar code. If a zsh fan really wanted a drush cli that used zsh instead of bash, it would be possible for a suitably motivated individual to create a patch that allowed drush to support both. It's unlikely that one maintainer could support all shells that anyone might want to use, though.

Note that you would have the same problem with a re-implementation of a shell; you'd have to decide if your shell functions would follow the bash pattern or the zsh pattern or some other pattern altogether. This is not to say that you shouldn't re-implement a shell in php; this is potentially useful work that could benefit people who do not use Linux or Cygwin.

I'm not sure that I understand your last suggestion. Drush is already a shell-agnostic tool that you can run anywhere; you just need to type "drush" before your command name. ;) Drush cli provides a bit of an optimization over this that helps people who like bash. I think it will be very useful to a subset of drush users, and others will seek other solutions.

I encourage you to continue to do so, either by submitting enhancements to drush cli, or by pursuing your php shell implementation. No one wants two projects that do exactly the same thing, but when there are definite reasons, well, sometimes similar projects are created. I would of course encourage you to bring any relevant improvements you may have discovered in your own shell-bash binding to drush cli if you have the time and interest to do so.

Yoran’s picture

To be more precise on my last suggestion, in order to implement a simple auto-completion plugin for bash, I needed to make a drush plugin like this :

function drush_drush_extension_ds_commands() {
  $commands = drush_get_commands();
  foreach ($commands as $name => $command) {
    echo $name . "\n";
  }
}

// FIXME Need some cache here...
function drush_drush_extension_ds_modules() {
  $modules = drush_pm_get_projects();
  foreach ($modules as $name => $module) {
    if ($module->type == 'module') {
      echo $name . "\n";
    }
  }
}

function drush_drush_extension_ds_module($module_name) {
  $modules = drush_pm_get_projects();
  $module = $modules[$module_name];
  echo dirname($module->filename);
}

With those new commands, i'm able to complete drush commands, but also some command arguments (ex. drush en [tab]). I think this would be interesting for such commands to be directly in core.

But perhaps better option, would be to add completion behavior directly to drush command. The same way you have a drush hook for commands help, you can imagine kind of drush_auto_complement hook, that will permit each command author to provide list of possibilities in every situation. Something like :

function example_drush_auto_complete() {
  $args=func_get_args();
	
  switch (count($args)) {
    case 1:
      return array('sub-command1', 'sub-command2');

    case 2:
	switch ($args[1]) {
		case 'sub-command1':
		      return get_list_of_enabled_modules();
		etc.
	}
	break;

  etc...
  }
  // null returned => northing to auto-complete
}

This way, implementing auto-completion for each shell should be quite easy.

Yoran’s picture

Hi Greg,

In order to be more pragmatic, I wrapped my "drush completion hook" as a drush module and updated this project page with explanation. If you don't mind, could you have a look and giving me your feedback ?

greg.1.anderson’s picture

All of that looks very good. You might want to take some of these ideas on over to #437568: Autocomplete awesomeness for drush, and also review that thread and see if any of these problems have already been solved there. There's a lot in my brain right now, and I wasn't able to wrap my head around the above + the previous work that's been done on autocompletion, but some work has already been done... drush cli only goes part-way to providing autocompletion; more work is needed.

jonhattan’s picture

For completeness, #543550: Drush interactive mode was other attempt to implement a drush shell. The idea there was to be able to enter a (real) drush shell based on php and readline (#562888: The readline library) to autocomplete drush commands and even more relevant to me: the possibility to run commands within the same bootstrap process.

greg.1.anderson’s picture

Status: Active » Closed (fixed)

Drush eventually did adopt the ideas in this project; drush core-cli is no longer supported, and there are example bash customizations in the Drush folder. I don't know if everything that was here made it into Drush core before this project was abandoned, but I am marking this issue as 'fixed'.

Project: » Lost & found issues

This issue’s project has disappeared. Most likely, it was a sandbox project, which can be deleted by its maintainer. See the Lost & found issues project page for more details. (The missing project ID was 698324)