سؤال

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
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top