无论如何,用git偷懒的fish函数【git】
大家所思考的事情
加上并提交并推送。
这件事真麻烦。
只需一个命令即可将内容推送到远程仓库。
所以我创建了一个名为fish的函数。
把以下文件放到~/.config/fish/functions/,然后重新启动fish,你就不需要再添加、提交或推送了。
function zubora -d "zubora 'commit message' [files to add;optional]"
if test (count $argv) -gt 1 # 引数の数が1より多いかどうかでaddの挙動を分岐
# "> git add -n [files]; git add [files]" を出力
set_color white ; echo -n "> "
set_color -o ; echo -n "git "; set_color normal
set_color cyan ; echo -n "add -n $argv[2..-1]"
set_color magenta ; echo -n "; "
set_color -o white; echo -n "git "; set_color normal
set_color cyan ; echo "add $argv[2..-1]"
# git add -n [files]; git add [files] を実行
set_color normal; git add -n $argv[2..-1]; git add $argv[2..-1]
else
# "> git add -n -A; git add -A" を出力
set_color white ; echo -n "> "
set_color -o ; echo -n "git " ; set_color normal
set_color cyan ; echo -n "add -n -A"
set_color magenta ; echo -n "; "
set_color -o white; echo -n "git "; set_color normal
set_color cyan ; echo "add -A"
# git add -n -A; git add -A を実行
set_color normal; git add -n -A; git add -A
end
# feature/n ブランチでは、コミットメッセージに #n をつける
set -l msg
set branch (string split / (git rev-parse --abbrev-ref HEAD))
if test $branch[1] = feature
set msg (string join ' ' $argv[1] (string join '' '#' $branch[2]))
else
set msg $argv[1]
end
# "> git commit -m 'コミットメッセージ'" を出力
set_color white ; echo -n "> "
set_color -o ; echo -n "git " ; set_color normal
set_color cyan ; echo -n "commit -m "
set_color yellow; echo "'$msg'"
# git commit -m 'コミットメッセージ' を実行
set_color normal; git commit -m $msg
# "> git push" を出力
set_color white; echo -n "> "
set_color -o ; echo -n "git " ; set_color normal
set_color cyan ; echo "push"
# > git push を実行
set_color normal; git push
end
用法
$ zubora 'コミットメッセージ' [addするファイル;省略可能]
# コミットメッセージのあとにaddしたいファイルを複数指定
$ zubora 'I want to zubora' i_want_add_commit_push_this.file
# ファイルを指定しない(git add -Aが実行されます)
$ zubora 'I want to metcha zubora'
$ zubora 'Add "git add -n" to zubora function'
# 以下は標準出力
> git add -n -A; git add -A
add '.config/fish/config.fish'
> git commit -m 'Add "git add -n" to zubora function'
[master 661f980] Add "git add -n" to zubora function
1 file changed, 1 insertion(+), 1 deletion(-)
> git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 471 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To git@github.com:kyon-bll/.dotfiles.git
e8e0c2d..661f980 master -> master
$ zubora 'Move zubora function from config.fish to functions' .config/fish/config.fish
> git add -n .config/fish/config.fish; git add .config/fish/config.fish
add '.config/fish/config.fish'
> git commit -m 'Move zubora function from config.fish to functions'
[master bef0edd] Move zubora function from config.fish to functions
1 file changed, 37 insertions(+), 74 deletions(-)
rewrite .config/fish/config.fish (69%)
> git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 469 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To git@github.com:kyon-bll/.dotfiles.git
661f980..bef0edd master -> master
总之
大家也一起懶洋洋吧!