bash – 如何使用模糊查找程序获取git的分支?
发布时间:2020-12-15 21:44:39 所属栏目:安全 来源:网络整理
导读:我找到了 git examples with fzf(fuzzy finder),他们确实很棒. 喜欢: # fbr - checkout git branchfbr() { local branches branch branches=$(git branch -vv) branch=$(echo "$branches" | fzf +m) git checkout $(echo "$branch" | awk '{print $1}' | se
|
我找到了
git examples with fzf(fuzzy finder),他们确实很棒.
喜欢: # fbr - checkout git branch
fbr() {
local branches branch
branches=$(git branch -vv) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
# fbr - checkout git branch (including remote branches)
fbr() {
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
我在.bashrc中有这个 bind '"C-b": "fbr n"' 按下Ctrl-b之后,我选择一个git的分支,然后在我按Enter键后立即切换,但是有没有办法先输入类似git push staging的东西(然后获取分支列表并将所选分支放在右边的位置)光标是在调用分支列表之前,然后按Enter键将所选分支推送到分段) 例如: 解决方法
这些是我在bash中使用的键绑定
> CTRL-GCTRL-F – git status中列出的文件 请注意,如果您使用的是tmux,则不需要重绘当前行. is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
gf() {
is_in_git_repo &&
git -c color.status=always status --short |
fzf --height 40% -m --ansi --nth 2..,.. | awk '{print $2}'
}
gb() {
is_in_git_repo &&
git branch -a -vv --color=always | grep -v '/HEADs' |
fzf --height 40% --ansi --multi --tac | sed 's/^..//' | awk '{print $1}' |
sed 's#^remotes/[^/]*/##'
}
gt() {
is_in_git_repo &&
git tag --sort -version:refname |
fzf --height 40% --multi
}
gh() {
is_in_git_repo &&
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph |
fzf --height 40% --ansi --no-sort --reverse --multi | grep -o '[a-f0-9]{7,}'
}
gr() {
is_in_git_repo &&
git remote -v | awk '{print $1 " " $2}' | uniq |
fzf --height 40% --tac | awk '{print $1}'
}
bind '"er": redraw-current-line'
bind '"C-gC-f": "$(gf)eC-eer"'
bind '"C-gC-b": "$(gb)eC-eer"'
bind '"C-gC-t": "$(gt)eC-eer"'
bind '"C-gC-h": "$(gh)eC-eer"'
bind '"C-gC-r": "$(gr)eC-eer"'
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
