From 4b21f631c117f4246743f4f6fd809677b0e5d9a0 Mon Sep 17 00:00:00 2001 From: wegt-meoh Date: Wed, 19 Jun 2024 06:16:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0windows=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E8=A1=8C=E5=91=BD=E4=BB=A4=E6=89=A7=E8=A1=8C=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9342d19b0..e46c7c28c 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,31 @@ hosts 文件在每个系统的位置不一,详情如下: 这样每次 hosts 有更新都能及时进行更新,免去手动更新。 -### 2.3 一行命令 (适用于类 Unix 系统) +### 2.3 一行命令 + +#### windows + +使用命令需要安装[git bash](https://gitforwindows.org/) +复制以下命令保存到本地命名为**fetch_github_hosts** + +```shell +_hosts=$(mktemp /tmp/hostsXXX) +hosts=/c/Windows/System32/drivers/etc/hosts +remote=https://raw.hellogithub.com/hosts +reg='/# GitHub520 Host Start/,/# Github520 Host End/d' + +sed "$reg" $hosts > "$_hosts" +curl "$remote" >> "$_hosts" +cat "$_hosts" > "$hosts" + +rm "$_hosts" +``` + +在**CMD**中执行以下命令,执行前需要替换**git-bash.exe**和**fetch_github_hosts**为你本地的路径,注意前者为windows路径格式后者为shell路径格式 + +`"C:\Program Files\Git\git-bash.exe" -c "/c/Users/XXX/fetch_github_hosts"` + +可以将上述命令添加到windows的task schedular(任务计划程序)中以定时执行 #### GNU(Ubuntu/CentOS/Fedora)