alexherbo2 / kakoune.cr

A command-line tool for Kakoune
https://kakoune.org
The Unlicense
54 stars 11 forks source link

Working with Kitty and kcr #14

Closed alecStewart1 closed 3 years ago

alecStewart1 commented 3 years ago

I use Kitty for my terminal, because I've found that things like Alacritty + tmux is acutally pretty slow.

In order to create splits with Kitty and Kakoune, I have the following code:

# Providing a means to create splits like the tmux module can,
# but with kitty instead.
#
# Thank you user joefiorini:
# https://github.com/joefiorini/joeconf-kakoune-plugins/blob/master/plugins/kitty.kak

provide-module kitty-split %[

# Ensure we don't load built-in kitty module
set-option global windowing_modules

declare-option str kitty_split_default_location "last"
declare-option str kitty_split_default_type "window"

define-command kitty-split -params .. -shell-completion -docstring '
kitty-split [location] [type] [<arguments>]: create a new terminal window as a kitty split
Accepts --horizontal or --vertical for the location of the split
Any extra arguments will be passed to "kitty @ launch"' \
%{
  nop %sh{
    echo "arg: <<${1}>>" 1>&2
    kitty_locations=(vsplit before hsplit after last neighbor first)
    kitty_split_types=(window tab primary clipboard os-window background overlay)

    case "${kitty_locations[@]}" in
      *"${1}"*)
        split_arg=$1
        shift
        ;;
    esac

    case "${kitty_split_types[@]}" in
      *"${1}"*)
        type_arg=$1
        shift
        ;;
    esac

    echo "split_arg: <<${split_arg:-$kak_opt_kitty_split_default_location}>>" 1>&2
    echo "type_arg: <<${type_arg:-$kak_opt_kitty_split_default_type}>>" 1>&2
    echo "shifted: <<${1}>>" 1>&2
    kitty @ launch --no-response --type="${type_arg:-$kak_opt_kitty_split_default_type}" --cwd="$PWD" --location="${split_arg:-$kak_opt_kitty_split_default_location}" "${@}"
  }
}

define-command kitty-split-horizontal -params .. -shell-completion -docstring '
kitty-split-horizontal [<arguments>]: create a new terminal window above or below
the current window.
Any extra arguments will be passed to "kitty @ launch"' \
%{
    kitty-split hsplit %arg{@}
}

define-command kitty-split-vertical -params .. -shell-completion -docstring '
kitty-split-vertical [<arguments>]: create a new terminal window to the left or right of
the current window.
Any extra arguments will be passed to "kitty @ launch"' \
%{
    kitty-split vsplit %arg{@}
}

define-command kitty-overlay -params .. -shell-completion -docstring '
kitty-overlay [<arguments>]: create a new terminal window on top of the current window.
Any extra arguments will be passed to "kitty @ launch"' \
%{
  kitty-split overlay %arg{@}
}

require-module kitty

unalias global terminal kitty
alias global terminal kitty-split
alias global focus kitty-focus
]

However, when trying to create a split with doing :kitty-split kcr edit, I'll get back:

Failed to launch child: kcr
With error: No such file or directory
Press Enter to exit

I'm launch kakoune with kcr edit, being as an alias k. So I don't exactly know how I can use kcr with Kitty.

Some guidance would be appreciated, and maybe even some examples in the share/kcr/init/example.kak would be great too!

alexherbo2 commented 3 years ago

The basic command to open a new connected terminal is >. The command is an alias to connect terminal. To connect a command, you can do for example connect kitty-split-horizontal.

Do not do kcr edit. I guess you want to attach. Just do new.

No such file or directory means you don’t have kcr in your path when launching.

As a side note, it does not look right for kitty-split to be aliased to terminal because it handles the location and type options of kitty. The terminal command is an abstraction to <terminal> -e or <terminal> -e sh -c to run programs. With this alias, we are for example unable to do terminal tab — where tab is a valid command.

alecStewart1 commented 3 years ago

To connect a command, you can do for example connect kitty-split-horizontal.

Ooooooh.

I guess you want to attach. Just do new.

See, I do that and for a brief seconds, I see a new tab or split coming up for like a brief second...then nothing. There's no new tab or split. Now if I press the keys configured for kitty to do those things, it works as normal.

No such file or directory means you don’t have kcr in your path when launching.

I mean, it is in my path. ~/.local/bin which contains kcr is in my path, so I don't exactly know what to do there. Though maybe that's working as intended.

alexherbo2 commented 3 years ago

If new doesn’t work, there is something not related to kakoune.cr.

For kcr launching, I suspect you do not have ~/.local/bin in your path at the moment of launching, but set when you connect to your shell. It can be verified with terminal sh -c 'echo "$PATH" > ~/path.txt'.

For new, it may also be due to terminal not doing a perfect forwarding of the arguments.

alecStewart1 commented 3 years ago

If new doesn’t work, there is something not related to kakoune.cr.

Hmmm, I'll look at the code for kitty module for Kakoune, and look at what I have for my kitty-split stuff. Or maybe it's related to my configuration for Kitty. I'll have to look around.

I suspect you do not have ~/.local/bin in your path at the moment of launching

Hmm, that's weird.

For new, it may also be due to terminal not doing a perfect forwarding of the arguments.

Well, I'm not sure how I could debug that.

alecStewart1 commented 3 years ago

Nope. ~/.local/bin is in my path. Even other directories I've added to my PATH, like ~/bin, are in there.

I just opened up the *scratch* buffer and did :!sh -c 'echo $PATH'.

alexherbo2 commented 3 years ago

!sh is different from making kitty launching a new process. Please try with the terminal command to see.

alecStewart1 commented 3 years ago

Ah, yup. ~/.local/bin is not there. So how do I remedy this?

alexherbo2 commented 3 years ago

Maybe set your path in your profile file, instead of your shell.

alecStewart1 commented 3 years ago

In ~/.profile? That doesn't change anything. Weird.

alexherbo2 commented 3 years ago

Try to restart your environment.

alecStewart1 commented 3 years ago

Ah, yup! There we go! Thanks!

joefiorini commented 3 years ago

@alecStewart1 Unrelated to the issue at hand, but as the author of the original code I just wanted to point out that the built-in kitty support now uses the launch command and accepts additional parameters to pass on to kitty. You can now simply do `:terminal --location=vsplit", etc. and it will "just work". I've been updating my configs to do that, hopefully will publish it eventually. Also thanks for the shoutout in your config, really made my day!