Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitconfig aliasing using !source doesn't work (zsh)

I have a gitconfig like this:

[alias]
l = "!source ~/.githelpers && pretty_git_log"

When I run it I get this:

[desktop] git l
source ~/.githelpers && pretty_git_log: 1: source: not found
error: cannot run source ~/.githelpers && pretty_git_log: No such file or directory
fatal: While expanding alias 'l': 'source ~/.githelpers && pretty_git_log': No such file or directory

When I add any other shell builtins to test, they run fine:

[alias]
l = "!echo running from the builtin"

[desktop] git l
running from the builtin

Any idea why the source command can't be found from git? I am running zsh, but changing to bash didn't seem to make a difference:

[desktop] bash
[desktop] git l
source ~/.githelpers && pretty_git_log: 1: source: not found
error: cannot run source ~/.githelpers && pretty_git_log: No such file or directory
fatal: While expanding alias 'l': 'source ~/.githelpers && pretty_git_log': No such file or directory
like image 999
user1244166 Avatar asked Sep 19 '12 16:09

user1244166


1 Answers

The failure comes from the fact that the !<command> construct tries to find a program by that name to run. There is a /bin/echo program (which is different from your shell's built in echo, but that's a different story), but there is not a /bin/source (or /usr/bin or any other place). By nature of what source does, it cannot be a separate program.

Try this instead:

[alias]
l = "!sh -c 'source ~/.githelpers && pretty_git_log'"

Change sh to bash (or whatever) as necessary.

like image 138
twalberg Avatar answered Sep 18 '22 02:09

twalberg