summaryrefslogtreecommitdiff
path: root/.zsh/utils
blob: 1097637718e2e5364150a3920a4b8801a782fc75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# utils
#
# utility functions
#
# Copyright © 2011 Tobias Klauser <tklauser@distanz.ch>
# Released under the terms of the Artistic Licence 2.0
#
# Source repository: git://git.distanz.ch/dotfiles/zsh.git

# prepend custom directory to $PATH
path_prepend()
{
  local dir
  for dir; do
    case "$PATH" in
      "*:${dir}:*"|"${dir}:*"|"*:${dir}") :;;
      *) test -d "$dir" && path=("$dir" $path);;
    esac
  done
}

# append custom directory to $PATH
path_append()
{
  local dir
  for dir; do
    case "$PATH" in
      "*:${dir}:*"|"${dir}:*"|"*:${dir}") :;;
      *) test -d "$dir" && path+="$dir";;
    esac
  done
}

# are we root?
is_root() {
  test ${EUID:?} -eq 0
}

# are we on Mac OS X?
is_darwin() {
  [[ $OSTYPE == darwin* ]] && return 0
  return 1
}

# are we running within an utf environment?
is_utfenv() {
  case "$LANG $CHARSET $LANGUAGE" in
    *utf*) return 0 ;;
    *UTF*) return 0 ;;
    *)     return 1 ;;
    esac
}

# vim:ft=zsh