英文:
How to use a script output as a value in .gitconfig?
问题
我想用我的YubiKey签署我的git提交,但仅在我的YubiKey存在时。我有一个名为 yubikey-present.sh
的脚本,可以运行它,如果YubiKey存在,则输出 true
,否则输出 false
。
有没有办法运行这个脚本,并将输出用作 ~/.gitconfig
中 commit.gpgsign
的值?我尝试过:
[commit]
gpgsign = !`/path/to/yubikey-present.sh`
但它告诉我:
fatal: bad boolean config value '!`/path/to/yubikey-present.sh`' for 'commit.gpgsign'
英文:
I want to sign my git commits with my Yubikey, but only if my Yubikey is present. I have a script, yubikey-present.sh
that I can run that will output true
if the yubikey is present and false
otherwise.
Is there a way to run this script and use the output as the value for commit.gpgsign
in ~/.gitconfig
? I've tried:
[commit]
gpgsign = !`/path/to/yubikey-present.sh`
But it tells me:
fatal: bad boolean config value '!`/path/to/yubikey-present.sh`' for 'commit.gpgsign'
答案1
得分: 3
你可以尝试编写一个钩子脚本,在每次提交之前更改你的配置。.git/hooks/pre-commit
是一个在每次提交之前运行的钩子脚本。尝试创建一个包含以下内容的脚本:
#!/bin/sh
git config commit.gpgsign "$(/path/to/yubikey-present.sh)"
英文:
You could try writing a hook script that changes your configuration before each commit. .git/hooks/pre-commit
is a hook script that is run before each commit. Try a script that contains this line:
#!/bin/sh
git config commit.gpgsign "$(/path/to/yubikey-present.sh)"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论