使用!源的gitconfig别名不起作用(zsh) [英] gitconfig aliasing using !source doesn't work (zsh)
问题描述
我有一个像这样的gitconfig:
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
当我添加任何其他的shell内置函数来测试时,它们运行良好:
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
任何想法为什么source命令不能从git中找到?我正在运行zsh,但更改为bash似乎没有什么区别:
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
推荐答案
从!< command>
构造试图通过该名称找到要运行的程序这一事实。有一个 / bin / echo
程序(它与你的shell内建的 echo
不同),但这是一个不同的故事),但不存在 / bin / source
(或 / usr / bin
或其他任何地方)。根据 source
的性质,它不能是一个单独的程序。
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.
试试这个:
[alias]
l = "!sh -c 'source ~/.githelpers && pretty_git_log'"
将 sh
更改为 bash
(或其他)。
Change sh
to bash
(or whatever) as necessary.
这篇关于使用!源的gitconfig别名不起作用(zsh)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!