LoginSignup
1
1

More than 3 years have passed since last update.

git checkout . を打つと「本当にいいのか?」と念を押されるようにした

Last updated at Posted at 2019-09-07

はじめに

とある日の朝、「さーて、頑張るぞー」と意気込んで
まずはじめにgit checkout .
「..............(昨日の進展全部消えた.. :smile:) 」

git checkoutコマンドってブランチを切る時にも使うのに(gitの最新バージョンでは変わりますけど..)こういう怖さがあるので、
仮に間違えてgit checkout .コマンドを打ってもアラートがでるようにしました。

I just finally know what I have to do. And I know in my heart that it’s right.(やっとやるべきことがわかったんだ。そして、心から思っている。それは正しいと) -- トニー・スターク

動作環境

OS: mac OS Mojave 10.14.14
shell: zsh

プログラム

preexec_functions=()
preexec_functions+=(show_alert_git_checkout)
show_alert_git_checkout() {
   local cmd="${1}"
   if [[ $cmd = "git checkout ." ]]; then
     echo "Are you sure to use 'git checkout .' ? (y/N): "
     if read -q; then
       echo "start execute 'git checkout .'"
     else
       kill -INT 0 # stop git checkout .
     fi
   fi
}

実行結果

// case yes
name% git checkout .
Are you sure to use 'git checkout .' ? (y/N):
ystart execute 'git checkout .'
name%
name%

// case no

name% git checkout .
Are you sure to use 'git checkout .' ? (y/N):
n%
name%
name%

参考文献

https://kakurasan.hatenadiary.jp/entry/20080326/p1
http://zsh.sourceforge.net/Doc/Release/Functions.html
http://web.cs.elte.hu/zsh-manual/zsh_17.html

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