kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.86k stars 997 forks source link

can't launch kitty with --single-instance in macos-launch-services-cmdline #7846

Closed ahmedelgabri closed 2 months ago

ahmedelgabri commented 2 months ago

Describe the bug I can't launch kitty with --single-instance in macos-launch-services-cmdline I know this was supposed to be fixed in 0.36.1 but I'm on 0.36.2 and it doesn't work still.

To Reproduce Steps to reproduce the behavior:

  1. mkdir ~/.config/kitty
  2. echo "--single-instance" > ~/.config/kitty/macos-launch-services-cmdline
  3. Try to launch kitty from GUI using spotlight, alfred, raycast or finder
  4. Nothing happens.

Alternative step:

Run the following from the terminal

open -a kitty.app --args --single-instance

Environment details

kitty 0.36.2 (15ac33a058) created by Kovid Goyal
Darwin pandoras-box 21.6.0 Darwin Kernel Version 21.6.0: Mon Jun 24 00:56:10 PDT 2024; root:xnu-8020.240.18.709.2~1/RELEASE_X86_64 x86_64
ProductName:    macOS ProductVersion:   12.7.6 BuildVersion:    21H1320
OpenGL: '4.1 INTEL-18.8.16' Detected version: 4.1
Frozen: True
Fonts:
  medium: PragmataProMonoLiga-Regular: /Library/Fonts/Nix Fonts/iigip63mgd66fy7y6w46pld2c1g8iywl-PragmataPro0.830/share/fonts/opentype/PragmataPro_Mono_R_liga_0830.otf
          Features: ()
    bold: PragmataProMonoLiga-Bold: /Library/Fonts/Nix Fonts/iigip63mgd66fy7y6w46pld2c1g8iywl-PragmataPro0.830/share/fonts/opentype/PragmataPro_Mono_B_liga_0830.otf
          Features: ()
  italic: PragmataProMonoLiga-Italic: /Library/Fonts/Nix Fonts/iigip63mgd66fy7y6w46pld2c1g8iywl-PragmataPro0.830/share/fonts/opentype/PragmataPro_Mono_I_liga_0830.otf
          Features: ()
      bi: PragmataProMonoLiga-BoldItalic: /Library/Fonts/Nix Fonts/iigip63mgd66fy7y6w46pld2c1g8iywl-PragmataPro0.830/share/fonts/opentype/PragmataPro_Mono_Z_liga_0830.otf
          Features: ()
Paths:
  kitty: /Applications/kitty.app/Contents/MacOS/kitty
  base dir: /Applications/kitty.app/Contents/Resources/kitty
  extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions
  system shell: /run/current-system/sw/bin/zsh
Loaded config files:
  /Users/ahmed/.config/kitty/kitty.conf

Config options different from defaults:
active_border_color             None
allow_remote_control            yes
confirm_os_window_close         0
cursor_stop_blinking_after      0
disable_ligatures               1
enable_audio_bell               False
font_family                     family="PragmataPro Mono Liga"
font_size                       12.0
hide_window_decorations         1
inactive_text_alpha             0.6
kitty_mod                       cmd
macos_custom_beam_cursor        True
macos_option_as_alt             3
macos_traditional_fullscreen    True
scrollback_fill_enlarged_window True
scrollback_lines                20000
scrollback_pager                ['nvim', '-c', 'set nonumber nolist showtabline=0 foldcolumn=0', '-c', 'autocmd VimEnter * cnoremap q q!|nnoremap q :q!<CR>|normal G', '-c', 'silent write /tmp/kitty_scrollback_buffer | te cat /tmp/kitty_scrollback_buffer - ']
select_by_word_characters       :@-./_~?&=%+#
strip_trailing_spaces           smart
symbol_map:
    U+e000 - U+e00a → Symbols Nerd Font Mono
    U+e0a0 - U+e0c8 → Symbols Nerd Font Mono
    U+e0ca - U+e0ca → Symbols Nerd Font Mono
    U+e0cc - U+e0d7 → Symbols Nerd Font Mono
    U+e200 - U+e2a9 → Symbols Nerd Font Mono
    U+e300 - U+e3e3 → Symbols Nerd Font Mono
    U+e5fa - U+e6b1 → Symbols Nerd Font Mono
    U+e700 - U+e7c5 → Symbols Nerd Font Mono
    U+ea60 - U+ebeb → Symbols Nerd Font Mono
    U+ed00 - U+efc1 → Symbols Nerd Font Mono
    U+f000 - U+f2e0 → Symbols Nerd Font Mono
    U+f000 - U+f2ff → Symbols Nerd Font Mono
    U+f300 - U+f372 → Symbols Nerd Font Mono
    U+f400 - U+f533 → Symbols Nerd Font Mono
    U+f0001 - U+f1af0 → Symbols Nerd Font Mono
tab_activity_symbol             ▲
tab_bar_edge                    1
update_check_interval           0.0
window_alert_on_bell            False
window_padding_width            FloatEdges(left=10.0, top=10.0, right=10.0, bottom=10.0)
Added mouse actions:
    cmd+left press grabbed →  mouse_discard_event
    cmd+left release grabbed →  mouse_click_url
    cmd+left release ungrabbed →  mouse_click_url
    opt+cmd+left press ungrabbed →  mouse_selection rectangle
