如何将脚本输出用作.gitconfig中的值?

huangapple go评论59阅读模式
英文:

How to use a script output as a value in .gitconfig?

问题

我想用我的YubiKey签署我的git提交,但仅在我的YubiKey存在时。我有一个名为 yubikey-present.sh 的脚本,可以运行它,如果YubiKey存在,则输出 true,否则输出 false

有没有办法运行这个脚本,并将输出用作 ~/.gitconfigcommit.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)"

huangapple
  • 本文由 发表于 2023年6月22日 06:04:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76527435.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定