Browse Source

feat(helper): add os-type helper functions

Add the following functions:

- is-darwin
- is-linux
- is-bsd
- is-cygwin

And apply them everywhere I found code doing that what these functions do.
master
Kaspar Vollenweider 5 years ago committed by Kaleb Elwert
parent
commit
b133a6df81
  1. 2
      modules/haskell/init.zsh
  2. 20
      modules/helper/init.zsh
  3. 2
      modules/homebrew/init.zsh
  4. 2
      modules/macports/init.zsh
  5. 2
      modules/osx/init.zsh
  6. 2
      modules/perl/init.zsh
  7. 2
      modules/python/init.zsh
  8. 2
      modules/rsync/init.zsh
  9. 6
      modules/utility/init.zsh

2
modules/haskell/init.zsh

@ -11,7 +11,7 @@ if (( ! $+commands[ghc] )); then
fi fi
# Prepend Cabal per user directories to PATH. # Prepend Cabal per user directories to PATH.
if [[ "$OSTYPE" == darwin* && -d $HOME/Library/Haskell ]]; then if is-darwin && [[ -d $HOME/Library/Haskell ]]; then
path=($HOME/Library/Haskell/bin(/N) $path) path=($HOME/Library/Haskell/bin(/N) $path)
else else
path=($HOME/.cabal/bin(/N) $path) path=($HOME/.cabal/bin(/N) $path)

20
modules/helper/init.zsh

@ -29,3 +29,23 @@ function coalesce {
done done
return 1 return 1
} }
# is true on MacOS Darwin
function is-darwin {
[[ "$OSTYPE" == darwin* ]]
}
# is true on Linux's
function is-linux {
[[ "$OSTYPE" == linux* ]]
}
# is true on BSD's
function is-bsd {
[[ "$OSTYPE" == *bsd* ]]
}
# is true on Cygwin (Windows)
function is-cygwin {
[[ "$OSTYPE" == cygwin* ]]
}

2
modules/homebrew/init.zsh

@ -6,7 +6,7 @@
# #
# Return if requirements are not found. # Return if requirements are not found.
if [[ "$OSTYPE" != (darwin|linux)* ]]; then if ! is-darwin || ! is-linux; then
return 1 return 1
fi fi

2
modules/macports/init.zsh

@ -7,7 +7,7 @@
# #
# Return if requirements are not found. # Return if requirements are not found.
if [[ "$OSTYPE" != darwin* ]]; then if ! is-darwin; then
return 1 return 1
fi fi

2
modules/osx/init.zsh

@ -6,7 +6,7 @@
# #
# Return if requirements are not found. # Return if requirements are not found.
if [[ "$OSTYPE" != darwin* ]]; then if ! is-darwin; then
return 1 return 1
fi fi

2
modules/perl/init.zsh

@ -37,7 +37,7 @@ fi
# Local Module Installation # Local Module Installation
# #
if [[ "$OSTYPE" == darwin* ]]; then if is-darwin; then
# Perl is slow; cache its output. # Perl is slow; cache its output.
cache_file="${TMPDIR:-/tmp}/prezto-perl-cache.$UID.zsh" cache_file="${TMPDIR:-/tmp}/prezto-perl-cache.$UID.zsh"
perl_path="$HOME/Library/Perl/5.12" perl_path="$HOME/Library/Perl/5.12"

2
modules/python/init.zsh

@ -22,7 +22,7 @@ elif (( $+commands[pyenv] )); then
else else
if [[ -n "$PYTHONUSERBASE" ]]; then if [[ -n "$PYTHONUSERBASE" ]]; then
path=($PYTHONUSERBASE/bin $path) path=($PYTHONUSERBASE/bin $path)
elif [[ "$OSTYPE" == darwin* ]]; then elif is-darwin; then
path=($HOME/Library/Python/*/bin(N) $path) path=($HOME/Library/Python/*/bin(N) $path)
else else
# This is subject to change. # This is subject to change.

2
modules/rsync/init.zsh

@ -23,7 +23,7 @@ fi
# macOS and HFS+ Enhancements # macOS and HFS+ Enhancements
# https://bombich.com/kb/ccc5/credits # https://bombich.com/kb/ccc5/credits
if [[ "$OSTYPE" == darwin* ]] && grep -q 'file-flags' <(rsync --help 2>&1); then if is-darwin && grep -q 'file-flags' <(rsync --help 2>&1); then
_rsync_cmd="${_rsync_cmd} --crtimes --fileflags --protect-decmpfs --force-change" _rsync_cmd="${_rsync_cmd} --crtimes --fileflags --protect-decmpfs --force-change"
fi fi

6
modules/utility/init.zsh

@ -134,9 +134,9 @@ if zstyle -t ':prezto:module:utility:grep' color; then
fi fi
# macOS Everywhere # macOS Everywhere
if [[ "$OSTYPE" == darwin* ]]; then if is-darwin; then
alias o='open' alias o='open'
elif [[ "$OSTYPE" == cygwin* ]]; then elif is-cygwin; then
alias o='cygstart' alias o='cygstart'
alias pbcopy='tee > /dev/clipboard' alias pbcopy='tee > /dev/clipboard'
alias pbpaste='cat /dev/clipboard' alias pbpaste='cat /dev/clipboard'
@ -166,7 +166,7 @@ fi
alias df='df -kh' alias df='df -kh'
alias du='du -kh' alias du='du -kh'
if [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then if is-darwin || is-bsd; then
alias topc='top -o cpu' alias topc='top -o cpu'
alias topm='top -o vsize' alias topm='top -o vsize'
else else

Loading…
Cancel
Save