From 0ffc11903dcfdc08c91cd30bc66bb7503d36aa96 Mon Sep 17 00:00:00 2001 From: GeekMasher Date: Wed, 5 Feb 2025 15:25:19 +0000 Subject: [PATCH] feat: Update OS detection support and scripts --- geek/.geek/updates.sh | 42 +++++++++++++----------------------------- zsh/.zshrc | 28 +++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/geek/.geek/updates.sh b/geek/.geek/updates.sh index 689de44..8a17db4 100755 --- a/geek/.geek/updates.sh +++ b/geek/.geek/updates.sh @@ -1,35 +1,19 @@ #!/bin/bash -unameOut="$(uname -s)" -case "${unameOut}" in - Linux*) machine=Linux;; - Darwin*) machine=Mac;; - CYGWIN*) machine=Cygwin;; - MINGW*) machine=MinGw;; - *) machine="UNKNOWN:${unameOut}" -esac -distoOut="$(lsb_release -si)" -case "${distoOut}" in - Ubuntu*) distro=Ubuntu;; - Pop*) distro=PopOS;; - Debian*) distro=Debian;; - *) distro="" -esac - # Base commands -if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then +if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then alias deb-install="sudo dpkg -i $1 && sudo apt install -f" fi update() { - if [[ "$machine" == "Linux" ]]; then - if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then + if [[ "$OSTYPE" == "Linux" ]]; then + if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then sudo apt update -y else echo "Unknown Distro / Package Manager" fi - elif [[ "$machine" == "Mac" ]]; then + elif [[ "$OSTYPE" == "Macos" ]]; then brew update else echo "Unknown OS: $machine" @@ -37,8 +21,8 @@ update() { } upgrade() { - if [[ "$machine" == "Linux" ]]; then - if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then + if [[ "$OSTYPE" == "Linux" ]]; then + if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then echo "Updating apt..." sudo apt upgrade -y sudo apt dist-upgrade -y @@ -52,7 +36,7 @@ upgrade() { if [[ -x "$(flatpak)" ]]; then flatpak update fi - elif [[ "$machine" == "Darwin" ]]; then + elif [[ "$OSTYPE" == "Macos" ]]; then echo "Updating brew..." brew update brew upgrade @@ -77,11 +61,11 @@ install() { # Update first before search update - if [[ "$machine" == "Linux" ]]; then - if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then + if [[ "$OSTYPE" == "Linux" ]]; then + if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then sudo apt install -y "$*" fi - elif [[ "$machine" == "Darwin" ]]; then + elif [[ "$OSTYPE" == "Macos" ]]; then brew install "$*" else echo "Unknown OS: $machine" @@ -89,11 +73,11 @@ install() { } search() { - if [[ "$machine" == "Linux" ]]; then - if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then + if [[ "$OSTYPE" == "Linux" ]]; then + if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then sudo apt-cache search "$*" fi - elif [[ "$machine" == "Darwin" ]]; then + elif [[ "$OSTYPE" == "Macos" ]]; then brew search "$*" else echo "Unknown OS: $machine" diff --git a/zsh/.zshrc b/zsh/.zshrc index c70996f..e15e489 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -1,9 +1,23 @@ +#!/bin/bash + +# OS Detection +case "$(uname -s)" in + Linux*) + export OSTYPE=Linux;; + Darwin*) + export OSTYPE=Macos;; + *) + echo "Unknown Operating System: $(uname -s)" +esac # Export different paths export PATH=$HOME/.geek/bin:$HOME/.local:/usr/local/bin:$PATH -if [[ "$OSTYPE" == "darwin"* ]]; then +if [[ "$OSTYPE" == "Macos" ]]; then export ZSH=/Users/$USER/.oh-my-zsh + # Assumes zsh suggestions are from brew + source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh + plugins=( 1password git @@ -17,6 +31,14 @@ if [[ "$OSTYPE" == "darwin"* ]]; then zsh-autosuggestions ) else + # Distro + case "$(lsb_release -si)" in + Ubuntu*) distro=Ubuntu;; + Pop*) distro=PopOS;; + Debian*) distro=Debian;; + *) distro="" + esac + export ZSH=$HOME/.oh-my-zsh # See https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins plugins=( @@ -63,3 +85,7 @@ if [ -x "$(command -v fastfetch)" ]; then fastfetch fi + +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion