Replies: 2 comments
-
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
-
And here's #!/usr/bin/env bash
fzf_main_cmd()
{
#ps -ef
ps -fu $USER
}
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.."
elif (( NTH_NUM == NTH_TOTAL )); then
NTH_NUM+=".."
fi
echo "$NTH_NUM"
}
export -f fzf_mov_nth
export FZF_PS_BINDINGS="h,j,J,k,K,l,g,G,q,r,/"
fzf \
--wrap \
--layout reverse-list \
--no-input \
--nth "$NTH_INIT" \
--info inline \
--header-lines 1 \
--header-border horizontal \
--color nth:regular,fg:dim \
--bind 'h:transform-nth(fzf_mov_nth prev ${FZF_NTH%..})+transform:
if [[ $FZF_QUERY ]]; then
echo "show-input+clear-query"
fi' \
--bind 'j:down,k:up' \
--bind 'g:first,G:last,J:page-down,K:page-up' \
--bind 'l:transform-nth(fzf_mov_nth next ${FZF_NTH%..})+transform:
if [[ $FZF_QUERY ]]; then
echo "show-input+clear-query"
fi' \
--bind 'q:abort' \
--bind 'r:transform:
echo -n "reload(fzf_main_cmd)"
if [[ "$FZF_QUERY" ]]; then
echo "+show-input+clear-query"
fi' \
--bind "/:show-input+unbind($FZF_PS_BINDINGS)" \
--bind 'enter,esc,ctrl-c:transform:
if [[ $FZF_INPUT_STATE = enabled ]]; then
echo "rebind($FZF_PS_BINDINGS)+hide-input"
elif [[ $FZF_KEY = enter ]]; then
echo accept
else
echo abort
fi' \
--bind 'change:transform:
if [[ ! $FZF_QUERY ]]; then
if [[ $FZF_KEY == h ]] || [[ $FZF_KEY == l ]] || [[ $FZF_KEY == r ]]; then
echo "rebind($FZF_PS_BINDINGS)+hide-input"
fi
fi' \
--bind 'result:transform-prompt:echo "$(fzf_get_nth_header ${FZF_NTH%..})> "' \
<<< "$CMD_OUTPUT" | awk '{print $2}' |
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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