Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kitty <= 0.36.4] Suggestions for 'kitty kitten' result in 'bash: _command_offset: command not found' #512

Open
ozmodeuz opened this issue Sep 30, 2024 · 6 comments
Labels
External Problem/Bug Problems/Bugs of other projects

Comments

@ozmodeuz
Copy link

ble version: 0.4.0-devel4+670c7ea
Bash version: 5.2.37(1)-release (x86_64-pc-linux-gnu)

Hi, when I use the kitty terminal, and type 'kitty kitten' to invoke one of kitty's plugins, as soon as I type a character following 'kitty kitten ' I get the error 'bash: _command_offset: command not found' followed by a suggestion of a command. E.g.:

image

In the above screenshot, 'kitty kitten a' is what I typed, followed by the error, and then an actual suggestion.

If I keep typing I get more errors, the number of which seems to vary based on how fast I type:

image

Above you can see I typed 'bcd' following 'a' and got a bunch more errors.

It seems likely this is actually a kitty issue, but in order to report that I think I need to know a bit more about what ble.sh is trying to do.

A few notes:

  1. Despite the errors I can keep typing, enter the name of a plugin, and successfully run it. If I do, then typing that specific name no longer results in the errors (but entering any other text following kitty kittens does)
  2. It doesn't happen outside kitty terminal; hence why I think its probably a kitty issue really
  3. I've realised that I don't actually have to run 'kitty kittens' to use kitty's plugins; I can just do 'kitten [name of plugin]' - however I'd like to figure out if there's an issue with my bash/kitty setup, or with kitty itself that's causing the error

I'd appreciate any guidance on getting to the bottom of this.

Thanks,

Oz

@akinomyoga
Copy link
Owner

Sorry for the delayed reply. I'm busy recently.

This is related to the completion setting for the kitty command. In the plain Bash, a broken completion setting would cause an issue only when the user explicitly requests the completion by pressing Tab, but in ble.sh with auto-complete enabled, ble.sh dynamically attempts calling the completion setting so that the error messages would appear even before the user requests the TAB completion. Just to confirm the situation, I have several questions:

  • Q1: What are the results of the following commands?
$ ble/widget/display-shell-version
$ declare -p BASH_COMPLETION_COMPAT_DIR
  • Q2: Does the error message stop if you turn off the auto-complete feature?
$ bleopt complete_auto_complete=
$ kitty kitten    # <-- does the error message appear?
  • Q3: Does the problem reproduce without ble.sh when you attempt a TAB completion by pressing TAB?

The issue is probably because bash-completion is not properly set up for kitty's shell integration code. kitty tries to call _command_offset through the completion function _ksi_completions in kitty's shell integration. However, _command_offset is a function provided by the project scop/bash-completion, which means that kitty's shell integration actually requires bash-completion, though kitty doesn't seem to mention that in its manual.

  • One possibility is that kitty tries to load bash-completion in the background, but it is failing for some reason.
  • Another possibility is that bash-completion is actually loaded, but the API _command_offset is somehow failing to be activated due to a custom value of BASH_COMPLETION_COMPAT_DIR or something.

@ozmodeuz
Copy link
Author

ozmodeuz commented Oct 3, 2024

Hi, thanks for the reply, no worries about the delay :)

Here's the output for Q1:

$ ble/widget/display-shell-version
GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu) [Arch Linux]
ble.sh, version 0.4.0-devel4+670c7ea (noarch) [git 2.46.1, GNU Make 4.4.1, GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.2.1, GNU MP 6.2.1)]
locale: LANG=en_GB.UTF-8
terminal: TERM=xterm-kitty wcwidth=15.0-west/15.1-2+ri, kitty:0 (1;4000;36)
options: +inherit_errexit
$ declare -p BASH_COMPLETION_COMPAT_DIR
bash: declare: BASH_COMPLETION_COMPAT_DIR: not found
[ble: exit 1]

Q2: Yeah seems to go away with autocomplete disabled via bleopt complete_auto_complete=

Q3: entering kitty kitten followed by tab gives one error, then shows me the one kitty kitten command I've run this way, followed by the menu of folders in the working directory. Subsequent tabs tab through the menu of options as you'd expect.

$ kitty kitten bash: _command_offset: command not found
        kitten themes
.bash_history    .bash_logout    .bash_profile    .bashrc  ...

@akinomyoga
Copy link
Owner

Thank you for the results.

The problem seems to be that bash-completion is not loaded in your session. As explained in my previous reply, kitty's shell integration calls _command_offset, which is a shell function provided by the bash-completion framework. This means kitty's shell integration actually depends on bash-completion. However, as far as I search kitty's codebase, I don't find any code that tries to ensure the existence of bash-completion. It even doesn't mention bash-completion at all. I think this should be fixed at kitty's side by turning off the attempt of calling _command_offset when _command_offset is not found. I'll later submit a PR.

For your case, you can install bash-completion by pacman -S bash-completion.

@ozmodeuz
Copy link
Author

ozmodeuz commented Oct 4, 2024

That did the trick, thanks for your help! If you drop a link to the kitty PR i'll go and give it a bump.

@akinomyoga
Copy link
Owner

I submitted a PR to kitty today (kovidgoyal/kitty#7973), and it was soon merged.

@akinomyoga akinomyoga added the External Problem/Bug Problems/Bugs of other projects label Oct 19, 2024
@akinomyoga akinomyoga changed the title Suggestions for 'kitty kitten' result in 'bash: _command_offset: command not found' [kitty] Suggestions for 'kitty kitten' result in 'bash: _command_offset: command not found' Oct 19, 2024
@akinomyoga akinomyoga changed the title [kitty] Suggestions for 'kitty kitten' result in 'bash: _command_offset: command not found' [kitty <= 0.36.4] Suggestions for 'kitty kitten' result in 'bash: _command_offset: command not found' Oct 19, 2024
@akinomyoga
Copy link
Owner

The fix in kitty seemed to have been released in kitty v0.37.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Problem/Bug Problems/Bugs of other projects
Projects
None yet
Development

No branches or pull requests

2 participants