junegunn / fzf-git.sh

bash and zsh key bindings for Git objects, powered by fzf
612 stars 53 forks source link

refactor: improve git ref formatting and filtering #53

Closed LangLangBart closed 1 month ago

LangLangBart commented 3 months ago

description

The issue with the current refs is that the sed command is missing the $' in front of the term so that \t (tabs) can be expanded, as my sed version is unable to do so.

Another issue is that assigning FZF_GIT_COLOR=never has no effect because the colorization takes place in the sed part.

Additionally, other refs, for example when doing a git bisect, weren't colorized and would disrupt the columnization.

intended solution

Unfortunately, there is no %(else if) construct available, so one has to construct nested %(if) terms.

open questions

Should other refs like refs/bisect even be listed at all ?

Are the colors okay ?

Would you like me to add a toogle to the ⌥ Option + A keybind in an extra PR or is the feature still too young[^4] ?

--- a/fzf-git.sh
+++ b/fzf-git.sh
@@ -267,5 +267,7 @@ _fzf_git_each_ref() {
     --bind "ctrl-o:execute-silent:bash $__fzf_git {1} {2}" \
     --bind "alt-e:execute:${EDITOR:-vim} <(git show {2}) > /dev/tty" \
-    --bind "alt-a:change-border-label(🍀 Every ref)+reload:bash \"$__fzf_git\" all-refs" \
+    --bind "alt-a:transform:[[ ! \$FZF_BORDER_LABEL =~ Each ]] \
+      && echo 'change-border-label(☘️  Each ref)+reload:bash \"$__fzf_git\" refs' \
+      || echo 'change-border-label(🍀 Every ref)+reload:bash \"$__fzf_git\" all-refs'" \
     --preview "git log --oneline --graph --date=short --color=$(__fzf_git_color .) --pretty='format:%C(auto)%cd %h%d %s' {2} --" "$@" |
   awk '{print $2}'

[^1]: [PATCH 00/15] port branch.c to use ref-filter's printing options [^2]: Git - git-for-each-ref Documentation - %(if) [^3]: Git - git-config Documentation - color [^4]: Add environment variables: FZF_{BORDER,PREVIEW}_LABEL (#3693) · junegunn/fzf@f625c5a · GitHub

junegunn commented 1 month ago

The issue with the current refs is that the sed command is missing the $' in front of the term so that \t (tabs) can be expanded, as my sed version is unable to do so.

Strange, I don't have the problem. Both BSD sed and GNU sed work as expected both on bash and zsh.

echo -e 'foo\tbar' | sed 's/\t/xx/'
echo -e 'foo\tbar' | gsed 's/\t/xx/'

Are you using a different implementation of sed?

LangLangBart commented 1 month ago

Are you using a different implementation of sed?

Yes, I am using an outdated version of sed, found under text_cmds-101.40.1[^1] (macOS 10.15[^2]). The explicit handling of \t as a tab character was introduced in text_cmds-106[^3] (macOS 11).

echo -e 'foo\tbar' | ./sed-101 's/\t/xx/'
# foo   bar
echo -e 'foo\tbar' | ./sed-106 's/\t/xx/'
# fooxxbar

Using a more modern sed version solves the first issue described in the description.

[^1]: Tags · apple-oss-distributions/text_cmds · GitHub [^2]: Apple Open Source - Releases [^3]: text_cmds-106 · apple-oss-distributions/text_cmds@26b7439 · GitHub

LangLangBart commented 1 month ago

rebased

junegunn commented 1 month ago

Thanks, that clarifies. Patch looks good and works well, thanks, and thanks for the patience!

Should other refs like refs/bisect even be listed at all ?

I'm not sure, I rarely use bisect, so I don't know if it's desirable or not.

Are the colors okay ?

Tags used to be brightcyan, let me fix it.

Would you like me to add a toogle to the ⌥ Option + A keybind in an extra PR or is the feature still too young4 ?

It would be nice. I just didn't implement toggling because I didn't feel it's much needed because I can just close the window and re-trigger the binding.