2

Sample : to use Composer locally, I must write :

php composer.phar

After some locals installation of Composer, I want to alias it only "composer" but keeping absolute path with "pwd" command. I tried something like this in my .bashrc file :

alias composer='php ' . pwd . '/composer.phar'

Tested with this signs : ".", "+", ";", "&&" and “nothing” but none works.

And nothing found in Wikipedia article, official documentation or other stack question.

  • 1
    Presumably you want something like alias composer=/path/to/composer.phar. The alias is defined, and just copied verbatim when used (no further expansion). Or use a shell function, that can take arguments and do other stuff. – vonbrand Jan 28 '16 at 22:29
  • 1
    Do you want a relative or absolute path? Because a relative path is easy, and your attempted solution seems to be trying for an absolute path. – Tom Zych Jan 29 '16 at 0:22
  • You're right, I meant absolute path ;) – Klemart3D Jan 30 '16 at 0:47
5

You could add a subshell to your alias.

alias composer='php $(pwd)/composer.phar'
  • +1 Well done! I'm more a shell functions than an aliases guy, but anyway, I never though about embedding a to be substituted command inside an alias definition which I wrongly thought were more static than what you demonstrate. – jlliagre Jan 28 '16 at 22:55
  • I'm the same way, preferring functions. With an alias just remember its just text substitution so all subshells are evaluated at run time and not when the alias is created. – jecxjo Jan 28 '16 at 23:02
3

I would use a shell function:

composer() {
    php "$PWD"/composer.phar "$@"
}
  • 1
    better double-quote $PWD too – PSkocik Jan 30 '16 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.