Howdoi - Instant answers from the (kak) command line

Need to install via:
$ pip install howdoi

# <https://github.com/gleitz/howdoi>
declare-option -hidden str howdoicmd 'howdoi -n 5'
# <https://github.com/mawww/kakoune/blob/master/rc/tools/grep.kak>
define-command -params .. \
    -docstring %{howdoi [<arguments>]: howdoi --help
    All the optional arguments are forwarded to the howdoi utility
    Instant coding answers via the command line
    <https://github.com/gleitz/howdoi>} \
    howdoi %{ evaluate-commands %sh{
        output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-howdoi.XXXXXXXX)/fifo
        mkfifo ${output}

     if [ $# -gt 0 ]; then
         ( ${kak_opt_howdoicmd} "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
     else
         ( ${kak_opt_howdoicmd} "${kak_selection}" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
     fi

     printf %s\\n "evaluate-commands %{
               edit! -fifo ${output} *howdoi*
               hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
           }"
}}

Defaults to -n 5 answers and terminal does not render colour flag -c
see test_howdoi.py for system settings/usage.

:howdoi format date bash
Summary
★  Answer from https://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script ★
# put current date as yyyy-mm-dd in $date
# -1 -> explicit current date, bash >=4.3 defaults to current time if not provided
# -2 -> start time for shell
printf -v date '%(%Y-%m-%d)T\n' -1 

# put current date as yyyy-mm-dd HH:MM:SS in $date
printf -v date '%(%Y-%m-%d %H:%M:%S)T\n' -1 

# to print directly remove -v flag, as such:
printf '%(%Y-%m-%d)T\n' -1
# -> current date printed to terminal

Cool guys enjoy your week. Bye.

Nice! It reminds me of tldr.kak made by ironzorg https://github.com/lenormf/kakoune-extra/blob/master/tldr.kak

Yeah tldr :white_check_mark: and a short term hope but a long term plan is implementation like explain-shell.kak spit screen and the ability to append to buffer. All requests are cached by howdoi so maybe, maybe not save temp file, probably not, but maybe save search pattern to perfect a search string.

If anyone knows the author ath3 give him a tap on the shoulder point him over here and say: “mate it’s amateur hour, time to crack the knuckles and show this bloke how its done”.

Or anyone else who just wants to give me sh#t and turn this into a kakoune plugin or feature like man.kak for :trophy: time.

Cool cool bye.

http://cheat.sh/

declare-option -hidden str cheat_filetype
define-command -params 1.. cheat %{
    set-option global cheat_filetype %opt{filetype}
    try %{ delete-buffer! *cheat* }
    edit -scratch *cheat*
    execute-keys "!curl cheat.sh/%opt{cheat_filetype}/%sh{echo $@ | tr ' ' '+'}<ret>"
    ansi-render
}

Needs kak-ansi plugin, if you don’t want to use it you can change curl query to

+ execute-keys "!curl cheat.sh/%opt{cheat_filetype}/%sh{echo $@ | tr ' ' '+'}/T<ret>"
- execute-keys "!curl cheat.sh/%opt{cheat_filetype}/%sh{echo $@ | tr ' ' '+'}<ret>"
- ansi-render
3 Likes

Night before xmas @TeddyDD and @eraserhd have just put santa out of business. Run rudolf run, there coming for you!!

Great gift, thanks guys.

Correct query without syntax highlighting is:

execute-keys "!curl cheat.sh/%opt{cheat_filetype}/%sh{echo $@ | tr ' ' '+'}?T<ret>"
1 Like

doing it local:

declare-option -hidden str cheat_filetype

define-command -params 1.. cheat %{
    set-option global cheat_filetype %opt{filetype}
    try %{ delete-buffer! *cheat* }
    edit -scratch *cheat*
    execute-keys "!cht.sh %sh{echo $@}<ret>"
    ansi-render
}

:cheat -help

TeddyDD :clap:

cht script still uses the API but nice implementatnion anyway :slight_smile:

I have to say that cht.sh is one of most useful references and I use it daily.

but, but, but Teddy.
$ curl https://cht.sh/:cht.sh > cht.sh
$ kak cht.sh +76