git-dev.nvim icon indicating copy to clipboard operation
git-dev.nvim copied to clipboard

[Feature Request] Gitea Open with IDE support

Open snoweuph opened this issue 1 year ago • 3 comments

I would love to see Gitea open with <IDE>: https://blog.gitea.com/release-of-1.22.0/#rocket-customizable-open-with-ide-menu-29320

Requirements

  • #16

snoweuph avatar Jun 01 '24 22:06 snoweuph

Cool!

I have yet to try this new Gitea feature, but I imagine something like this could work:

  • Create a small script (I created it in ~/.local/bin/git-dev for the sake of this example since it is already in my PATH).
#!/bin/bash

# Strip 'git-dev://open/?repo='
nvim -c "GitDevOpen ${1/git-dev:\/\/open\/?repo=/}"
  • Make it executable:
chmod +x ~/.local/bin/git-dev
  • Create ~/.local/share/applications/gitdev.desktop:
[Desktop Entry]
Name=GitDev
Comment=Opens a Git URI in Neovim.
Exec=git-dev %u
Terminal=true
Type=Application
MimeType=x-scheme-handler/git-dev
  • Register the new scheme:
xdg-mime default gitdev.desktop x-scheme-handler/git-dev
  • xdg-open now supports git-dev URI in this format: git-dev://open/?repo=<URL>. Example:
xdg-open git-dev://open/?repo=https://github.com/moyiz/git-dev.nvim
  • Add it to Gitea configuration:
Neovim = git-dev://open/?repo={url}

It should work assuming Gitea does no escape url.

I will think about generating such handler via plugin options.

Let me know how it goes :slightly_smiling_face:

moyiz avatar Jun 02 '24 08:06 moyiz

Summary

It works, when un-escaping the URL.

For my config, i changed it to nvim-gitdev for all files

Repository to try it out with: https://git.euph.dev/Snoweuph/Dotfiles image

Also, it doesn't work with git@ URLs: image

also for the script to work on my System (Kinoite), I had to wrap the nvim run with toolbx: nvim-gitdev.sh

#!/bin/bash
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
git_url=$(urldecode $1)
# Strip 'git-dev://open/?repo='
toolbox run -- nvim -c "GitDevOpen ${git_url/nvim-gitdev:\/\/open\/?repo=/}"

In the .desktop file, I had to use absolute an PATH, because it does not have access to my users $PATH nvim-gitdev.desktop

[Desktop Entry]
Name=Neovim GitDev Handler
Comment=Opens a Git URI in Neovim.
Exec=/home/snoweuph/.local/bin/nvim-gitdev.sh %u
Terminal=true
Type=Application
MimeType=x-scheme-handler/nvim-gitdev

I suggest an option like this:

opts = {
    xdg_handler = {
      wrapper = "toolbox run -- "
   }
}

xdg-handler should be nil by default, and this way, its easy to expand it with more options, if needed

snoweuph avatar Jun 03 '24 15:06 snoweuph

I just forked the project, and I gonna work on adding the needed code, to handle registering x-schemes

snoweuph avatar Jun 18 '24 14:06 snoweuph