mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-18 08:13:40 -05:00
update fzf-marker codes
49
Examples.md
49
Examples.md
@@ -33,6 +33,7 @@ Table of Contents
|
||||
* [Vagrant](#vagrant)
|
||||
* [Wrapper](#wrapper)
|
||||
* [LastPass CLI](#lastpass-cli)
|
||||
* [fzf-marker](#fzf-marker)
|
||||
|
||||
|
||||
|
||||
@@ -722,32 +723,42 @@ The terminal command Tweak https://github.com/pindexis/marker.git
|
||||
|
||||
```sh
|
||||
# marker templete select
|
||||
_fzf_marker_display() {
|
||||
local selected
|
||||
if selected=$(cat ${FZF_MARKER_CONF_DIR:-~/.config/marker}/*.txt |
|
||||
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/' |
|
||||
_fzf_marker_main_widget() {
|
||||
if echo "$BUFFER" | grep -q -P "{{"; then
|
||||
_fzf_marker_placeholder
|
||||
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
|
||||
LBUFFER=$(echo $selected | sed 's/\s*#.*//')
|
||||
fi
|
||||
zle redisplay
|
||||
fi
|
||||
zle redisplay
|
||||
}
|
||||
|
||||
# move the cursor the next placeholder
|
||||
function _fzf_move_cursor_to_next_placeholder {
|
||||
match=$(echo "$BUFFER" | perl -nle 'print $& if m{\{\{.+?\}\}}' | head -n 1)
|
||||
if [[ ! -z "$match" ]]; then
|
||||
len=${#match}
|
||||
match=$(echo "$match" | sed 's/"/\\"/g')
|
||||
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'"))')
|
||||
CURSOR="$placeholder_offset"
|
||||
BUFFER="${BUFFER[1,$placeholder_offset]}${BUFFER[$placeholder_offset+1+$len,-1]}"
|
||||
fi
|
||||
_fzf_marker_placeholder() {
|
||||
local strp pos placeholder
|
||||
strp=$(echo $BUFFER | grep -Z -P -b -o "\{\{[\w]+\}\}")
|
||||
strp=$(echo "$strp" | head -1)
|
||||
pos=$(echo $strp | cut -d ":" -f1)
|
||||
placeholder=$(echo $strp | cut -d ":" -f2)
|
||||
if [[ -n "$1" ]]; then
|
||||
BUFFER=$(echo $BUFFER | sed -e "s/{{//" -e "s/}}//")
|
||||
CURSOR=$(($pos + ${#placeholder} - 4))
|
||||
else
|
||||
BUFFER=$(echo $BUFFER | sed "s/$placeholder//")
|
||||
CURSOR=pos
|
||||
fi
|
||||
}
|
||||
|
||||
zle -N _fzf_marker_display
|
||||
zle -N _fzf_move_cursor_to_next_placeholder
|
||||
bindkey "${FZF_MARKER_DISPLAY_KEY:-\C-@}" _fzf_marker_display
|
||||
bindkey "${FZF_MARKER_NEXT_PLACEHOLDER_KEY:-\C-v}" _fzf_move_cursor_to_next_placeholder
|
||||
_fzf_marker_placeholder_widget() { _fzf_marker_placeholder "defval" }
|
||||
|
||||
zle -N _fzf_marker_main_widget
|
||||
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
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user