0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gitのメールアドレスを手軽に変えたい

Posted at

やりたいこと。

gitのメールアドレスを手軽に変えたい。
毎回git config --local user.name aaaとかめんどい(そして、user.name=aaaって打って、できなくてイライラする)。
仕事用と私用で変えたいのです。

.bashrc

GIT_USERSの中を適宜変えて、$HOME/.bashrcに追加。

.bashrc
declare -A GIT_USERS=(
    ["aaa"]="aaa@users.noreply.github.com"
    ["bbb"]="bbb@exmaple.com"
)

## git config complete
_set_git_config.sh() {
  if [ ${COMP_CWORD} == 1 ]; then
    COMPREPLY=( $(compgen -W '${!GIT_USERS[@]}' -- ${COMP_WORDS[${COMP_CWORD}]}) )
  fi
}

function set_git_config(){
    if [ -n "${1}" ] && [ -n "${GIT_USERS[${1}]}" ]; then
        git config --local user.name ${1}
        git config --local user.email ${GIT_USERS[${1}]}
    fi
    git config --show-scope --list | grep user
}

complete -F _set_git_config.sh set_git_config

使い方

set_git_config aaa
補完が利くのでset_git_config [TAB]とかで使えます。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?