PowerShellでGitショートカット

GitといえばTerminal

素敵な記事を見かけた。寿命を延ばす事ができるらしい。 postd.cc

しかし、僕はVisual Studio愛好家であり
開発環境はWindowsなのである。(実機はmacだけどね!)

WindowsといえばPowerShell

PowerShellでもエイリアス登録してショートカットすればいいいじゃない!
と思ってた時期がありました。
でも、駄目でした。コマンドラインが渡せませんでした。

Functionにしよう!

というわけで、僕が使っている設定ファイルの一部がこちら。 やたらと使うコマンド達。

remove-item alias:gcm -force
remove-item alias:gl -force
remove-item alias:gp -force
remove-item alias:gps -force

function gs(){ git status }
function ga(){ git add $args }
function gaa(){ git add -A }
function gcm(){ git commit -m $args }
function gcam(){ git commit --amend -m $args }
function gl() { git log }
function glg() { git log --graph --oneline --decorate --all }
function gld() { git log --pretty=format:"%h %ad %s" --date=short --all }
function gls() { git log --stat --decorate }
function glns() { git log --stat --name-status --decorate }
function gls() { git log --stat --decorate --grep=$args }
function gdt() { git difftool $args }
function gp() { git pull $args }
function gps() { git push $args }
function grsh { git reset --soft HEAD^ }
function grhh { git reset --hard HEAD^ }

こいつらを、$profileで出力される設定ファイルに書き込んであげてください。
remove-item aliasをしているのは、組み込みエイリアスと被っちゃうからです。
書き込んだら、.$profileで読み込み直してくださいね。

使用例はこんな感じ

gs
gaa
gcm "コメント"
gps origin master