MLFlexer / resurrect.wezterm

A plugin to restore windows, tabs and panes for Wezterm inspired by tmux-resurrect
MIT License
74 stars 2 forks source link

Unable to require plugin ("could not find repository at" error) #19

Closed joncrangle closed 3 months ago

joncrangle commented 3 months ago

I've been unable to add this plugin on both Mac and Windows.

On both OS, I get an error about httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm not being found or not existing.

I'm using wezterm-nightly and requiring with:

local resurrect = wezterm.plugin.require 'https://github.com/MLFlexer/resurrect.wezterm'
resurrect.init_directories() -- you can delete this line once the directories have been created
resurrect.periodic_save()

I import other plugins in my config (smart-splits and your wonderful smart_workspace_switcher.wezterm) with no issues.

MLFlexer commented 3 months ago

Can you open the debug overlay, default keybindings are Ctrl + Shift + L and paste the output here? That might give me a better indication of where the error occurs

Also can you paste the output of ls $HOME/.local/share/wezterm/plugins that should output the directory names if the plugins you have installed, and I would expect httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm to be one of them

joncrangle commented 3 months ago

Thanks for your help.

Can you open the debug overlay, default keybindings are Ctrl + Shift + L and paste the output here? That might give me a better indication of where the error occurs

On Mac:

ERROR plugin > Failed to require httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm which is stored in "/Users/jon/Library/Application Support/wezterm/plugins/httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm": could not find repository at '/Users/jon/Library/Application Support/wezterm/plugins/httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs'; class=Repository (6); code=NotFound (-3)
stack traceback:
        [C]: in field 'list'
        ...bsDscomsZsMLFlexersZsresurrectsDswezterm/plugin/init.lua:6: in local 'enable_sub_modules'
        ...bsDscomsZsMLFlexersZsresurrectsDswezterm/plugin/init.lua:10: in main chunk
        [C]: in function 'require'
        [C]: in field 'require'
        [string "/Users/jon/.config/wezterm/wezter..."]:107: in main chunk

On Windows:

ERROR wezterm_gui::termwindow > Failed to apply config overrides to window: program not found
stack traceback:
        [C]: in local 'poll'
        [string "?"]:4: in function 'wezterm.background_child_process'
        ...bsDscomsZsMLFlexersZsresurrectsDswezterm/plugin/init.lua:91: in function 'httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm.init_directories'
        [string "C:\Users\jon\AppData\Local\wezterm\wez..."]:115: in main chunk
: nil

Also can you paste the output of ls $HOME/.local/share/wezterm/plugins that should output the directory names if the plugins you have installed, and I would expect httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm to be one of them

No such file or directory (os error 2)

MLFlexer commented 3 months ago

Thanks, I can see that some of my assumptions of how the directories are created on non-linux systems are wrong. I have an idea of how to fix this issue, but I do not have access to a Mac, so if you can help me test it, then it would be greatly appreciated! I will try and fix the issue ASAP :smile:

joncrangle commented 3 months ago

Thanks, I can see that some of my assumptions of how the directories are created on non-linux systems are wrong. I have an idea of how to fix this issue, but I do not have access to a Mac, so if you can help me test it, then it would be greatly appreciated! I will try and fix the issue ASAP 😄

I'm happy to help with testing on Mac and Windows.

joncrangle commented 3 months ago

I just tried on my Arch laptop and have a similar error:

could not find repository at '/home/jon/.config/.local/share/wezterm/
plugins/httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs';
class=Repository (6); code=NotFound (-3)
stack traceback:
        [C]: in field 'list'
        ...bsDscomsZsMLFlexersZsresurrectsDswezterm/plugin/init.lua:6: in local
'enable_sub_modules'
        ...bsDscomsZsMLFlexersZsresurrectsDswezterm/plugin/init.lua:10: in main chunk
        [C]: in function 'require'
        [C]: in field 'require'
        /home/jon/.config/wezterm/keys.lua:4: in main chunk
        [C]: in function 'require'
        /home/jon/.config/wezterm/mouse.lua:2: in main chunk
        [C]: in function 'require'
        [string "/home/jon/.config/wezterm/wezterm.lua"]:18: in main chunk
MLFlexer commented 3 months ago

Very strange, I would expect it to work fine on Arch, as I have tested it on NixOS...

What version of wezterm are you using? wezterm --verision

Can you try to write the following in the debug overlay: wezterm.plugin.list() and paste the output? It seems to be a problem with that

joncrangle commented 3 months ago

