Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS name and version #724

Closed
nojhan opened this issue Aug 16, 2022 · 2 comments
Closed

OS name and version #724

nojhan opened this issue Aug 16, 2022 · 2 comments
Assignees
Labels
enhancement Feature request good first issue help wanted An issue where ideas or patches are welcome
Milestone

Comments

@nojhan
Copy link
Collaborator

nojhan commented Aug 16, 2022

Display the OS name and version.

Description

Display somewhere the operating system name, optionally along with its version.
Probably use lsb_release.

Not sure this can be done in a portable way, especially for Linux.

@nojhan nojhan added the enhancement Feature request label Aug 16, 2022
@Rycieos
Copy link
Collaborator

Rycieos commented Aug 21, 2022

Not sure this can be done in a portable way, especially for Linux.

That is going to be the trick. For the external-tool-tester.sh, I just dump as much info as possible, and let the human reader figure it out:

https://github.com/nojhan/liquidprompt/blob/6f0dc9f7dda99fe98c6dce26be5e461692782c6d/tools/external-tool-tester.sh#L24-L34

Portability is not likely without a bunch of testing and work put in. Might be easiest to just do uname -o or uname -s or even uname and return that as the OS. Open to ideas.

@Rycieos Rycieos added the help wanted An issue where ideas or patches are welcome label Aug 21, 2022
@nojhan
Copy link
Collaborator Author

nojhan commented Oct 30, 2022

Here is how Powerlevel10k is doing it in at most 3 subshell calls (MIT licensed):

  _p9k_uname="$(uname)"
  [[ $_p9k_uname == Linux ]] && _p9k_uname_o="$(uname -o 2>/dev/null)"
  _p9k_uname_m="$(uname -m)"

  if [[ $_p9k_uname == Linux && $_p9k_uname_o == Android ]]; then
    _p9k_set_os Android ANDROID_ICON
  else
    case $_p9k_uname in
      SunOS)                     _p9k_set_os Solaris SUNOS_ICON;;
      Darwin)                    _p9k_set_os OSX     APPLE_ICON;;
      CYGWIN*|MSYS*|MINGW*)      _p9k_set_os Windows WINDOWS_ICON;;
      FreeBSD|OpenBSD|DragonFly) _p9k_set_os BSD     FREEBSD_ICON;;
      Linux)
        _p9k_os='Linux'
        local os_release_id
        if [[ -r /etc/os-release ]]; then
          local lines=(${(f)"$(</etc/os-release)"})
          lines=(${(@M)lines:#ID=*})
          (( $#lines == 1 )) && os_release_id=${lines[1]#ID=}
        elif [[ -e /etc/artix-release ]]; then
          os_release_id=artix
        fi
        case $os_release_id in
          *arch*)                  _p9k_set_os Linux LINUX_ARCH_ICON;;
          *debian*)                _p9k_set_os Linux LINUX_DEBIAN_ICON;;
          *raspbian*)              _p9k_set_os Linux LINUX_RASPBIAN_ICON;;
          *ubuntu*)                _p9k_set_os Linux LINUX_UBUNTU_ICON;;
          *elementary*)            _p9k_set_os Linux LINUX_ELEMENTARY_ICON;;
          *fedora*)                _p9k_set_os Linux LINUX_FEDORA_ICON;;
          *coreos*)                _p9k_set_os Linux LINUX_COREOS_ICON;;
          *gentoo*)                _p9k_set_os Linux LINUX_GENTOO_ICON;;
          *mageia*)                _p9k_set_os Linux LINUX_MAGEIA_ICON;;
          *centos*)                _p9k_set_os Linux LINUX_CENTOS_ICON;;
          *opensuse*|*tumbleweed*) _p9k_set_os Linux LINUX_OPENSUSE_ICON;;
          *sabayon*)               _p9k_set_os Linux LINUX_SABAYON_ICON;;
          *slackware*)             _p9k_set_os Linux LINUX_SLACKWARE_ICON;;
          *linuxmint*)             _p9k_set_os Linux LINUX_MINT_ICON;;
          *alpine*)                _p9k_set_os Linux LINUX_ALPINE_ICON;;
          *aosc*)                  _p9k_set_os Linux LINUX_AOSC_ICON;;
          *nixos*)                 _p9k_set_os Linux LINUX_NIXOS_ICON;;
          *devuan*)                _p9k_set_os Linux LINUX_DEVUAN_ICON;;
          *manjaro*)               _p9k_set_os Linux LINUX_MANJARO_ICON;;
          *void*)                  _p9k_set_os Linux LINUX_VOID_ICON;;
          *artix*)                 _p9k_set_os Linux LINUX_ARTIX_ICON;;
          *rhel*)                  _p9k_set_os Linux LINUX_RHEL_ICON;;
          amzn)                    _p9k_set_os Linux LINUX_AMZN_ICON;;
          *)                       _p9k_set_os Linux LINUX_ICON;;
        esac
        ;;
    esac
  fi

@nojhan nojhan self-assigned this Nov 3, 2022
@nojhan nojhan added this to the v2.2 milestone Nov 3, 2022
nojhan added a commit that referenced this issue Nov 3, 2022
- Implements #724
- Display arch, family, kernel, distrib, version codename.
- As a dev env item.
- With hash-colored items.
- Adds the `_lp_substitute` utility function.
nojhan added a commit that referenced this issue Nov 15, 2022
- Implements #724
- Display arch, family, kernel, distrib, version codename.
- As a dev env item.
- With hash-colored items.
- Adds the `_lp_substitute` utility function.
nojhan added a commit that referenced this issue Dec 3, 2022
- Implements #724
- Display arch, family, kernel, distrib, version codename.
- As a dev env item.
- With hash-colored items.
- Adds the `_lp_substitute` utility function.

Co-authored-by: Mark Vander Stel <mvndrstl@gmail.com>
@nojhan nojhan closed this as completed Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request good first issue help wanted An issue where ideas or patches are welcome
Projects
None yet
Development

No branches or pull requests

2 participants