LoginSignup
4
1

More than 5 years have passed since last update.

git add --all; git commit -m 'first commit'; git push --all を省略化する

Last updated at Posted at 2016-10-01

はじめに

Gitでの追加、コミット、プッシュのコマンドが長いのでZshで省略可しました。
下記のようなコードを一発で打ちたいです。

$ git add --all; git commit -m 'first commit'; git push --all

これを

$ ga -m 'first commit'

こんな感じに省略化します。

簡単なコミット方法を身近なエンジニアに聞いてみましたが「エイリアス化じゃない?」ということだったのでエイリアス化して、その後でコミットメッセージを付けるために関数化しました。

導入方法

コードです。

git-add-all-git-commit-git-push-all.zsh
#!/usr/bin/env zsh

# git add --all; git commit -m 'first commit'; git push --allgit add --all; git commit -m 'first commit'; git push --all をしてくれるコマンド

# Thanks @link http://qiita.com/mollifier/items/eba71bc33bb7e3b76233
# Thanks @link http://qiita.com/petitviolet/items/b1e8b5139169dd530919
# Thanks @link http://qiita.com/mollifier/items/6fdeff2750fe80f830c8

# Usage: ga [-m|--message message]
function ga() {
  local -A opthash
  local MESSAGE
  zparseopts -D -A opthash -- -help h -message: m:
  if [[ -n "${opthash[(i)--help]}" ]]; then
    echo 'Usage: ga [-m|--message message]'
    return 0
  fi
  if [[ -n "${opthash[(i)-h]}" ]]; then
    echo 'Usage: ga [-m|--message message]'
    return 0
  fi

  if [[ -n "${opthash[(i)--message]}" ]]; then
     MESSAGE=${opthash[--message]}
  fi
  if [[ -n "${opthash[(i)-m]}" ]]; then
     MESSAGE=${opthash[-m]}
  fi
  if [[ $MESSAGE ]] then
     CMD="git add --all; git commit -m '${MESSAGE}'; git push --all"
  else
     CMD="git add --all; git commit -m 'Automatically commit'; git push --all"
  fi
  eval ${CMD}
}

_gacmd() {
  _arguments \
  -m'[commit message]' \
  --message'[commit message]'
}

compdef _gacmd ga

ファイルを作って

$ source git-add-all-git-commit-git-push-all.zsh

sourceで読ませます。

でもsourceは良くないらしいので、将来的には他の方法にしたいです。

zsh で source して使うプラグインを作るのは止めにしよう
http://qiita.com/mollifier/items/6fdeff2750fe80f830c8

githubにコードを置いてみました。名前が長いのは当てつけです。

https://github.com/yousan/git-add-all-git-commit-git-push-all

使い方

$ ga

と打つだけでadd, コミット、プッシュをしてくれます。
このままだとコミットメッセージが自動で付いてしまいますが、-mオプションを付けるとコミットメッセージも指定出来ます。

$ ga -m 'hoge message'
4
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
4
1