On Thu, 13 Nov 2014, Jürgen Haas wrote:
> within fish I'm heaviliy using drush, a shell extension for the Drupal
> CMS with a lot of options that are also sometimes context sensitive.
>
> For bash, the drush package contains a drush.complete.sh which can be
> sourced for terminal sessions. That looks like this:
>
> =================== START ============
> # Completion function, uses the "drush complete" command to retrieve
> # completions for a specific command line COMP_WORDS.
> _drush_completion() {
> # Set IFS to newline (locally), since we only use newline
> separators, and
> # need to retain spaces (or not) after completions.
> local IFS=$'\n'
> # The '< /dev/null' is a work around for a bug in php libedit stdin
> handling.
> # Note that libedit in place of libreadline in some distributions. See:
> # https://bugs.launchpad.net/ubuntu/+source/php5/+bug/322214
> COMPREPLY=( $(drush --early=includes/complete.inc "${COMP_WORDS[@]}"
> < /dev/null 2> /dev/null) )
> }
>
> # Register our completion function. We include common short aliases
> for Drush.
> complete -o bashdefault -o default -o nospace -F _drush_completion d
> dr drush drush5 drush6 drush7 drush.php
> =================== FINISH ============
>
> I'm trying to port this to fish and came as long as this:
>
> complete -x -c drush -d "Dr" -a "(drush --early=includes/complete.inc)"
>
> This is working to a certain extend such that it displays all options
> almost all of the time. What I need is to provide the specific command
> line COMP_WORDS to the script complete.inc. What is the right syntax
> for that? I looked into variable expansion but could figure it out.
I think the `commandline` builtin is what you want.
```
-a '(drush --early=includes/complete.inc (commandline -cpo))'
```
This passes all arguments in the current process invocation (`-p`) up to
the cursor (`-c`) and breaks them into separate tokens so each argument is
a new token (`-o`).
> Once that's complete I should also define the local variable IFS=$'\n'
> and I'd appreciate if anyone could give me a hint on how to get all of
> this into a single command or a function for the fish shell.
You can put a function into the completion file, and it will get loaded
with the completions.
I don't think you need the IFS definition as fish won't throw the spaces
away (see the comment in the bash definition), but if you do, something
like this in your ~/.config/fish/completions/drush.fish should work:
```
function __complete_drush
set -lx IFS '\n'
drush --early=includes/complete.inc (commandline -cpo)
end
complete -x -c drush -d "Dr" -a '(__complete_drush)'
```
Hope that helps.
David Adam
zanc...@ucc.gu.uwa.edu.au
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users