はじめに
とある日の朝、「さーて、頑張るぞー」と意気込んで
まずはじめにgit checkout .
「..............(昨日の進展全部消えた.. ) 」
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
プログラム
.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