Very strange, I would expect it to work fine on Arch, as I have tested it on NixOS...

What version of wezterm are you using? wezterm --verision

Can you try to write the following in the debug overlay: wezterm.plugin.list() and paste the output? It seems to be a problem with that

On Arch: wezterm 20240624-065522-552bb1d6 wezterm.plugin.list()

could not find repository at '/home/jon/.config/.local/share/wezterm/
plugins/httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs';
class=Repository (6); code=NotFound (-3)
stack traceback:
        [C]: in field 'list'
        [string: "repl"]: in main chunk

On Windows: wezterm 20240316-074238-889f8a9c wezterm.plugin.list()

[
    {
        "component": "httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm",
        "plugin_dir": "C:\\Users\\jon\\AppData\\Roaming\\wezterm\\plugins\\httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm",
        "url": "https://github.com/MLFlexer/resurrect.wezterm",
    },
    {
        "component": "httpssCssZssZsgithubsDscomsZsMLFlexersZssmart_workspace_switchersDswezterm",
        "plugin_dir": "C:\\Users\\jon\\AppData\\Roaming\\wezterm\\plugins\\httpssCssZssZsgithubsDscomsZsMLFlexersZssmart_workspace_switchersDswezterm",
        "url": "https://github.com/MLFlexer/smart_workspace_switcher.wezterm",
    },
    {
        "component": "httpssCssZssZsgithubsDscomsZsmrjones2014sZssmart-splitssDsnvim",
        "plugin_dir": "C:\\Users\\jon\\AppData\\Roaming\\wezterm\\plugins\\httpssCssZssZsgithubsDscomsZsmrjones2014sZssmart-splitssDsnvim",
        "url": "https://github.com/mrjones2014/smart-splits.nvim",
    },
]

On Mac: wezterm 20240722-080956-7e8fdc11 wezterm.plugin.list()

could not find repository at '/Users/jon/Library/Application Support/wezterm/plugins/httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs'; class=Repository (6); code=NotFound (-3)
stack traceback:
        [C]: in field 'list'
        [string "repl"]:1: in main chunk
MLFlexer commented 3 months ago

I just tried wezterm.plugin.list() on NixOS version 20240723-151548-8f84d7ee and it worked as expected, just like on the windows output. I think #18 can resolve the issue on windows. If you can cd into the plugin directory on your windows machine and git checkout the branch 19-unable-to-require-plugin. Then delete the

resurrect.init_directories() -- you can delete this line once the directories have been created

line from your config and check if it works?

For Mac and Arch: Can you try and delete the repository and reload your config by restarting your wezterm or something similar? I would think you would need to run rm -rdf /Users/jon/Library/Application Support/wezterm/plugins/httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs on Mac and rm -rdf /home/jon/.config/.local/share/wezterm/plugins/httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs on Arch

Then checking the output of wezterm.plugin.list()?

joncrangle commented 3 months ago

Ok - I've managed to get it working on Windows in a bit of a convoluted way with branch 19-unable-to-require-plugin. I'll try on Mac and Arch later when I have some more time.

I had resurrect.init_directories() commented out throughout the process.

1) git clone https://github.com/MLFlexer/resurrect.wezterm.git within C:\Users\{USERNAME}\AppData\Roaming\wezterm\plugins\ 2) Checkout branch 19-unable-to-require-plugin 3) I removed the "sZs" from the end of each entry in init.lua 4) Restarted wezterm. This resulted in a second resurrect directory being created in the plugin folder, so the directory contained httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs/ and httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm. I made sure both resurrect plugin folders were on branch 19-unable-to-require-plugin and restarted wezterm again.

If I remove either of these resurrect folders, the wezterm config crashes. But the plugin loads and works. I can save sessions.

A bug I've found with windows is that it will not "resurrect" properly because path elements with spaces need to be wrapped in quotes.

C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.4.0_x64__8wekyb3d8bbwe\pwsh.exe
C:\Program: The term 'C:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
MLFlexer commented 3 months ago

Ok - I've managed to get it working on Windows in a bit of a convoluted way with branch 19-unable-to-require-plugin. I'll try on Mac and Arch later when I have some more time.

I had resurrect.init_directories() commented out throughout the process.

1. `git clone https://github.com/MLFlexer/resurrect.wezterm.git` within `C:\Users\{USERNAME}\AppData\Roaming\wezterm\plugins\`

2. Checkout branch `19-unable-to-require-plugin`

3. I removed the "sZs" from the end of each entry in `init.lua`

4. Restarted wezterm. This resulted in a second resurrect directory being created in the plugin folder, so the directory contained  `httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs/` and `httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm`. I made sure both resurrect plugin folders were on branch `19-unable-to-require-plugin` and restarted wezterm again.

If I remove either of these resurrect folders, the wezterm config crashes. But the plugin loads and works. I can save sessions.

This is because the way Wezterm requires the plugins is by creating a directory where each / is replaced with sZs. In the readme i wrote: wezterm.plugin.require 'https://github.com/MLFlexer/resurrect.wezterm i.e. without the / but in the code i wrote wezterm.plugin.require 'https://github.com/MLFlexer/resurrect.wezterm/ i.e. with the / at the end. I hope that mistakes like this can be fixed by 5820. For now I have ensured that all requires are without the /.

A bug I've found with windows is that it will not "resurrect" properly because path elements with spaces need to be wrapped in quotes.

C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.4.0_x64__8wekyb3d8bbwe\pwsh.exe
C:\Program: The term 'C:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Would you expect it to be C:\'Program Files'\WindowsApps\Microsoft.PowerShell_7.4.4.0_x64__8wekyb3d8bbwe\pwsh.exe?

joncrangle commented 3 months ago

Ok - I've managed to get it working on Windows in a bit of a convoluted way with branch 19-unable-to-require-plugin. I'll try on Mac and Arch later when I have some more time. I had resurrect.init_directories() commented out throughout the process.

1. `git clone https://github.com/MLFlexer/resurrect.wezterm.git` within `C:\Users\{USERNAME}\AppData\Roaming\wezterm\plugins\`

2. Checkout branch `19-unable-to-require-plugin`

3. I removed the "sZs" from the end of each entry in `init.lua`

4. Restarted wezterm. This resulted in a second resurrect directory being created in the plugin folder, so the directory contained  `httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs/` and `httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm`. I made sure both resurrect plugin folders were on branch `19-unable-to-require-plugin` and restarted wezterm again.

If I remove either of these resurrect folders, the wezterm config crashes. But the plugin loads and works. I can save sessions.

This is because the way Wezterm requires the plugins is by creating a directory where each / is replaced with sZs. In the readme i wrote: wezterm.plugin.require 'https://github.com/MLFlexer/resurrect.wezterm i.e. without the / but in the code i wrote wezterm.plugin.require 'https://github.com/MLFlexer/resurrect.wezterm/ i.e. with the / at the end. I hope that mistakes like this can be fixed by 5820. For now I have ensured that all requires are without the /.

A bug I've found with windows is that it will not "resurrect" properly because path elements with spaces need to be wrapped in quotes.

C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.4.0_x64__8wekyb3d8bbwe\pwsh.exe
C:\Program: The term 'C:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Would you expect it to be C:\'Program Files'\WindowsApps\Microsoft.PowerShell_7.4.4.0_x64__8wekyb3d8bbwe\pwsh.exe?

Yes - I think if 'Program Files' is wrapped in quotes it should work.

I've got the plugin working on Arch and Mac now. I went into the plugin directory and noticed the folder wasn't initialized as a git directory. I initialized it and added https://github.com/MLFlexer/resurrect.wezterm.git as a remote origin in the directory, and pulled the latest commits.

MLFlexer commented 3 months ago

Opened a new issue on the windows paths and closing this as it seems to be solved.

Thank you @joncrangle very much for helping test it on different platforms!

joncrangle commented 3 months ago

Thanks @MLFlexer I think I may have tracked down the weird issue that was going on.

If you require the plugin with: local resurrect = wezterm.plugin.require 'https://github.com/MLFlexer/resurrect.wezterm', a folder gets created in the wezterm plugin directory with the name: httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm.

However, if you require the plugin with: local resurrect = wezterm.plugin.require 'https://github.com/MLFlexer/resurrect.wezterm/' (Note: the forward slash at the end), a folder gets created in the wezterm plugin directory with the name: httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDsweztermsZs.

I think that part of the reason I am ending up with two folders in the plugin directory is because at various points, the path construction has or doesn't have the forward slash at the end. In my config, I've noticed that state files are stored in the folder without the sZs. I can prevent an additional folder being created by adding the following to the plugin's init.lua:

local plugin_name = pub.get_require_path()
assert(
    plugin_name == "httpssCssZssZsgithubsDscomsZsMLFlexersZsresurrectsDswezterm",
    "Inconsistent plugin name detected"
)

But I think a better approach would be to handle both scenarios depending on how the user required the plugin (with or without the forward slash).