From 5e7e75803b6caaa79988165af1af68a896074b0f Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Mon, 11 Dec 2017 03:53:57 +0100 Subject: [PATCH] added fco_preview: might be really bad code, but it "works for me!" --- Examples.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Examples.md b/Examples.md index 2c1e664..e0258fc 100644 --- a/Examples.md +++ b/Examples.md @@ -244,7 +244,7 @@ Replacing `eval` with `print -z` will push the arguments onto the editing buffer #### With write to terminal capabilities -These have been tested in bash. +These have been tested in bash. ```sh # fh - repeat history @@ -385,6 +385,24 @@ fco() { fzf-tmux -l30 -- --no-hscroll --ansi +m -d "\t" -n 2) || return git checkout $(echo "$target" | awk '{print $2}') } + + +# 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 + target=$( +(echo "$tags"; echo "$branches") | + fzf --no-hscroll --no-multi --delimiter="\t" -n 2 \ + --preview="git log -200 --pretty=format:%s $(echo {+2..} | sed 's/$/../' )" ) || return + git checkout $(echo "$target" | awk '{print $2}') +} + ``` ```sh @@ -481,7 +499,7 @@ ftags() { tm() { [[ -n "$TMUX" ]] && change="switch-client" || change="attach-session" - if [ $1 ]; then + if [ $1 ]; then tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return fi session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found." @@ -887,7 +905,7 @@ _fzf_marker_main_widget() { _fzf_marker_placeholder else local selected - if selected=$(cat ${FZF_MARKER_CONF_DIR:-~/.config/marker}/*.txt | + if selected=$(cat ${FZF_MARKER_CONF_DIR:-~/.config/marker}/*.txt | sed -e "s/\(^[a-zA-Z0-9_-]\+\)\s/${FZF_MARKER_COMMAND_COLOR:-\x1b[38;5;255m}\1\x1b[0m /" \ -e "s/\s*\(#\+\)\(.*\)/${FZF_MARKER_COMMENT_COLOR:-\x1b[38;5;8m} \1\2\x1b[0m/" | fzf --bind 'tab:down,btab:up' --height=80% --ansi -q "$LBUFFER"); then @@ -903,7 +921,7 @@ _fzf_marker_placeholder() { strp=$(echo "$strp" | head -1) pos=$(echo $strp | cut -d ":" -f1) placeholder=$(echo $strp | cut -d ":" -f2) - if [[ -n "$1" ]]; then + if [[ -n "$1" ]]; then BUFFER=$(echo $BUFFER | sed -e "s/{{//" -e "s/}}//") CURSOR=$(($pos + ${#placeholder} - 4)) else @@ -919,4 +937,3 @@ zle -N _fzf_marker_placeholder_widget bindkey "${FZF_MARKER_MAIN_KEY:-\C-@}" _fzf_marker_main_widget bindkey "${FZF_MARKER_PLACEHOLDER_KEY:-\C-v}" _fzf_marker_placeholder_widget ``` -