Search code examples
bashaliasxargs

xargs command silently fails when used in a bash alias


From the command line, this opens two files in my phpstorm application:

git diff --name-only final-migration | xargs pstorm

When I create an alias in my ~/.bash_profile:

alias ropen="git diff --name-only $1 | xargs pstorm"

and call it from the same directory as the successful command:

ropen final-migration

Nothing happens.. I've tried altering the alias so that it echos instead of xargs pstorm which works as expected. It seems like xargs is where the problem lies when it's being used in an alias.. I'm not sure what I'm missing.


Solution

  • The issue was with my version of xargs which is supplied with OSX. By using the GNU version, @socowi's suggestion of using a function worked just perfectly.

    To install the gnu version of xargs, I did as @Benjamin W said and used homebrew to install findutils. I then added the path as suggested from installing findutils to my ~/.bash_profile.