# Howdoi - Instant answers from the (kak) command line

**URL:** <https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777>\
**Category:** Recipes & Guides\
**Tags:** plugins\
**Created:** [November 3, 2019, 7:12pm UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777 "2019-11-03T19:12:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncan](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/duncan/32/95_2.png) [@duncan](https://discuss.kakoune.com/u/duncan)\
**Post date:** [November 3, 2019, 7:12pm UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/1 "2019-11-03T19:12:52Z")

</div>

Need to install via:  
`$ pip install howdoi`

```bash
# <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](https://github.com/gleitz/howdoi/blob/master/test_howdoi.py) for system settings/usage.

```bash
:howdoi format date bash

```

> **Summary**
>
> ```bash
> ★ 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.

---

<div class="post-metadata">

**Author:** ![Delapouite](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/delapouite/32/10_2.png) [@Delapouite](https://discuss.kakoune.com/u/Delapouite)\
**Post date:** [November 3, 2019, 10:18pm UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/2 "2019-11-03T22:18:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![duncan](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/duncan/32/95_2.png) [@duncan](https://discuss.kakoune.com/u/duncan)\
**Post date:** [November 4, 2019, 12:34pm UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/3 "2019-11-04T12:34:46Z")

</div>

Yeah tldr ✅ and a short term hope but a long term plan is implementation like [explain-shell.kak](https://github.com/ath3/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](https://github.com/mawww/kakoune/blob/master/rc/tools/man.kak) for 🏆 time.

Cool cool bye.

---

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [November 5, 2019, 6:45pm UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/4 "2019-11-05T18:45:12Z")

</div>

[http://cheat.sh/](http://cheat.sh/)

```auto
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](https://github.com/eraserhd/kak-ansi) plugin, if you don’t want to use it you can change curl query to

```diff
+ 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

```

---

<div class="post-metadata">

**Author:** ![duncan](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/duncan/32/95_2.png) [@duncan](https://discuss.kakoune.com/u/duncan)\
**Post date:** [December 24, 2019, 4:10am UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/5 "2019-12-24T04:10:56Z")

</div>

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

Great gift, thanks guys.

> [@TeddyDD](#):
>
> [http://cheat.sh/](http://cheat.sh/)

- [kak-ansi](https://github.com/eraserhd/kak-ansi)

---

<div class="post-metadata">

**Author:** ![vbauerster](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/v/85e7bf/32.png) [@vbauerster](https://discuss.kakoune.com/u/vbauerster)\
**Post date:** [September 30, 2020, 4:24am UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/6 "2020-09-30T04:24:21Z")

</div>

> [@TeddyDD](#):
>
> ```auto
> + 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
> 
> ```

Correct query without syntax highlighting is:

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

```

---

<div class="post-metadata">

**Author:** ![duncan](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/duncan/32/95_2.png) [@duncan](https://discuss.kakoune.com/u/duncan)\
**Post date:** [October 19, 2020, 9:42am UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/7 "2020-10-19T09:42:11Z")

</div>

doing it local:

```auto
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`

 ![cheat-00](https://discuss.kakoune.com/uploads/default/original/1X/2b72b84d2bad8fa8a872676738212fb1c4b941a4.png)

TeddyDD 👏

---

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [October 19, 2020, 3:05pm UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/8 "2020-10-19T15:05:22Z")

</div>

cht script still uses the API but nice implementatnion anyway 🙂

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

---

<div class="post-metadata">

**Author:** ![duncan](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/duncan/32/95_2.png) [@duncan](https://discuss.kakoune.com/u/duncan)\
**Post date:** [January 23, 2021, 2:30pm UTC](https://discuss.kakoune.com/t/howdoi-instant-answers-from-the-kak-command-line/777/9 "2021-01-23T14:30:17Z")

</div>

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

 ![cheatsh_standalone_install](https://discuss.kakoune.com/uploads/default/original/1X/5d1d766748102c7f6a3bfb32b300a45392d487db.png)
