Skip to content

A small program to assist in creating wrappers that always launch a program with additional arguments and/or environment variables.

License

Notifications You must be signed in to change notification settings

jonathanlmc/wrapperize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wrapperize

This is a small Linux utility program that creates wrappers for arbitrary executables to launch them with a predefined set of arguments and/or environment variables, without modifying the original executable.

This is primarily designed for Arch Linux. By default, the program will generate pacman hooks for the wrapped executable so that the wrapper is automatically recreated whenever the package associated with the wrapper is updated, reinstalled, or removed. This behavior can be disabled via a --nohooks flag so executables not managed by pacman (such as a script in /home) can be wrapped without requiring root.


  1. Prerequisites
  2. Installation
  3. Usage
  4. Examples
  5. How it works

Prerequisites

  • Rust 1.93 or later.

Installation

cargo install --path wrapperize

The binary will be installed to ~/.cargo/bin/wrapperize.
~/.cargo/bin must be added to your $PATH if it isn't already.

Usage

$ wrapperize --help
Wrap an executable to always execute with additional arguments or environment variables.

Usage: wrapperize <executable_path> [options]

Arguments:
  <executable_path>      Absolute path to the executable to wrap

Options:
  -a, --arg <ARG>    An additional argument to launch the executable with. Can be used multiple times.
  -e, --env <ENV>    An environment variable in the format of `ENV=value`. Can be used multiple times.
  --nohooks          Do not generate pacman hooks.
  --passthrough-args-first
                     Place the wrapper arguments after the passthrough arguments, so they are seen last by the wrapped executable.
  -h, --help         Print help information

Examples

Basic wrapping

Wrap /usr/bin/vim so it always launches with --servername=MYVIM:

sudo wrapperize /usr/bin/vim -a --servername=MYVIM

Multiple arguments

Add several arguments:

sudo wrapperize /usr/bin/gcc \
  -a -O3 \
  -a -march=native

Environment variables

Set environment variables when launching the executable:

sudo wrapperize /usr/bin/ssh \
  -e SSH_AUTH_SOCK=/run/user/1000/keyring/ssh \
  -e SSH_ASKPASS=/usr/bin/ssh-askpass

Passthrough order

By default the wrapper’s predefined arguments are placed before any additional arguments that may be passed to the wrapper. If you need them after, specify the --passthrough-args-first flag during wrapper creation:

sudo wrapperize /usr/bin/python3 \
  -a -O \
  --passthrough-args-first

Skipping pacman hooks

If the binary isn’t managed by pacman (e.g., a script in /home), skip the hook generation:

wrapperize /home/user/myscript.sh -e MY_VAR=foo --nohooks

How it works

Wrapper script

The original executable is renamed to a hidden file, and the generated wrapper script is created with the executable's original name:

/usr/bin/.vim-unwrapped  ← original executable
/usr/bin/vim             ← wrapper (generated by wrapperize)

The wrapper script will generally look like this (assuming both environment variables and arguments were defined during wrapper creation):

#!/usr/bin/env bash
export ENV1="value1"
export ENV2="value2"
exec "/usr/bin/.vim-unwrapped" --arg1 --arg2 "$@"

Pacman hooks

Unless skipped via the --nohooks flag, the following pacman hooks will be created in /etc/pacman.d/hooks:

  1. Install/Update hook – runs after the executable's associated package is installed or upgraded to recreate the wrapper.
    • A shell script is also generated next to this hook that is called by it to actually install the wrapper.
  2. Removal hook – runs after the executable's associated package is removed to delete the wrapper, pacman hooks, and the shell script created for the install/update hook.

About

A small program to assist in creating wrappers that always launch a program with additional arguments and/or environment variables.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages