From 985090c6f2df359c0e688317939e299d140ec617 Mon Sep 17 00:00:00 2001 From: Diogo Lemos Date: Sat, 15 Jun 2019 17:13:57 +0100 Subject: [PATCH] Fixed fco_preview to correctly show logs. Use git --format to remove dependency on grep, sed and awk. Show branches first. Colour change 'tag' to magenta (from red). Use bash syntax and remove echo at the end --- Examples.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Examples.md b/Examples.md index 2eb4cc0..3536965 100644 --- a/Examples.md +++ b/Examples.md @@ -439,17 +439,17 @@ fco() { # fco_preview - checkout git branch/tag, with a preview showing the commits between the tag/branch and HEAD fco_preview() { local tags branches target - tags=$( -git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return branches=$( -git branch --all | grep -v HEAD | -sed "s/.* //" | sed "s#remotes/[^/]*/##" | -sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') || return + git --no-pager branch --all \ + --format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \ + | sed '/^$/d') || return + tags=$( + git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}') || return target=$( -(echo "$tags"; echo "$branches") | - fzf --no-hscroll --no-multi --delimiter="\t" -n 2 \ - --ansi --preview="git log -200 --pretty=format:%s $(echo {+2..} | sed 's/$/../' )" ) || return - git checkout $(echo "$target" | awk '{print $2}') + (echo "$branches"; echo "$tags") | + fzf --no-hscroll --no-multi -n 2 \ + --ansi --preview="git --no-pager log -150 --pretty=format:%s '..{2}'") || return + git checkout $(awk '{print $2}' <<<"$target" ) } ```