.bashrc.d/01detect_system: Use /etc/os-release
authorW. Trevor King <wking@tremily.us>
Wed, 11 Jul 2018 22:08:19 +0000 (15:08 -0700)
committerW. Trevor King <wking@tremily.us>
Wed, 11 Jul 2018 22:40:21 +0000 (15:40 -0700)
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

src/.bashrc.d/01detect_system
src/.bashrc.d/05histappend
src/.bashrc.d/15prompt_dircolors
src/.bashrc.d/20completion
src/.bashrc.d/20lesspipe
src/.bashrc.d/20screen
src/.bashrc.d/70title

index 03d8f1745871f541a38facd23686807c97559903..b46bbba2760872f26e78a628584d02b888300f3a 100644 (file)
@@ -3,20 +3,11 @@
 # 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
index 19fab780025287d8ac869b4cc89ba5f4f4a1f2ec..6c96d658eec290c14bd4f2a2ca168abc1ef0d6bd 100644 (file)
@@ -1,4 +1,5 @@
-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
index 16e95b0cb98a93be355276c7aaadc0fd625b7a4a..b59af8cf98fc627ab4af91d594aefc012bb52e03 100644 (file)
@@ -1,4 +1,5 @@
-if [ "${OS}" != 'Gentoo' ] && [ "${OS}" != 'Gentoo Prefix' ]; then
+if test "${OS}" != gentoo
+then
        use_color=false
        
        # Set colorful PS1 only on colorful terminals.
index b99ebd9c50c4945579a505796837f9c173f480d1..e0ea6e45335681e3db665516747da5b4cb9c1ed2 100644 (file)
@@ -3,7 +3,8 @@
 # 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,
@@ -12,7 +13,8 @@ if [ "${OS}" = 'Gentoo' ]; then
        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
index 792f02c20b0e85f902fa63d1854d4b1dcbc517b4..297b5a94b5d9a8b0d4b559b77facc98c2cc1a2df 100644 (file)
@@ -1,6 +1,7 @@
 # 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
index 164c04bca785a3af87f257383c0c44b199428159..6e7a2f68cb72e2d7fb87acf94e260eb81dbb2b99 100644 (file)
@@ -1,6 +1,8 @@
-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
index b6f581415fe6171b65d0cb639c42d13e56312e2c..9186127546a203ad4ab32becc4af4ed196359910 100644 (file)
@@ -1,4 +1,5 @@
-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)