My-Alternatives is a light-weight wrapper over update-alternatives, offering user-level customizations.
Supports Debian, SUSE*, and RedHat
* for suse support, use the debian version
With my-alternatives, configuring custom alternatives is as easy as:
home configuration example
# initialize my-alternatives
# note: place this in your .profile
$ eval "$( my-alternatives init )"
# customize an alternative
$ my-alternatives select <name>
Your selections will be saved into your HOME
configuration, and made active in any login shell that performs the initialization routine.
NOTE: You can save the initialization routine in your .profile
If you want to make a temporary change that only modifies your current shell session, you can initialize a TEMP
configuration:
temp configuration example
# initialize a temporary configuration
# note: your HOME configuration must already be initialized
$ my-alternatives init-tmp
# customize an alternative for just the current shell
$ my-alternatives select <name>
The first time you select
an alternative, my-alternatives automatically imports the alternative group into your configuration.
When the HOME
configuration is the active configuration, my-alternatives imports the group from the system-level configuration.
When a TEMP
configuration is active, my-alternatives first tries to import from your HOME
configuration, falling back onto the system-level configuration if the group is not present.
If you want to import an alternative group into your active configuration without selecting an alternative, you can use the import
command:
import example
$ my-alternatives import <name>
Below are tables of the available commands for each supported OS
NOTE: SUSE uses a rebranded version of Debian's udpate-alternatives.
Until such time as the feature set of the two versions diverges, this project will just maintain the Debian vesion.
Below is the list of custom commands that my-alternatives-debian implements:
Command | Description |
---|---|
init , shellenv |
Prepare the current shell session for user-level alternatives. |
init-tmp , tmp |
Configure the current shell session for temporary (short-lived) changes. |
rm-tmp |
Remove the temporary configuration from the current shell session, making the HOME configuration active. |
select , config |
Select the active alternative for a group. This is equivalent to update-alternatives --config with the adition of the auto-import logic. |
import |
Import an alternative group into the current configuration. |
add |
Add an alternative to a group within the current configuration. This is equivalent to update-alternatives --install but has slightly different syntax. see my-alternatives help add for details. |
version |
Display my-alternatives version number. |
NOTE: See my-alternatives help <command>
to learn about a specific command, including additional options.
Below is the list of commands that are implemented as pass-through to the related Debian update-alternatives command:
My-Alternatives Command | Update-Alternatives Command |
---|---|
select , config |
--config |
select-all , --config-all |
--all |
rm-alt |
--remove |
rm-group , rm-grp |
--remove-all |
query |
--query |
display |
--display |
list |
--list |
set |
--set |
auto |
--auto |
get-selections |
--get-selections |
set-selections |
--set-selections |
ua-help |
--help |
ua-version |
--version |
My-Alternatives will set the --admindir
and --altdir
options to point to your active configuration.
All additional command-line options are passed-through, unmodified.
NOTE: See update-alternatives --help
or man update-alternatives
to learn more about the various commands and their options.
RedHat has its own implementation of update-alternatives, which is slightly different from the Debian version.
One major difference is that it does NOT support the --query
option, meaning that there's no means of determining an anternative's full configuraiton using just the tool's public API.
In order to support this version, we have to use knowledge of the system's private API. Namely:
- Defaulting the "admin" directory to
/var/lib/alternatives
- Assuming the name and format of files in the admin directory
- Defaulting the "alt" directory to
/etc/alternatives
- Assuming the name and nature of files in the alt directory
Below is the list of custom commands that my-alternatives-redhat implements:
Command | Description |
---|---|
init , shellenv |
Prepare the current shell session for user-level alternatives. |
init-tmp , tmp |
Configure the current shell session for temporary (short-lived) changes. |
rm-tmp |
Remove the temporary configuration from the current shell session, making the HOME configuration active. |
select , config |
Select the active alternative for a group. This is equivalent to update-alternatives --config with the adition of the auto-import logic. |
import |
Import an alternative group into the current configuration. |
add |
Add an alternative to a group within the current configuration. This is equivalent to update-alternatives --install but has slightly different syntax. see my-alternatives help add for details. |
add-child |
Add an child to an existing alternative for a group within the current configuration. This is equivalent to update-alternatives --add-slave but has slightly different syntax. see my-alternatives help add-child for details. |
version |
Display my-alternatives version number. |
NOTE: See my-alternatives help <command>
to learn about a specific command, including additional options.
Below is the list of commands that are implemented as pass-through to the related RedHat update-alternatives command:
My-Alternatives Command | Update-Alternatives Command |
---|---|
select , config |
--config |
add-child |
--add-slave |
rm-alt |
--remove |
rm-group , rm-grp |
--remove-all |
rm-child |
--remove-slave |
display |
--display |
list |
--list |
set |
--set |
auto |
--auto |
ua-help |
--help |
ua-version |
--version |
My-Alternatives will set the --admindir
and --altdir
options to point to your active configuration.
All additional command-line options are passed-through, unmodified.
NOTE: See update-alternatives --help
or man update-alternatives
to learn more about the various commands and their options.
If you need to pass a specific command to update-alternatives, you can do so using the ua
command:
invoke update-alternatives directly
$ my-alternatives ua --display pager
My-Alternatives will set the --admindir
and --altdir
options to point to your active configuration.
All additional command-line options are passed-through, unmodified.
NOTE: See update-alternatives --help
or man update-alternatives
to learn more about available commands and their options.
See the Releases page for downloadable archives of versioned releases.
git clone git://github.com/TekWizely/my-alternatives.git
Depending on how you acquire the files, the scripts may be named by their OS flavor, i.e:
- Debian :
my-alternatives-debian
- RedHat :
my-alternatives-redhat
Feel free to rename them as desired. Personally, I rename the script AND set up a few convenient aliases:
$ cp my-alternatives-debian ~/bin/my-alternatives
$ alias ma="my-alternatives"
$ alias mua="my-alternatives ua"
To contribute to My-Alternatives, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes and commit them:
git commit -m '<commit_message>'
- Push to the original branch:
git push origin <project_name>/<location>
- Create the pull request.
Alternatively see the GitHub documentation on creating a pull request.
If you want to contact me you can reach me at TekWizely@gmail.com.
The tekwizely/my-alternatives
project is released under the MIT License. See LICENSE
file.
As of v0.7.0
, my-alternatives has been split (and renamed) into two scripts: my-alternatives-debian
and my-alternatives-redhat
.
As of v0.6.0
, my-alternatives is a complete re-write. As much as possible, commands are implemented as pass-through to update-alternatives, pointing to your active configuration.
My-Alternatives does not require root / sudo privileges to use, as it creates and maintains user-owned configuration directories.
CAVEATS:
- Written in Bash
- Requires the following system tools:
update-alternatives
readlink
(redhat version)mktemp
(debian version)umask
dirname
basename
manpath
(optional)
- Utilizes tmp files / directories
- Sets
umask 077
for safety
- Sets
- Tested on:
- Ubuntu
Ubuntu 20.04.3 LTS
Debian update-alternatives version 1.19.7.
Bash 5.0.17(1)-release
- openSUSE
openSUSE Leap 15.3
SUSE update-alternatives version 1.19.0.4.
Bash 4.4.23(1)-release
- CentOS
CentOS Linux release 8.4.2105
alternatives version 1.13
GNU bash, version 4.4.19(1)-release
- Ubuntu