用 ghproxy 加速 Doom Emacs 安装

这里使用的服务是:

感谢相关人员的付出!

用法

用 ghproxy 替换 github 地址

git config --global url."https://ghproxy.com/https://github".insteadOf https://github

安装 doom

git clone --depth 1 https://github.com/doomemacs/doomemacs ~/.emacs.d
DOOMGITCONFIG=~/.gitconfig ~/.emacs.d/bin/doom install
  1. 如果操作正常,git clone 应该飞快。(笔者测试时一度达到了惊人的 15M/s。)
  2. 要手动指定一下 DOOMGITCONFIG 是因为 doom 默认不读取 ~/.gitconfig

Enjoy!

16 个赞

大佬牛逼!解决了 :+1:

希望能用久一些

感谢!留一个名标记一下。

按照这个说明, 去安装 doom emacs, 确实成功了.

不过同时产生了一个问题: git push 的时候, 似乎也要经过这个代理 , 但是, 它是禁止这样操作的.

使用 --unset 取消一下 git 的设置:

git config --global --unset url."https://ghproxy.com/https://github".insteadOf https://github

查看设置可以用:git config -l

1 个赞

学到了,之前在自己调整上游地址…… :melting_face:

;;; cfg-package-vc.el --- Handle VC packages

;;; Commentary:

;;; Code:
(eval-when-compile (require 'rx))
(require 'cl-lib)
(require 'cfg-package)
(require 'package-vc)

(defconst cfg-package-vc--package-proxies
  `((,(rx string-start (group) "https://github.com")
     "https://ghproxy.com/" 1))
  "List of proxy definitions.
Each proxy definition should match (REGEXP REPLACE &optional
GROUP), where REGEXP is the regexp to be replaced, REPLACE is the
target replacement string.  When GROUP is nil, replace the entire
match with REPLACE; otherwise replace the matching group number
or name with REPLACE.")

(defun cfg-package-vc--package-proxy (package)
  "Proxy the package definition PACKAGE."
  (declare (pure t) (side-effect-free t))
  (let* ((pname (car-safe package))
         (plist (cdr-safe package))
         (url (plist-get plist :url)))
    (unless url
      (user-error "Package `%s' should include a `:url' spec"
                  package))
    (cl-dolist (proxy cfg-package-vc--package-proxies package)
      (cl-destructuring-bind
          (regexp replace &optional group) proxy
        (save-match-data
          (when (string-match regexp url)
            (let* ((group (or group 0))
                   (url (replace-match replace nil t url group)))
              (cl-return (cl-list* pname :url url plist)))))))))

(defun cfg-package-vc-install--advice (args)
  "Advice for `package-vc-install' filtering ARGS."
  (declare (pure t) (side-effect-free t))
  (cl-destructuring-bind (package &optional rev backend) args
    (list (cfg-package-vc--package-proxy package) rev backend)))

(advice-add #'package-vc-install
            :filter-args #'cfg-package-vc-install--advice)

;;;###autoload
(defun cfg-package-vc-install (direct &optional proxied)
  "Install packages specified from DIRECT and PROXIED.
DIRECT means direct installation; PROXIED means under a proxy."
  (let* ((all-packages (mapcar #'car (append direct proxied)))
         (all-pkgs (seq-uniq all-packages)))
    (unless (eq (length all-packages) (length all-pkgs))
      (user-error "Duplicate packages specified in %S"
                  `((direct ,direct) (proxied ,proxied))))
    (setq package-vc-selected-packages
          (append direct
                  (mapcar #'cfg-package-vc--package-proxy proxied)
                  (seq-filter (lambda (e) (memq (car e) all-pkgs))
                              package-vc-selected-packages)))
    (package-install-selected-packages)
    (package-vc-install-selected-packages)))

(provide 'cfg-package-vc)
;;; cfg-package-vc.el ends here.
1 个赞

太感谢大佬了,试了好久,终于使用这个方法成功了!!!

我注意到一点,git push时如果使用 ssh ([email protected])就一般不会出现卡顿现象?所以另一种解法可以是把push地址修改为ssh。