m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-18 16:45:38 -05:00

update fzf-marker codes

hanson
2017-06-01 11:22:37 -05:00
parent 39231d907f
commit 0bf387a674

@@ -33,6 +33,7 @@ Table of Contents
* [Vagrant](#vagrant) * [Vagrant](#vagrant)
* [Wrapper](#wrapper) * [Wrapper](#wrapper)
* [LastPass CLI](#lastpass-cli) * [LastPass CLI](#lastpass-cli)
* [fzf-marker](#fzf-marker)
@@ -722,32 +723,42 @@ The terminal command Tweak https://github.com/pindexis/marker.git
```sh ```sh
# marker templete select # marker templete select
_fzf_marker_display() { _fzf_marker_main_widget() {
local selected if echo "$BUFFER" | grep -q -P "{{"; then
if selected=$(cat ${FZF_MARKER_CONF_DIR:-~/.config/marker}/*.txt | _fzf_marker_placeholder
sed -e 's/\(^[a-zA-Z0-9_-]\+\)\s/\x1b[38;5;255m\1\x1b[0m /' -e 's/\s*\(#\+\)\(.*\)/\x1b[38;5;8m \1\2\x1b[0m/' | else
local selected
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 fzf --bind 'tab:down,btab:up' --height=80% --ansi -q "$LBUFFER"); then
LBUFFER=$(echo $selected | sed 's/\s*#.*//') LBUFFER=$(echo $selected | sed 's/\s*#.*//')
fi
zle redisplay
fi fi
zle redisplay
} }
# move the cursor the next placeholder _fzf_marker_placeholder() {
function _fzf_move_cursor_to_next_placeholder { local strp pos placeholder
match=$(echo "$BUFFER" | perl -nle 'print $& if m{\{\{.+?\}\}}' | head -n 1) strp=$(echo $BUFFER | grep -Z -P -b -o "\{\{[\w]+\}\}")
if [[ ! -z "$match" ]]; then strp=$(echo "$strp" | head -1)
len=${#match} pos=$(echo $strp | cut -d ":" -f1)
match=$(echo "$match" | sed 's/"/\\"/g') placeholder=$(echo $strp | cut -d ":" -f2)
placeholder_offset=$(echo "$BUFFER" | python -c 'import sys;keyboard_input = raw_input if sys.version_info[0] == 2 else input; print(keyboard_input().index("'$match'"))') if [[ -n "$1" ]]; then
CURSOR="$placeholder_offset" BUFFER=$(echo $BUFFER | sed -e "s/{{//" -e "s/}}//")
BUFFER="${BUFFER[1,$placeholder_offset]}${BUFFER[$placeholder_offset+1+$len,-1]}" CURSOR=$(($pos + ${#placeholder} - 4))
fi else
BUFFER=$(echo $BUFFER | sed "s/$placeholder//")
CURSOR=pos
fi
} }
zle -N _fzf_marker_display _fzf_marker_placeholder_widget() { _fzf_marker_placeholder "defval" }
zle -N _fzf_move_cursor_to_next_placeholder
bindkey "${FZF_MARKER_DISPLAY_KEY:-\C-@}" _fzf_marker_display zle -N _fzf_marker_main_widget
bindkey "${FZF_MARKER_NEXT_PLACEHOLDER_KEY:-\C-v}" _fzf_move_cursor_to_next_placeholder 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
``` ```