Added shortcuts:
    ctrl+i →  send_text application \x48
    kitty_mod+shift+h →  show_scrollback
Removed shortcuts:
    cmd++ →  change_font_size all +2.0
    cmd+, →  edit_config_file
    cmd+- →  change_font_size all -2.0
    cmd+0 →  change_font_size all 0
    cmd+1 →  first_window
    cmd+2 →  second_window
    cmd+3 →  third_window
    cmd+4 →  fourth_window
    cmd+5 →  fifth_window
    cmd+6 →  sixth_window
    cmd+7 →  seventh_window
    cmd+8 →  eighth_window
    cmd+9 →  ninth_window
    cmd+= →  change_font_size all +2.0
    cmd+c →  copy_to_clipboard
    cmd+down →  scroll_line_down
    cmd+end →  scroll_end
    cmd+enter →  new_window
    cmd+h →  hide_macos_app
    cmd+home →  scroll_home
    cmd+k →  clear_terminal to_cursor active
    cmd+m →  minimize_macos_window
    cmd+n →  new_os_window
    cmd+page_down →  scroll_page_down
    cmd+page_up →  scroll_page_up
    cmd+q →  quit
    cmd+r →  start_resizing_window
    cmd+t →  new_tab
    cmd+up →  scroll_line_up
    cmd+v →  paste_from_clipboard
    cmd+w →  close_tab
    ctrl+cmd+, →  load_config_file
    ctrl+cmd+f →  toggle_fullscreen
    kitty_mod+enter →  new_window
    kitty_mod+f2 →  edit_config_file
    kitty_mod+h →  show_scrollback
    kitty_mod+k →  scroll_line_up
    kitty_mod+n →  new_os_window
    kitty_mod+q →  close_tab
    kitty_mod+t →  new_tab
    kitty_mod+w →  close_window
    opt+cmd+h →  hide_macos_other_apps
    opt+cmd+r →  clear_terminal reset active
    opt+cmd+s →  toggle_macos_secure_keyboard_entry
    shift+cmd+/ →  open_url https://sw.kovidgoyal.net/kitty/
    shift+cmd+[ →  previous_tab
    shift+cmd+] →  next_tab
    shift+cmd+d →  close_window
    shift+cmd+w →  close_os_window
Changed shortcuts:
    kitty_mod+, →  edit_config_file
    kitty_mod+0 →  change_font_size all 0
Colors:
    background                      #111111   
    color0                          #1d1f21   
    color1                          #cc6666   
    color10                         #99cc99   
    color11                         #ffcc66   
    color12                         #6699cc   
    color13                         #cc99cc   
    color14                         #66cccc   
    color15                         #dddddd   
    color2                          #b5bd68   
    color3                          #f0c674   
    color4                          #81a2be   
    color5                          #b294bb   
    color6                          #8abeb7   
    color7                          #c5c8c6   
    color8                          #333333   
    color9                          #f2777a   
    cursor                          #20bbfc   
    foreground                      #c5c8c6   
    inactive_tab_background         #1d1f21   

Important environment variables seen by the kitty process:
    PATH                                /Applications/kitty.app/Contents/MacOS:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
    LANG                                en_US.UTF-8
    SHELL                               /run/current-system/sw/bin/zsh
    USER                                ahmed
kovidgoyal commented 2 months ago

Does not reproduce for me steps I tried

1) echo "--single-instance" > ~/.config/kitty/macos-launch-services-cmdline 2) Run

open -a kitty.app

3) kitty opens as expected 4) Quit kitty 5) click kitty dock icon 6) kitty opens as expected 7) In another terminal run

kitty --single-instance

8) A new window in the kitty instance from 6 opens, as expected.

Make sure you have actually quit kitty before editing macos-launch-services-cmdline, maybe try rebooting your machine. And if it doesnt start look in console.app for logs.

ahmedelgabri commented 2 months ago

I did reboot multiple times, I will have a look at the logs from console.app

igorepst commented 2 months ago

@kovidgoyal Hi. I can confirm the bug report. I am on 0.36.2, installed via Homebrew, on Sonoma 14.6.1. As I update regularly, I am sure it worked in previous versions. open -a kitty.app doesn't show Kitty's window.

cat ~/.config/kitty/macos-launch-services-cmdline
--single-instance
--listen-on unix:/tmp/kitty-main

I almost never open Kitty from dock actually, so let me share the results running from Terminal.app:

 /opt/homebrew/bin/kitty --single-instance --listen-on unix:/tmp/kitty-main
 Failed to connect to single instance socket: Connection refused

ls -al /tmp/ | grep kitty returns no results as well. However, /opt/homebrew/bin/kitty & works, and then, as I have listen_on unix:/tmp/kitty-main in kitty.conf

ls -al /tmp/ | grep kitty
srwxr-xr-x  1 igor.epstein wheel   0 12-09-2024 11:54 kitty-main-3203

Console.app doesn't show anything that is related to Kitty, as far as I can tell. How can I help to debug this? Thank you

