Skip to content

Instantly share code, notes, and snippets.

@BuriedStPatrick
Last active March 3, 2023 14:08
Show Gist options
  • Save BuriedStPatrick/ca3d99729ecf6e5a2d64d9188bfd8de8 to your computer and use it in GitHub Desktop.
Save BuriedStPatrick/ca3d99729ecf6e5a2d64d9188bfd8de8 to your computer and use it in GitHub Desktop.
Forwarding CLI commands to APX run tools

Forwarding CLI commands to APX run tools

VanillaOS's APX tool is quite neat since you can export desktop-entries with apx export <program>. However, if you like to run CLI tools on your host system without apx enter it's a bit trickier. Here's a little guide on how you can get around this using she-bang scripts.

Steps

  1. Create a folder somewhere in your home-directory structure that you'd like to contain shebang scripts. I'm just going to use ~/scripts as a starting point.

  2. Add the folder to your shell's PATH environment variable:

export PATH=$HOME/scripts:$PATH
  1. Install some CLI tool with APX. I'm going to use kubelogin as it's what I needed at the time of writing this. I'm installing it in an Arch container so I can get the latest and greatest community packaged binary.
apx install --aur kubelogin
  1. Create a she-bang script for it inside your scripts-directory that we added in step 1 and make it executable.
touch $HOME/scripts/kubelogin
chmod +x $HOME/scripts/kubelogin
  1. Now we need to modify the script to execute the underlying binary if we're running in the container, and if we're running from our host system we need to pass it down to the container. Like so:
#!/bin/bash
if [ -f "/usr/sbin/kubelogin" ]; then
    /usr/sbin/kubelogin $@
else
    apx run --aur "/usr/sbin/kubelogin $@"
fi

I got the full path to kubelogin using apx run --aur whereis kubelogin. Additionally, if your container isn't Arch based, obviously you want to replace --aur with the distro you're using for the container instead. The $@ is needed to pass any arguments down the chain. For example, if I want to check the version like: kubelogin --version.

Conclusion

This should enable you to run basically any commandline utility from your host shell without needing to apx enter all the time. It would be nice with built-in functionality so we didn't need to do this, but for now this does the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment