Skip to content

Commit

Permalink
feat(zsh): add Linux distribution checking
Browse files Browse the repository at this point in the history
- Add Linux distribution checking
  - Allow commands to be enabled only on specific Linux distributions
- Update aliases to use the new environmental variable
  • Loading branch information
d2s committed Nov 4, 2019
1 parent 52e05cc commit dedcfbb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
30 changes: 18 additions & 12 deletions zsh/aliases.zsh
Expand Up @@ -198,25 +198,31 @@ fi
# openSUSE package management helpers
# -----------------------------------------------------------

if type -p zypper &>/dev/null; then
# -----------------------------------------------------------
# Install openSUSE package defined in string variable
# Usage:
# install-opensuse-package "package"
install-opensuse-package() {
printf "\\n"
printf "sudo zypper in %s\\n" "$1"
sudo zypper in "$1"
printf "\\n\\n"
}
if [[ "$DISTRIBUTION" == "openSUSE" ]]; then
# If `zypper` is available
if type -p zypper &>/dev/null; then
# -----------------------------------------------------------
# Install openSUSE package defined in string variable
# Usage:
# install-opensuse-package "package"
install-opensuse-package() {
printf "\\n"
printf "sudo zypper in %s\\n" "$1"
sudo zypper in "$1"
printf "\\n\\n"
}

# Show openSUSE package details
alias details="zypper info"
fi
fi


# -----------------------------------------------------------
# Debian package management helpers
# -----------------------------------------------------------

if [ "$SYSTEMTYPE" = "linux" ] ; then
if [[ "$DISTRIBUTION" == "Debian" ]]; then
# If `apt` is available
if type -p apt &>/dev/null; then
# Show Debian package details
Expand Down
15 changes: 15 additions & 0 deletions zsh/zshrc.symlink
Expand Up @@ -28,6 +28,21 @@ PLATFORM="$MACHINE-$OS-$OSVERSION"
export PLATFORM


# -----------------------------------------------------------
# Check what Linux distribution you are using
CHECK_DISTRIBUTION=`cat /etc/*release | grep -w 'NAME='`

# Compare command output to check if it includes text string
if [[ "$CHECK_DISTRIBUTION" == *Debian* ]]; then
DISTRIBUTION="Debian"
elif [[ "$CHECK_DISTRIBUTION" == *openSUSE* ]]; then
DISTRIBUTION="openSUSE"
fi

# Export system-specific value based on the operating system
export DISTRIBUTION


# -----------------------------------------------------------
# Define reusable values
# -----------------------------------------------------------
Expand Down

0 comments on commit dedcfbb

Please sign in to comment.