From f4e807c03256bf60934d986cd2febe9f2a8374f7 Mon Sep 17 00:00:00 2001 From: PorridgePi Date: Wed, 28 Sep 2022 19:28:20 +0800 Subject: [PATCH] zshrc: feat: Add OS determination --- .zshrc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.zshrc b/.zshrc index c9dd345..a3159f7 100644 --- a/.zshrc +++ b/.zshrc @@ -7,6 +7,41 @@ if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]] fi +########## Personal - Determine OS and Set Variables ########################## +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux + OSNAME=Linux + + if [ -f /etc/os-release ]; then + . /etc/os-release + DISTRO=$NAME + VER=$VERSION_ID + elif type lsb_release >/dev/null 2>&1; then + DISTRO=$(lsb_release -si) + VER=$(lsb_release -sr) + elif [ -f /etc/lsb-release ]; then + . /etc/lsb-release + DISTRO=$DISTRIB_ID + VER=$DISTRIB_RELEASE + elif [ -f /etc/debian_version ]; then + DISTRO=Debian + VER=$(cat /etc/debian_version) + else + # Fall back to uname + DISTRO=$(uname -s) + VER=$(uname -r) + fi +elif [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + OSNAME=macOS + VER=$(sw_vers | grep ProductVersion | cut -c 17-) +else + # Fall back to uname + OSNAME=$(uname -s) + VER=$(uname -r) +fi + + ########## Zinit ############################################################## ### Added by Zinit's installerW if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then