From c7f9155f864dd3d5c13791720610d332e21eab4c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 11 Jul 2018 15:08:19 -0700 Subject: [PATCH] .bashrc.d/01detect_system: Use /etc/os-release 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 | 17 ++++------------- src/.bashrc.d/05histappend | 3 ++- src/.bashrc.d/15prompt_dircolors | 3 ++- src/.bashrc.d/20completion | 6 ++++-- src/.bashrc.d/20lesspipe | 3 ++- src/.bashrc.d/20screen | 6 ++++-- src/.bashrc.d/70title | 3 ++- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/.bashrc.d/01detect_system b/src/.bashrc.d/01detect_system index 03d8f17..b46bbba 100644 --- a/src/.bashrc.d/01detect_system +++ b/src/.bashrc.d/01detect_system @@ -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 diff --git a/src/.bashrc.d/05histappend b/src/.bashrc.d/05histappend index 19fab78..6c96d65 100644 --- a/src/.bashrc.d/05histappend +++ b/src/.bashrc.d/05histappend @@ -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 diff --git a/src/.bashrc.d/15prompt_dircolors b/src/.bashrc.d/15prompt_dircolors index 16e95b0..b59af8c 100644 --- a/src/.bashrc.d/15prompt_dircolors +++ b/src/.bashrc.d/15prompt_dircolors @@ -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. diff --git a/src/.bashrc.d/20completion b/src/.bashrc.d/20completion index b99ebd9..e0ea6e4 100644 --- a/src/.bashrc.d/20completion +++ b/src/.bashrc.d/20completion @@ -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 diff --git a/src/.bashrc.d/20lesspipe b/src/.bashrc.d/20lesspipe index 792f02c..297b5a9 100644 --- a/src/.bashrc.d/20lesspipe +++ b/src/.bashrc.d/20lesspipe @@ -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 diff --git a/src/.bashrc.d/20screen b/src/.bashrc.d/20screen index 164c04b..6e7a2f6 100644 --- a/src/.bashrc.d/20screen +++ b/src/.bashrc.d/20screen @@ -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 diff --git a/src/.bashrc.d/70title b/src/.bashrc.d/70title index b6f5814..9186127 100644 --- a/src/.bashrc.d/70title +++ b/src/.bashrc.d/70title @@ -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) -- 2.26.2