michalzuber
michalzuber

Reputation: 5215

Alias executed recursively on OSX

I'm using oh-my-zsh a have the following alias in .zshrc:

alias composer="php -d memory_limit=-1 $(which composer)"

I get the following output:

$ composer
Could not open input file: composer:

And for:

$ which composer
composer: aliased to php -d memory_limit=-1 composer: aliased to php -d memory_limit=-1 composer: aliased to php -d memory_limit=-1 /usr/local/bin/composer
$ zsh --version
zsh 5.2 (x86_64-apple-darwin15.4.0)

Under Linux it works as expected:

$ which composer
composer: aliased to php -d memory_limit=-1 /usr/bin/composer
$ zsh --version
zsh 5.3.1 (x86_64-unknown-linux-gnu)

Upvotes: 1

Views: 253

Answers (2)

Adaephon
Adaephon

Reputation: 18399

This has nothing to do with it being on OS X or Linux, or the usage of screen. It very much looks like you ran the command

alias composer="php -d memory_limit=-1 $(which composer)"

multiple times. which lead to the recursive definition of composer:

composer: aliased to php -d memory_limit=-1 composer: aliased to php -d memory_limit=-1 composer: aliased to php -d memory_limit=-1 /usr/local/bin/composer

Adding line-breaks to make it obvious:

composer: aliased to php -d memory_limit=-1 \
composer: aliased to php -d memory_limit=-1 \
composer: aliased to php -d memory_limit=-1 \
/usr/local/bin/composer

While the first use of which composer will return /usr/local/bin/composer (or a similar path), subsequent uses will return composer: aliased to .... This leads to the error message that the input file composer: (Note the colon) could not be found.

Defining the alias just once will probably work for the most part, but to be safe you can tell which explicitly to look for paths (ignoring builtins, aliases and functions) with the parameter -p:

alias composer="php -d memory_limit=-1 $(which -p composer)"

Upvotes: 2

michalzuber
michalzuber

Reputation: 5215

It was an issue with GNU screen session. Creating a new screen window the alias works as expected.

Upvotes: -1

Related Questions