60 lines
1.5 KiB
Bash
60 lines
1.5 KiB
Bash
# Various functions
|
|
|
|
# This prompts the user for a "yes" or a "no"
|
|
# @argument $1: Question
|
|
# @argument $2: Content to show in preview window
|
|
# @return: 0 if the user answered "yes" and 1 otherwise.
|
|
ynprompt() {
|
|
return "$(printf '0 \033[32myes\033[0m\n1 \033[31mno\033[0m\n' |
|
|
$FZF \
|
|
--sync \
|
|
--bind='start:pos(2)' \
|
|
--bind='ctrl-c,ctrl-g,ctrl-q,esc:pos(2)+accept' \
|
|
--reverse \
|
|
--no-input \
|
|
--header="$1" \
|
|
--preview-window='60%,border-line' \
|
|
--margin='5%,5%,5%,15%' \
|
|
--preview="echo \"$2\"" \
|
|
--with-nth=2.. \
|
|
--accept-nth=1 \
|
|
--header-border='line' \
|
|
--color='border:yellow,header:yellow')"
|
|
}
|
|
|
|
# This prompts the user for a series of options.
|
|
# The options are read from stdin in the form "integer\toption\n".
|
|
# Prints number
|
|
#
|
|
# @argument $1: Question
|
|
# @argument $2: Content to show in preview window
|
|
multiprompt() {
|
|
cat |
|
|
$FZF \
|
|
--reverse \
|
|
--no-input \
|
|
--header="$1" \
|
|
--preview-window='60%,border-line,wrap-word' \
|
|
--margin='5%,5%,5%,15%' \
|
|
--preview="echo \"$2\"" \
|
|
--with-nth=2.. \
|
|
--accept-nth=1 \
|
|
--header-border='line' \
|
|
--bind="ctrl-c,esc,ctrl-q:" \
|
|
--color='border:yellow,header:yellow' | head -1 || true
|
|
}
|
|
|
|
# ASCII-encode address
|
|
# asciiaddress() {
|
|
# firstword=1
|
|
# for word in $*; do
|
|
# [ "${firstword:-}" ] || echo -n ' ' && firstword=
|
|
# case $word in
|
|
# *[![:cntrl:][:print:]]*) echo -n $word ;;
|
|
# *) return 0 ;;
|
|
# esac
|
|
# isascii "$word" && echo -n "$word" || echo -n "=?UTF-8?B?$(echo -n "$word" | base64)?="
|
|
# done
|
|
# }
|
|
|