0

I have this zsh alias:

alias ogf="source <(clone_git_file -ts $1)"

clone_git_file -ts returns a string which can be executed in a shell. Using source <(...) works perfectly (executes the code in my current shell), but I can't get the $1 token to be passed into the nested command.

I found the source usage above here by the way.

How can I achieve this, passing in the token correctly? If I remove the source <( from my alias and do this:

source <(ogf my_url)

my_url is passed along and everything works perfectly.

Community
  • 1
  • 1
Brandon
  • 1,735
  • 2
  • 22
  • 37

1 Answers1

1

Aliases don't take arguments. The $1 is expanded when you define the alias. You want to use a function instead.

ogf () {
    source <(clone_git_file -ts "$1")
}

It's also not simply a matter of preventing $1 from being expanded immediately; if you tried

alias ogf='source <(clone_git_file -ts $1)'

then ogf foo would expand to ogf $1 foo, with $1 being expanded to whatever the current shell's value of $1 is.

chepner
  • 497,756
  • 71
  • 530
  • 681
  • This fixes one problem, but causes another. The `source <()` part doesn't work. Change the nested method to `echo "time"` and try it yourself, no output. Do you know how to solve that? Thanks for your help so far! – Brandon Dec 19 '15 at 20:50
  • `source <(echo "time")` runs the time pre-command modifier for me. – chepner Dec 19 '15 at 20:58
  • I'm not sure what you mean, does that mean you get the output just the same as if you had typed `time` in the shell instead? – Brandon Dec 19 '15 at 21:09
  • You know what, I don't know what I did wrong but it is working now. Thank you! – Brandon Dec 19 '15 at 21:13