Skip to content

Instantly share code, notes, and snippets.

@ddennedy
Last active September 6, 2025 00:05
Show Gist options
  • Save ddennedy/9903297060fb8ddbb42cba3823d97dea to your computer and use it in GitHub Desktop.
Save ddennedy/9903297060fb8ddbb42cba3823d97dea to your computer and use it in GitHub Desktop.
Create a wrapper script in ~/.local/bin for each installed Flatpak
#!/bin/sh
# This script generates executable wrapper scripts for all installed Flatpak applications.
# The wrappers allow you to run Flatpak apps from the command line without using 'flatpak run'.
# The directory where the wrapper scripts will be placed.
BIN_DIR="$HOME/.local/bin"
# Create the bin directory if it doesn't exist.
mkdir -p "${BIN_DIR}"
echo "Wrapper scripts will be created in: ${BIN_DIR}"
echo "Make sure this directory is in your PATH."
# List all installed Flatpak applications and iterate through them.
# 'flatpak list --app' provides a clean list of app IDs.
# 'tail -n +2' is used to skip the header line.
flatpak list --app --columns=application,branch| tail -n +1 | while read -r flatpak_id branch; do
# Extract a user-friendly name from the Flatpak ID.
# This takes the last part of the ID, e.g., 'Chromium' from 'org.chromium.Chromium'.
WRAPPER_NAME=$(echo "${flatpak_id}" | cut -d. -f3)
# If branch is not "stable", append branch to wrapper name.
if [ "$branch" != "stable" ]; then
WRAPPER_NAME="${WRAPPER_NAME}-${branch}"
fi
# Define the full path for the new wrapper script.
WRAPPER_PATH="${BIN_DIR}/${WRAPPER_NAME}"
echo "Processing ${flatpak_id}..."
# Use a here-document to write the wrapper script content.
# The > redirects the output to create a new file, overwriting if it exists.
cat <<EOF > "${WRAPPER_PATH}"
#!/bin/sh
exec /usr/bin/flatpak run --branch=${branch} --arch=x86_64 ${flatpak_id} "\$@"
EOF
# Make the newly created script executable.
chmod +x "${WRAPPER_PATH}"
echo "Successfully created and made executable: ${WRAPPER_PATH}"
done
echo "All Flatpak wrappers have been generated."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment