Last active
October 4, 2023 07:53
-
-
Save kidd/12112ffc44f79ea8b44cadf48243c6a4 to your computer and use it in GitHub Desktop.
pure shell naive version of a picker like fzf (without the filtering, but only picking by number)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fzf is either fzf or a naive version of it | |
# the input is a sed line number, so it can be | |
# single number: 42 | |
# range: 1,10 | |
# separate lines: 10p;50p | |
mute command -v fzf || | |
fzf() { | |
local in=$(cat) | |
for p in "${@}"; do | |
[ "$p" = "-0" ] && [ "$(echo "$in" | wc -l)" -eq 1 ] && [ "" = "$in" ] && return 1 | |
[ "$p" = "-1" ] && [ "$(echo "$in" | wc -l)" -eq 1 ] && [ "" != "$in" ] && echo "$in" && return | |
done | |
# https://superuser.com/questions/1748550/read-from-stdin-while-piping-to-next-command | |
cat -n <(echo "$in") >/dev/tty | |
read -n num </dev/tty | |
echo "$in" | sed -n "${num}p" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment