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.
- Rust 1.93 or later.
cargo install --path wrapperizeThe binary will be installed to
~/.cargo/bin/wrapperize.
~/.cargo/binmust be added to your$PATHif it isn't already.
$ wrapperize --help
Usage: wrapperize [-a <arg...>] [-e <env...>] [--nohooks] [--passthrough-args-first] [--keep-relative] [--] <executable_path>
Positional Arguments:
executable_path path of the executable to wrap
Options:
-a, --arg an additional argument to launch the executable with; can be
used multiple times
-e, --env an environment variable in the format of `ENV=value` to
launch the executable with; can be used multiple times
--nohooks do not generate hooks for pacman; intended to be used for
paths not managed by pacman (such as `/home`)
--passthrough-args-first
place the wrapper arguments after the passthrough arguments,
so they are seen last by the wrapped executable
--keep-relative prevent the provided path from being canonicalized (made
absolute); this can only be used in combination with
`--nohooks` to minimize the chance of a path-related attack
--help, help display usage information
Wrap /usr/bin/vim so it always launches with --servername=MYVIM:
sudo wrapperize /usr/bin/vim -a --servername=MYVIMAdd several arguments:
sudo wrapperize /usr/bin/gcc \
-a -O3 \
-a -march=nativeSet 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-askpassBy 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-firstIf 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 --nohooksThe 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 "$@"Unless skipped via the --nohooks flag, the following pacman hooks will be created in /etc/pacman.d/hooks:
- 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.
- 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.