Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2dedb9573c | |||
| dc302bff1c |
+26
-9
@@ -21,23 +21,40 @@ warn_store_fallback() {
|
||||
EOF
|
||||
}
|
||||
|
||||
# helper 在 `git --exec-path`,不一定在 PATH。必须 exec 绝对路径:
|
||||
# Apple Git 的 osxkeychain 会对 argv[0] 做 O_EXLOCK,相对名会去锁 cwd 下的同名文件。
|
||||
dotfile_git_credential_exec() {
|
||||
local name="$1"
|
||||
shift
|
||||
local helper=""
|
||||
local exec_path
|
||||
exec_path="$(git --exec-path 2>/dev/null || true)"
|
||||
if [ -n "$exec_path" ] && [ -x "$exec_path/git-credential-$name" ]; then
|
||||
helper="$exec_path/git-credential-$name"
|
||||
elif command -v "git-credential-$name" >/dev/null 2>&1; then
|
||||
helper="$(command -v "git-credential-$name")"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
exec "$helper" "$@"
|
||||
}
|
||||
|
||||
case "$(uname -s)" in
|
||||
Darwin)
|
||||
if command -v git-credential-osxkeychain >/dev/null 2>&1; then
|
||||
exec git-credential-osxkeychain "$@"
|
||||
fi
|
||||
dotfile_git_credential_exec osxkeychain "$@" || true
|
||||
warn_store_fallback "未找到 osxkeychain"
|
||||
exec git-credential-store "$@"
|
||||
dotfile_git_credential_exec store "$@" || true
|
||||
;;
|
||||
Linux)
|
||||
if command -v git-credential-libsecret >/dev/null 2>&1; then
|
||||
exec git-credential-libsecret "$@"
|
||||
fi
|
||||
dotfile_git_credential_exec libsecret "$@" || true
|
||||
warn_store_fallback "未找到 git-credential-libsecret"
|
||||
exec git-credential-store "$@"
|
||||
dotfile_git_credential_exec store "$@" || true
|
||||
;;
|
||||
*)
|
||||
warn_store_fallback "未知系统 $(uname -s)"
|
||||
exec git-credential-store "$@"
|
||||
dotfile_git_credential_exec store "$@" || true
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "git credential helper 不可用" >&2
|
||||
exit 1
|
||||
|
||||
+13
-4
@@ -20,18 +20,28 @@ EOF
|
||||
|
||||
dotfile_help_requested "${1:-}" && dotfile_show_help
|
||||
|
||||
set -e
|
||||
set -euo pipefail
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
mise_fail() {
|
||||
echo -e "${RED}mise 安装失败,请检查错误信息${NC}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ! command -v mise &>/dev/null; then
|
||||
echo -e "${YELLOW}mise 未安装. 正在安装 mise...${NC}"
|
||||
curl https://mise.run | sh
|
||||
# 无 pipefail 时 curl 失败 sh 仍可能退出 0,会误报「安装完成」
|
||||
curl -fL --retry 3 https://mise.run | sh || mise_fail
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
|
||||
if ! command -v mise &>/dev/null; then
|
||||
mise_fail
|
||||
fi
|
||||
|
||||
if [ -f ~/.config/fish/config.fish ]; then
|
||||
if ! grep -q "mise activate" ~/.config/fish/config.fish; then
|
||||
echo -e "${YELLOW}正在为 fish shell 配置 mise...${NC}"
|
||||
@@ -72,6 +82,5 @@ fi
|
||||
if command -v mise &>/dev/null; then
|
||||
echo -e "${GREEN}mise 安装成功!${NC}"
|
||||
else
|
||||
echo -e "${RED}mise 安装失败,请检查错误信息${NC}"
|
||||
exit 1
|
||||
mise_fail
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user