kakoune

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

kitty.kak (3055B)


      1 # https://sw.kovidgoyal.net/kitty/index.html
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 provide-module kitty %{
      5 
      6 # ensure that we're running on kitty
      7 evaluate-commands %sh{
      8     [ -z "${kak_opt_windowing_modules}" ] || [ "$TERM" = "xterm-kitty" ] || echo 'fail Kitty not detected'
      9 }
     10 
     11 declare-option -docstring %{window type that kitty creates on new and repl calls (window|os-window)} str kitty_window_type window
     12 
     13 define-command kitty-terminal-window -params 1.. -docstring '
     14 kitty-terminal-window <program> [<arguments>]: create a new terminal as a kitty window
     15 The program passed as argument will be executed in the new terminal' \
     16 %{
     17     evaluate-commands %sh{
     18         match=""
     19         if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
     20             match="--match=window_id:$kak_client_env_KITTY_WINDOW_ID"
     21         fi
     22 
     23         listen=""
     24         if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then
     25             listen="--to=$kak_client_env_KITTY_LISTEN_ON"
     26         fi
     27 
     28         kitty @ $listen launch --type="$kak_opt_kitty_window_type" --cwd="$PWD" $match "$@" >/dev/null ||
     29             echo 'fail %{kitty-terminal-window: failure running `kitty @`, see `:buffer *debug*`}'
     30     }
     31 }
     32 complete-command kitty-terminal-window shell
     33 
     34 define-command kitty-terminal-tab -params 1.. -docstring '
     35 kitty-terminal-tab <program> [<arguments>]: create a new terminal as kitty tab
     36 The program passed as argument will be executed in the new terminal' \
     37 %{
     38     evaluate-commands %sh{
     39         match=""
     40         if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
     41             match="--match=window_id:$kak_client_env_KITTY_WINDOW_ID"
     42         fi
     43 
     44         listen=""
     45         if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then
     46             listen="--to=$kak_client_env_KITTY_LISTEN_ON"
     47         fi
     48 
     49         kitty @ $listen launch --type=tab --cwd="$PWD" $match "$@" >/dev/null ||
     50             echo 'fail %{kitty-terminal-tab: failure running `kitty @`, see `:buffer *debug*`}'
     51     }
     52 }
     53 complete-command kitty-terminal-tab shell
     54 
     55 define-command kitty-focus -params ..1 -docstring '
     56 kitty-focus [<client>]: focus the given client
     57 If no client is passed then the current one is used' \
     58 %{
     59     evaluate-commands %sh{
     60         if [ $# -eq 1 ]; then
     61             printf "evaluate-commands -client '%s' focus" "$1"
     62         else
     63             match=""
     64             if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
     65                 match="--match=id:$kak_client_env_KITTY_WINDOW_ID"
     66             fi
     67 
     68             listen=""
     69             if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then
     70                 listen="--to=$kak_client_env_KITTY_LISTEN_ON"
     71             fi
     72 
     73             kitty @ $listen focus-window $match >/dev/null ||
     74                 echo 'fail %{kitty-focus: failure running `kitty @`, see `:buffer *debug*`}'
     75         fi
     76     }
     77 }
     78 complete-command -menu kitty-focus client
     79 
     80 alias global focus kitty-focus
     81 
     82 # deprecated
     83 define-command -hidden kitty-terminal -params 1.. %{
     84     kitty-terminal-window %arg{@}
     85 }
     86 
     87 }