mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:39:52 +08:00
Completions: sort local git branches by recency
I have about fifty git branches for fish and I almost always `git checkout` between the most recent two or three - this makes the completions list more usable. If you're using `git cherry-pick` or `git merge`, etc. you also most likely to want to reference a recently changed branch. The decision was made to only sort local branches and not remote ones in the PR at #9248. The performance of changing from one `git for-each-ref` invocation to two separate ones (so we could sort them separately) was checked and found to be OK. Food for future thought: consider ergonomics, caveats, and performance of excluding the current branch's name from the list of completions (or perhaps only from the first completion). Or maybe there's another way to have `for-each-ref` give priority to a different branch while still sorting by recency?
This commit is contained in:
parent
6df57a6712
commit
40a0ea9bea
|
@ -51,11 +51,10 @@ function __fish_git_recent_commits
|
|||
end
|
||||
|
||||
function __fish_git_branches
|
||||
# This is much faster than using `git branch`,
|
||||
# and avoids having to deal with localized "detached HEAD" messages.
|
||||
__fish_git for-each-ref --format='%(refname)' refs/heads/ refs/remotes/ 2>/dev/null \
|
||||
| string replace -r '^refs/heads/(.*)$' '$1\tLocal Branch' \
|
||||
| string replace -r '^refs/remotes/(.*)$' '$1\tRemote Branch'
|
||||
# This is much faster than using `git branch` and avoids dealing with localized "detached HEAD" messages.
|
||||
# We intentionally only sort local branches by recency. See discussion in #9248.
|
||||
__fish_git for-each-ref --format='%(refname:strip=2)%09Local Branch' --sort=-committerdate refs/heads/ 2>/dev/null
|
||||
__fish_git for-each-ref --format='%(refname:strip=2)%09Remote Branch' refs/remotes/ 2>/dev/null
|
||||
end
|
||||
|
||||
function __fish_git_submodules
|
||||
|
@ -64,8 +63,7 @@ function __fish_git_submodules
|
|||
end
|
||||
|
||||
function __fish_git_local_branches
|
||||
__fish_git for-each-ref --format='%(refname:strip=2)' refs/heads/ 2>/dev/null \
|
||||
| string replace -rf '.*' '$0\tLocal Branch'
|
||||
__fish_git for-each-ref --format='%(refname:strip=2)%09Local Branch' --sort=-committerdate refs/heads/ 2>/dev/null
|
||||
end
|
||||
|
||||
function __fish_git_unique_remote_branches
|
||||
|
|
Loading…
Reference in New Issue
Block a user