kovidgoyal commented 2 months ago

All options in macos-launch-services-cmdline need to be on a single line.

igorepst commented 2 months ago

I fixed macos-launch-services-cmdline, however it changed nothing. Removing single-instance from there enables Kitty to be opened. Single instance doesn't work from command line as well, as I wrote above

kovidgoyal commented 2 months ago

Dont put listen_on in both kitty.conf and the CLI. Pick one.

igorepst commented 2 months ago

Moved all the config to "bak", open -a kitty.app works, single instance with or without listen-on does not - I tried from command line. I will check on Linux and will try to build Kitty on Mac later today

igorepst commented 2 months ago

Just found your answer, @kovidgoyal, here. That exactly what happened to me, and probably to @ahmedelgabri

find /private -name 'kitty-ipc*' 2>/dev/null
/private/var/folders/45/v2yv8_9n6hxdrw8kyblfhy100000gn/C/kitty-ipc-501
/private/var/folders/45/v2yv8_9n6hxdrw8kyblfhy100000gn/C/kitty-ipc-501.lock

ll /private/var/folders/45/v2yv8_9n6hxdrw8kyblfhy100000gn/C/kitty-ipc-501
srwxr-xr-x 1 igor.epstein staff 0 12-09-2024 10:47 /private/var/folders/45/v2yv8_9n6hxdrw8kyblfhy100000gn/C/kitty-ipc-501=

And system.log in Console.app has the following, which I understand as time of reboot: Sep 12 10:48:45 XXX reboot[34432]: SHUTDOWN_TIME: 1726127325 642601 So, probably, stale lock files were left for some reason, that survived reboot. And the reason of reboot was misbehavior of Mac, so maybe it crashed Kitty, preventing lock deletion

kovidgoyal commented 2 months ago

Lock files are auto cleaned on reboot, they are in /tmp so it cant be that unless for some reason your mac is not cleaning /tmp and friends on reboot.

igorepst commented 2 months ago

As far as I understood from googling, they are not in /tmp https://superuser.com/questions/892647/it-is-safe-delete-osxs-private-var-folders-at-reboot and https://www.swiftforensics.com/2017/04/the-mystery-of-varfolders-on-osx.html

ll /tmp
lrwxr-xr-x 1 root wheel 11 04-08-2024 13:31 /tmp -> private/tmp/
find /private -name 'kitty-ipc*' 2>/dev/null
/private/var/folders/45/v2yv8_9n6hxdrw8kyblfhy100000gn/C/kitty-ipc-501

And this folder with lock files has a lot of things from two month ago, even this

ll /private/var/folders/45/v2yv8_9n6hxdrw8kyblfhy100000gn/C/net.kovidgoyal.kitty/
total 0
drwxr-xr-x 4 igor.epstein staff 128 24-07-2024 21:15 com.apple.metal/
drwxr-xr-x 2 igor.epstein staff  64 24-07-2024 19:55 com.apple.metalfe/
kovidgoyal commented 2 months ago

Regardless, locks are in kernel objects that dont survive reboots. Whether the file exists or not it wont be locked.

kovidgoyal commented 2 months ago

also IIRC those lock files arent created by up-to-date versions of kitty, only the socket files. So where are they coming from on your system?

kitty --single-instance
find /private -name '*kitty*'

output no .lock files for me

igorepst commented 2 months ago

Indeed, the lock files are not there now, only the socket. Were they created up to 0.36.1? Anyway, hopefully the issue of original poster will be resolved this way as well. Thank you for Kitty and for your time

ahmedelgabri commented 2 months ago

I don't have .lock files, I only have an kitty-ipc-501 file

$ find /private -name 'kitty-ipc*' 2>/dev/null

/private/var/folders/cm/kq8d76d97m99g0szm14rzstc0000gn/C/kitty-ipc-501

That being said my Mac actually misbehaved and I had to force shut it down, so maybe something here is true.

[…] And the reason of reboot was misbehavior of Mac, so maybe it crashed Kitty, preventing lock deletion

ldelossa commented 2 months ago

This is currently broken for me too.

If I run /opt/homebrew/bin/kitty --single-instance or open -n -a kitty.app --args --single-instance in my terminal no kitty window opens at all.

Once I remove this command, everything works.

MacOS: 14.6.1 Kitty: 14.6.1`

Edit:

I needed to remove some private files as well:

/private/var/folders/k5/16jgcrmj3g57dg8fzy48whzc0000gn/C/net.kovidgoyal.kitty
/private/var/folders/k5/16jgcrmj3g57dg8fzy48whzc0000gn/C/kitty-ipc-501

Now it works, no idea where those came from. I've never ran kitty with an IPC.

ahmedelgabri commented 2 months ago

I can confirm that deleting the kitty-ipc-501 file fixed my issue too. I didn't have a net.kovidgoyal.kitty

ldelossa commented 2 months ago

Any one know why this file gets there? I'm assuming kitty crashes and nothing cleans this up?

jiz4oh commented 2 months ago

rm kitty-ipc-501 file and net.kovidgoyal.kitty dir works for me

jiz4oh commented 2 months ago

also occurred the same issue after upgrade to 0.36.2