whi*_*roi 8 bash command-line fuzzyfinder fzf
我用fzf(模糊查找器)找到了git示例,它们确实很好用.喜欢:
# 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/[^/]*/##")
}
Run Code Online (Sandbox Code Playgroud)
我在.bashrc中有这个
bind '"\C-b": "fbr \n"'
Run Code Online (Sandbox Code Playgroud)
按下Ctrl-b之后,我选择一个git的分支,然后在按Enter键后立即切换,但有没有办法首先输入类似的内容git push staging(然后获取分支列表并将选定的分支放在光标之前的位置调用分支列表,然后按Enter键将所选分支推送到staging)
例如:
git push staging(按Ctrl-B -选择一个分支),我希望得到这个输出-git push staging selected_branch
Jun*_*hoi 11
这些是我在bash中使用的键绑定
git status请注意,redraw-current-line如果您使用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 '/HEAD\s' |
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-g\C-f": "$(gf)\e\C-e\er"'
bind '"\C-g\C-b": "$(gb)\e\C-e\er"'
bind '"\C-g\C-t": "$(gt)\e\C-e\er"'
bind '"\C-g\C-h": "$(gh)\e\C-e\er"'
bind '"\C-g\C-r": "$(gr)\e\C-e\er"'
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 Windows,请尝试git checkout @(git branch -a | fzf).trim()