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

appimage.sh: detect vim/gvim self name #68

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

mralusw
Copy link
Contributor

@mralusw mralusw commented Mar 28, 2024

  • appimages pass $ARGV0 to AppRun: use it to detect vim/gvim

  • extracting Vim.appimage to an AppDir, symlinking AppRun to vim works

  • currently impossible to extract GVim.appimage and symlink AppRun b/c:

    • GVim.appimage uses linuxdeploy-plugin-gtk, which renames AppRun to *.wrapped and generates its own AppRun
    • this plugin-generated AppRun, if symlinked, tries to source hooks from the wrong dir (dirname / readlink order)
    • OTOH calling AppDir/**/AppRun.wrapped directly / via symlink bypasses those hooks and thus fails to set GTK vars
    • proposed: add an AppDirRun script for users who extract; document it
    • or: patch/replace AppRun after plugin-gtk generates it but before the appimage is packaged.
  • notes:

    • renamed $HERE to $this_dir, which linuxdeploy-plugin-gtk already clobbers (not explicitly exported, but might be in user's env)
    • resolving $0 in AppRun[.wrapped] is pointless when run from appimage ($0 is /tmp/.mount*/AppRun[.wrapped]).
    • both "our" AppRun and linuxdeploy-lugin-gtk's call utilities without a -- guard before args, thus AppDirs can't be named -...

- appimages pass `$ARGV0` to AppRun: use it to detect vim/gvim
- extracting Vim.appimage to an AppDir, symlinking AppRun to vim works

- currently impossible to extract GVim.appimage and symlink AppRun b/c:
  - GVim.appimage uses linuxdeploy-plugin-gtk, which renames AppRun to
    *.wrapped and generates its own AppRun
  - this plugin-generated AppRun, if symlinked, tries to source hooks
    from the wrong dir (`dirname` / `readlink` order)
  - OTOH calling `AppDir/**/AppRun.wrapped` directly / via symlink
    bypasses those hooks and thus fails to set GTK vars
  - proposed: add an AppDirRun script for users who extract; document it
  - or: patch/replace AppRun *after* plugin-gtk generates it but
    *before* the appimage is packaged.

- notes:
  - renamed `$HERE` to `$this_dir`, which linuxdeploy-plugin-gtk already
    clobbers (not explicitly exported, but might be in user's env)
  - resolving `$0` in `AppRun[.wrapped]` is pointless when run from
    appimage (`$0` is `/tmp/.mount*/AppRun[.wrapped]`).
  - both "our" AppRun and linuxdeploy-lugin-gtk's call utilities without
    a `--` guard before args, thus AppDirs can't be named `-...`
@mralusw
Copy link
Contributor Author

mralusw commented Mar 28, 2024

Fixes #67 (partially)

@chrisbra
Copy link
Member

Thanks. Regarding:

currently impossible to extract GVim.appimage and symlink AppRun

Why would one need that? Isn't the whole point of the appimage to have it readily available and running without having to extract it manually?

@mralusw
Copy link
Contributor Author

mralusw commented Mar 28, 2024

Why would one need that? Isn't the whole point of the appimage to have it readily available and running without having to extract it manually?

Yes and no. Every appimage has a hidden --appimage-extract flag. And if you look into apprun-hooks/linuxdeploy-plugin-gtk.sh, it tries to take this scenario into account (but ultimately fails):

export APPDIR="${APPDIR:-"$(dirname "$(realpath "$0")")"}" # Workaround to run extracted AppImage

Some users extract the appimage to some folder ("AppDir") in the filesystem, then symlink from AppRun to /usr/local/bin/real-app-name. It's a good way to get a clean build of an app without incurring the

  • memory overhead of mounting an appimage (squashfs) every time the app runs (possibly multiple times concurrently!) and the
  • CPU overhead of the appimage "shell" code. I personally use it to get a fresh [g]vim from vim-appimage while still keeping vim near-instantaneous (for example as a $GIT_EDITOR / $EDITOR).

The problem is that for GVim.appimage (but not Vim.appimage), linuxdeploy creates a "broken" AppRun that can't be symlinked to and renames "our" AppRun to *.wrapped.

Now, if you never even considered extracted appimages, I wonder why the code didn't just use $APPDIR (provided by the appimage infra) to begin with, instead of trying to compute $HERE by itself. Taking all this into account, I would

  • simplify "our" AppRun (which gets renamed to AppRun.wrapped in GVim.appimage) to be an appimage-only script (i.e. it could rely on $ARGV0 and $APPDIR being set)
  • possibly add a separate AppDirRun in the appimage for users who extract. Or AppDirRun can be documented / uploaded elsewhere in this repository (technically, it's already quoted in an issue, but it's a bit annoying to copy/pasta every time one extracts a new appimage)

@chrisbra
Copy link
Member

okay thanks. Let me merge your changes for now. If you think it is beneficial, to further improve the AppRun script generated, I welcome you to make those change and create a new PR. I am not planning to work further on this, since I am too busy with Vim maintenance.

@chrisbra chrisbra merged commit cf936b4 into vim:master Mar 28, 2024
@mralusw mralusw deleted the feat-detect-vim-gvim branch March 30, 2024 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants