The systemd folks kicked this off [1,2] and stopped supporting systems
without it in 2012-02-13 [3]. I haven't used Gentoo Prefix in a long
time, so I'm dropping that here. All the other distros here have
long-since added an /etc/os-release. And it means the script will now
autodetect rhel and others I had previously not supported as well.
I'd started off on this track for Arch in
7b8f3a76
(.bashrc.d/01detect_system: Use os-release to detect Arch,
2018-04-30). This commit just moves the rest of these distros over.
Also switch from the terse '[' to the more obvious 'test', and shift
'then' (where I touch it) onto its own line. No real reasons for
those; I just like that style more for some reason.
[1]: https://www.freedesktop.org/software/systemd/man/os-release.html
[2]: http://0pointer.de/blog/projects/os-release
[3]: https://lists.freedesktop.org/archives/systemd-devel/2012-February/004475.html
Subject: [systemd-devel] [HEADS-UP] Support for /dev/os-release now kinda mandatory
Date: Mon Feb 13 09:21:32 PST 2012
# This makes it easy to adjust script locations and so forth to match
# your system's file placement and other quirks.
-if [ -z "${OS}" ]; then
+if test -z "${OS}"; then
export OS='UNKNOWN'
- if [ -f '/etc/make.conf' ] || [ -f '/etc/portage/make.conf' ]; then
- export OS='Gentoo'
- elif [ "${SHELL#*gentoo}" != "${SHELL}" ]; then # assumes 'gentoo' in prefix
- export OS='Gentoo Prefix'
- elif grep -i '^ID=.*arch' /etc/os-release > /dev/null 2>&1; then
- export OS='Arch'
- elif grep -i debian /etc/issue > /dev/null 2>&1; then
- export OS='Debian'
- elif grep -i ubuntu /etc/issue > /dev/null 2>&1; then
- export OS='Ubuntu'
- elif grep -i fedora /etc/issue > /dev/null 2>&1; then
- export OS='Fedora'
+ _OS="$(source /etc/os-release && echo "${ID}")"
+ if test -n "_OS"; then
+ export OS="${_OS}"
elif grep -i sunos /etc/motd > /dev/null 2>&1; then
export OS='SunOS'
else
-if [ "${OS}" != 'Gentoo' ] && [ "${OS}" != 'Gentoo Prefox' ]; then
+if test "${OS}" != gentoo
+then
# Enable history appending instead of overwriting.
# https://bugs.gentoo.org/show_bug.cgi?id=139609
shopt -s histappend
-if [ "${OS}" != 'Gentoo' ] && [ "${OS}" != 'Gentoo Prefix' ]; then
+if test "${OS}" != gentoo
+then
use_color=false
# Set colorful PS1 only on colorful terminals.
# You don't need to enable this if it's already enabled globally for
# your system.
-if [ "${OS}" = 'Gentoo' ]; then
+if test "${OS}" = gentoo
+then
# Gentoo-based systems
#
# Bash completion comes from the 'app-shells/bash_completion' package,
if [ -f /etc/profile.d/bash_completion.sh ]; then
. /etc/profile.d/bash_completion.sh
fi
-elif [ "${OS}" = 'Debian' ] || [ "${OS}" = 'Ubuntu' ]; then
+elif test "${OS}" = debian -o "${OS}" = ubuntu
+then
# Debian-based systems
#
# Bash completion comes from the 'bash' package, which stores the
# make less more friendly for non-text input files, see lesspipe(1)
# (Debian-based systems only)
-if [ "${OS}" = "Debian" ] || [ "${OS}" = "Ubuntu" ]; then
+if test "${OS}" = debian -o "${OS}" = ubuntu
+then
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
fi
-if [ "${OS}" = 'Ubuntu' ]; then
+if test "${OS}" = ubuntu
+then
# adjust for Ubuntu not recognizing screen.* terms
- if [ "${TERM:0:7}" == "screen." ]; then
+ if test "${TERM:0:7}" == "screen." ]
+ then
export TERM="${TERM:7}"
fi
fi
-if [ "${OS}" != 'Gentoo' ] && [ "${OS}" != 'Gentoo Prefix' ]; then
+if test "${OS}" != gentoo
+then
# Change the window title of X terminals
case ${TERM} in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix)