Closed jasir closed 9 years ago
How substituting program (that's what was done in this PR) can help you solve described problem. Isn't currently directory available for usage as part of completion?
Can you explain your use case a bit further, @jasir? It's not entirely clear as your issue description and commit appear to differ in intention (to me anyway).
Based on your commit, my best guess is that you want to run against a relative path like app/console
, without generating a hook from one of the target projects:
# Desired behaviour
$ cd /srv/symfony-app-foo/
$ app/console [tab][tab] ==> [complete using /srv/symfony-app-foo/app/console]
$ cd /var/www/other-symfony-app/
$ app/console [tab][tab] ==> [complete using /var/www/other-symfony-app/app/console]
# Hook can only be generated using one of the projects
$ cd /srv/symfony-app-foo
$ app/console _completion -g ==> [generated hook uses relative app/console]
Ok, I will try. I admit is is very specific to my use.
I have one program stored in /c/programs/cli
. It is symfony-console application program, which dynamically register commands found in a directory it is runned in. This allows me simple creation of custom commands per projects (directories). So far it works well. But I have also "global" commands. It is the same program /c/programs/cli
but wrapped in shell like this:
cli-global.sh:
cd /c/programs/global-cli-definition
/c/programs/cli
I am trying to compete cli-global.sh using
But this way, generated hook calls /c/programs/cli, not wrapper cli-global.sh
In other words, I need the completion redirect to my wrapping script, otherwise wrapper script is skipped and as completion generator is used /c/programs/cli
This patch allows me to do:
eval /c/programs/cli-global.sh _completion -g -p cli-global --complete-program=/c/programs/cli-global.sh --shell-type=bash
There are a few options I can see that don't require editing this module. They are varying degrees of portability:
Do 1, but use sed or awk to replace the value automatically, like this (or with a more generic regex):
/c/programs/cli _completion -g -p cli-global | sed 's,/c/programs/cli _completion,/c/programs/cli-global.sh,'
Register your own completion handler that runs the cli-global.sh
script first (calling /c/programs/cli _completion
or the generated completion function in the process). You can get the function name by running this:
func_name=$(app _completion -g | grep ^function | cut -d' ' -f2)
CompletionCommand
. If you need this to be portable, add a config file that's read before completion is run. Eg. ~/.cli-global.json
Do any of those solutions work for you?
Hello, thank for very much your time and analysis. I will try to explain more: solution 1 and 2 would work, with one problem - anytime package symfony-console-completion is changed, it may stop to work. Am I right?
Solution 3 - I have to say it may work, really not sure, but it is definitely not very readable solution.
Solution 4 - will not work, my situation is little bit more complicated.
Overall - it is solvable by workarounds, but I see my solution a little bit more straightforward. Maybe if suggested 'complete-program' is changed to something better understandable?
completion-command-path
for example? With some sane description?
Again, thanks a lot for your opinions.
@jasir , what if you use that wrapper script (sh file) in the hook generation command? Won't it be used in generated code as well?
No, it will not work. $arg[0]
in php is still pointing to /c/programs/cli
But I have found different solution. I have put php code right to global program, like this:
#!/usr/bin/env php
<?php
chdir("c:/work/projects/globalmonkey");
require_once 'c:/work/projects/mymonkey/monkx/monkey/bootstrap.php';
this way it it works... So you can close it here if you thing it is not worth of.
Thank you very much for your help.
Awesome, glad you could figure out a solution. Since this is a bit of an edge-case use that can be worked around, I'll close this PR.
1 and 2 would work, with one problem - anytime package symfony-console-completion is changed, it may stop to work
Technically this is true, but the generated hook code doesn't change very often so it's not an insurmountable issue - maybe just an inconvenience.
Would alteration of generated completion hook suggested in https://github.com/stecman/symfony-console-completion/issues/44#issuecomment-101253790 would help you @jasir ?
This has very specific use for me: I have program (symfony console), which has different available commands according to current directory...