【Vimperator】GitHubからgit cloneするコマンド:GitCloneを作った
4244 ワード
「Clone or download」をポチって、コピーして、git clone コピペ
するのが面倒なので、Vimpertorで:GitClone
と打てばブラウザで今見ているリポジトリをgit clone
できるコマンドを作った。
環境はMacを想定。
「Clone or download」に書いてあるURLを取得する関数を書く。
.vimperatorrc
javascript <<EOT
function getGHUrl() {
var input = content.document.querySelector('input.input-mini.input-monospace.js-url-field.js-zeroclipboard-target') || content.document.querySelector('input.form-control.input-monospace.input-sm.js-zeroclipboard-target.js-url-field');
return input.value;
}
EOT
現状のGitHubでも、更新が遅いGitHub Enterpriseで対応できるように、querySelectorを書いておく。
後は、コマンドを書く。
.vimperatorrc
command! -nargs=0 -description="git clone" GitClone js io.system('(output=$((test -d ~/git || mkdir ~/git) && cd ~/git && git clone ' + getGHUrl() + ' 2>&1) && osascript -e "display notification \\\"$output\\\" with title \\\"Vimperator\\\"") &')
~/git以下にgit cloneする設定。git cloneが終わったら出力を通知する。ブラウザが固まらない様に全体を()で囲み、&を付けてバックグラウンドで実行している。
:GitClone
で実行する。
自分はghqを使っているので、:Ghq
というコマンドも作っておく。
.vimperatorrc
command! -nargs=0 -description="ghq" Ghq js io.system('(output=$(~/bin/ghq get ' + getGHUrl() + ' | /usr/local/bin/gsed -r "s/\\x1B\\[([0-9]{1,3}(;[0-9]{1,3})*)?[mK]//g") && osascript -e "display notification \\\"$output\\\" with title \\\"Vimperator\\\"") &')
ghqは~/bin/ghq
とする。ghqの出力はカラーなので、そのシーケンスを
/usr/local/bin/gsed -r "s/\\x1B\\[([0-9]{1,3}(;[0-9]{1,3})*)?[mK]//g"
の部分でとっている。Macに標準で入っているsedは拡張正規表現を使う-r
オプションがないので、brew install gnu-sed
で入れておく。
関連
Author And Source
この問題について(【Vimperator】GitHubからgit cloneするコマンド:GitCloneを作った), 我々は、より多くの情報をここで見つけました https://qiita.com/tmsanrinsha/items/8741074be70c00d72bc9著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .