2011年11月22日

GitHub 也推短網址服務 git.io

GitHub 是目前最火紅的開放源碼專案代管服務,目前有超過百萬位註冊會員,並建立超過 300 萬個 Repository。學習 Git 版本控制、擁有一組 GitHub 帳號,就可以將自己開發的軟體原始碼與全世界分享,並透過參與、觀摩優秀的專案和源碼,精進自己的程式設計能力。

Git.io 是 GitHub 的縮短網址(URL Shortener)服務,它只適用 GitHub 提供的服務,包括 Gist(程式碼的剪貼簿)。

使用 curl 指令,就可以建立一組 git.io 的短網址。

curl -i http://git.io -F "url=https://gist.github.com/1372738" | grep Location

執行結果:

Location: http://git.io/iKe9wQ

Git.io 的檢查規則如下,目前僅適用 gist.github.com 及 github.com 兩個 hostname。

/^(gist\.)?github\.com$/

只要 hostname 符合這個規則,包括在 github.com 的個人或組織專頁(http://github.com/個人或組織名稱),或是一個 repository(http://github.com/個人或組織名稱/repository名稱),以及某個 repository 目錄或檔案,都可以建立短網址。

有趣的是,Git.io 允許自訂短網址,但是「先搶先贏」。例如想要將 github.com/lyhcode 縮短為 git.io/lyh ,只要再加上 code= 的參數。

curl -i http://git.io -F "url=https://github.com/lyhcode" -F "code=lyh" | grep Location

執行結果:

Location: http://git.io/lyh

每次都輸入 curl 指令有點麻煩,可以在 ~/.gitconfig 加入以下設定:

[alias]
shorten = "!sh -c 'curl -i http://git.io -F url=$1' -"
shorten2 = "!sh -c 'curl -i http://git.io -F url=$1 -F code=$2' -"

之後只要用 git shorten 指令即可縮短網址。

git shorten https://gist.github.com/1372738
git shorten2 https://lyhcode.com/lyhcode lyh

3 則留言:

  1. 你还在看视频吗!你OUT了!看视频!看AV!还不如约个美女出来打一炮→打炮网址:lad.im/36z

    回覆刪除
  2. 好酷噢!note it!
    不過我都習慣 google 的,chrome 有個壓網址的外掛很好用 XD

    btw, io 縮址是什麽意思呢?我一直很好奇,到處查都找不到。
    .xxx 是色情業,.tv 是電視節目,.js 是 javascript,.io stands for ??

    回覆刪除
  3. .io 是 ccTLD,為 British Indian Ocean Territory 所屬,但是看起來感覺蠻 geek 的!goo.gl 不限網站來源~ git.io 則是 GitHub 專用的短網址~

    回覆刪除

lyhcode by lyhcode
歡迎轉載,請務必註明出處!