kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

fifo.kak (1115B)


      1 provide-module fifo %{
      2 
      3 define-command -params .. -docstring %{
      4     fifo [-name <name>] [-scroll] [-script <script>] [--] <args>...: run command in a fifo buffer
      5     if <script> is used, eval it with <args> as '$@', else pass arguments directly to the shell
      6 } fifo %{ evaluate-commands %sh{
      7     name='*fifo*'
      8     while true; do
      9         case "$1" in
     10             "-scroll") scroll="-scroll"; shift ;;
     11             "-script") script="$2"; shift 2 ;;
     12             "-name") name="$2"; shift 2 ;;
     13             "--") shift; break ;;
     14             *) break ;;
     15         esac
     16     done
     17     output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-fifo.XXXXXXXX)/fifo
     18     mkfifo ${output}
     19     if [ -n "$script" ]; then
     20         ( eval "$script" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
     21     else
     22         ( "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
     23     fi
     24 
     25     printf %s\\n "
     26             edit! -fifo ${output} ${scroll} ${name}
     27             hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
     28         "
     29     }}
     30 
     31 complete-command fifo shell
     32 
     33 }
     34 
     35 hook -once global KakBegin .* %{ require-module fifo }