c4se記:さっちゃんですよ☆

.。oO(さっちゃんですよヾ(〃l _ l)ノ゙☆)

.。oO(此のblogは、主に音樂考察Programming に分類されますよ。ヾ(〃l _ l)ノ゙♬♪♡)

音樂は SoundCloud に公開中です。

考察は現在は主に Scrapbox で公表中です。

Programming は GitHub で開發中です。

Git の proxy をon / off する

当校ではproxyを通さないとInternetに接続できないので辛い。Gitも繋がらないので辛い。とても辛い。
~/.gitconfigでproxyをちゃんと設定できる。commandからも設定できる。どちらも同じことだ。やろう。

set_git_proxy.bat の名で以下をPATHの通った所に保存する。
cf. Windos版whichコマンド (*nix `which` command on Windows (need Ruby).) http://c4se.hatenablog.com/entry/2013/03/24/061210
on / off する option に就いては以下の script を読んで欲しい。
http.proxy と云ふ項目と https.proxy と云ふ項目を設定する。又 ssh も通らないので、ssh の代りに https を使ふ様、url."https://".insteadOf と云ふ項目も設定する。

@echo off
rem setlocal
rem for %%t in (%1) do echo,%%~$path:t
rem for %%e in (%pathext%) do (
rem   for %%t in (%1%%e) do echo,%%~$path:t
rem )
rem endlocal
ruby -x %~f0 %*
@goto end

#!ruby
# coding=utf-8
# author: ne_Sachirou <utakata.c4se@gmail.com>
# date: 2014
# License: Public Domain

$USER = 'ユーザー名!'
$PW = 'パスワード!'
$DOMAIN = 'example.com'
$PORT = '8080'

def git_proxy_on
  puts "git config --global http.proxy http://#{$USER}:#{$PW}@#{$DOMAIN}:#{$PORT}"
       `git config --global http.proxy http://#{$USER}:#{$PW}@#{$DOMAIN}:#{$PORT}`
  puts "git config --global https.proxy http://#{$USER}:#{$PW}@#{$DOMAIN}:#{$PORT}"
       `git config --global https.proxy http://#{$USER}:#{$PW}@#{$DOMAIN}:#{$PORT}`
  puts 'git config --global url."https://".insteadOf git://'
       `git config --global url."https://".insteadOf git://`
end

def git_proxy_off
  puts 'git config --unset --global http.proxy'
       `git config --unset --global http.proxy`
  puts 'git config --unset --global https.proxy'
       `git config --unset --global https.proxy`
  puts 'git config --unset --global url."https://".insteadOf'
       `git config --unset --global url."https://".insteadOf`
end

case ARGV[0]
when 'on'
  git_proxy_on
when 'off'
  git_proxy_off
else
  http_proxy = `git config --get --global http.proxy`
  https_proxy = `git config --get --global https.proxy`
  if http_proxy != '' || https_proxy != ''
    puts 'Git Proxy On to Off'
    git_proxy_off
  else
    puts 'Git Proxy Off to On'
    git_proxy_on
  end
end

:end

set_git_proxy on で proxy を on。set_git_proxy on で proxy を off。set_git_proxy で toggle する。