Replies: 1 comment
-
Found the way with below script. #!/usr/bin/env bash
fzf_main_cmd()
{
ps -ef
}
NTH_INIT="8"
export -f fzf_main_cmd
CMD_OUTPUT="$(fzf_main_cmd)"
export NTH_HEADER_LIST="$(awk 'NR==1' <<< "$CMD_OUTPUT")"
export NTH_TOTAL="$(awk '{print NF; exit}' <<< "$CMD_OUTPUT")"
fzf_get_nth_header()
{
awk "{print \$$1}" <<< "$NTH_HEADER_LIST"
}
export -f fzf_get_nth_header
fzf_mov_nth()
{
NTH_MOV="$1"
NTH_NUM="$2"
if [[ "$NTH_NUM" == '..' ]]; then
if [[ "$NTH_MOV" == 'next' ]]; then
NTH_NUM="0"
elif [[ "$NTH_MOV" == 'prev' ]]; then
NTH_NUM="$(( NTH_TOTAL + 1 ))"
fi
fi
if [[ "$NTH_MOV" == 'next' ]]; then
NTH_NUM="$(( NTH_NUM + 1 ))"
elif [[ "$NTH_MOV" == 'prev' ]]; then
NTH_NUM="$(( NTH_NUM - 1 ))"
fi
if (( NTH_NUM < 1 )) || (( NTH_NUM > NTH_TOTAL )); then
NTH_NUM="1.."
fi
echo "$NTH_NUM"
}
export -f fzf_mov_nth
fzf \
--reverse \
--nth "$NTH_INIT" \
--info inline \
--header-lines 1 \
--header-border horizontal \
--color nth:regular,fg:dim \
--bind 'ctrl-r:reload(fzf_main_cmd)' \
--bind 'ctrl-n:transform-nth(fzf_mov_nth next ${FZF_NTH})' \
--bind 'ctrl-p:transform-nth(fzf_mov_nth prev ${FZF_NTH})' \
--bind 'result:transform-prompt:echo "$(fzf_get_nth_header ${FZF_NTH})> "' \
<<< "$CMD_OUTPUT" UPDATE 1: add |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First, thanks for the 0.59.0. 👏
I'm looking second example script in below section.
(The one feels like script named
fzf-ps
.)https://junegunn.github.io/fzf/releases/0.58.0/#fzf_nth-environment-variable
This one has
number
prompt for each section whenctrl-n
input happens.But latest 0.59.0, click-header enhancements section example script has nice
text
prompt from $FZF_CLICK_HEADER_WORD.But... we already know what itches our mind... the CLICK. 😅
https://junegunn.github.io/fzf/releases/0.59.0/#click-header-enhancements
So my question is there's way of getting (nth, more like focused) header text (and use as prompt, in this case) without using mouse click?
(Like $FZF_NTH_HEADER_WORD or $FZF_FOCUSED_HEADER_WORD? 🤔)
P.S.
Very interesting github.io page for sure.
hugo-book, right? 👍
Beta Was this translation helpful? Give feedback.
All reactions