LoginSignup
3
1

More than 3 years have passed since last update.

Git等のプロキシを一括設定するバッチファイル[Windows]

Posted at

プロキシという名の『吐き気を催すほどの邪悪』

一括設定バッチファイルを組んで,少しでも作業を効率化してやろうと,模索した.

注意事項

  • hgについては予め,proxy有りを想定したmercurial.inimercurial.ini.proxy.txtとして,proxy無しを想定したmercurial.inimercurial.ini.noproxy.txtとして,ユーザーフォルダに作成しておく.
  • netsh winhttpに関してはWindows 10の「設定アプリ」(8.1以前の場合は「インターネット オプション」)を流用するので,バッチファイル実行前にあらかじめ設定しておく.
  • 管理者権限で実行すること(proxy_pip.batを除く).

プロキシ一括設定

proxy_set.bat
echo off

rem プロキシ設定
set USER_PROXY_ID="username"
set USER_PROXY_PASS="password"
set USER_PROXY="proxy.example.com:8080"

rem netsh winhttp(ここだけGUI設定からのインポート)
netsh winhttp import proxy source=ie

rem git
git config --global http.proxy http://%USER_PROXY_ID%:%USER_PROXY_PASS%@%USER_PROXY%
git config --global https.proxy http://%USER_PROXY_ID%:%USER_PROXY_PASS%@%USER_PROXY%

rem hg
copy /Y %USERPROFILE%\mercurial.ini.proxy.txt %USERPROFILE%\mercurial.ini

プロキシ一括解除

proxy_unset.bat
echo off

rem netsh winhttp
netsh winhttp reset proxy

rem git
git config --global --unset http.proxy
git config --global --unset https.proxy

rem hg
copy /Y %USERPROFILE%\mercurial.ini.noproxy.txt %USERPROFILE%\mercurial.ini

pipについて

  • ユーザーフォルダに,以下のバッチファイルを作っておき,コマンドプロンプトから実行する.以下の設定はコマンドプロンプトの今実行中のプロセスにのみ適用される.(なので,解除したければ一回コマンドプロンプトを閉じればOK)
  • 実行するときのコマンドは%USERPROFILE%\proxy_pip
proxy_pip.bat
set HTTP_PROXY=http://username:password@proxy.example.com:8080
set HTTPS_PROXY=http://username:password@proxy.example.com:8080
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1