Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 133 lines (110 sloc) 2.249 kb
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
#!/usr/bin/env bash

# Display colorized information output
function cinfo() {
  COLOR='\033[01;33m' # bold yellow
  RESET='\033[00;00m' # normal white
  MESSAGE=${@:-"${RESET}Error: No message passed"}
  echo -e "${COLOR}${MESSAGE}${RESET}"
}

# Display colorized warning output
function cwarn() {
  COLOR='\033[01;31m' # bold red
  RESET='\033[00;00m' # normal white
  MESSAGE=${@:-"${RESET}Error: No message passed"}
  echo -e "${COLOR}${MESSAGE}${RESET}"
}

set_variables() {
  STOW=$PACKAGE-$VERSION
  PREFIX=$STOW_PATH/$STOW
}

verify_installed() {
  if [ ! -d $STOW_PATH/$1 ]; then
echo "Error: ${1} is not installed."
    exit 1
  fi
}

# TODO: Before linking detect similar formula linked!
stow_link() {
  echo "${1} linked."
  stow -d $STOW_PATH $1
  touch $STOW_PATH/.stow_${1}
}

stow_unlink() {
  if [ ! -f $STOW_PATH/.stow_${1} ]; then
echo "${1} not linked."
  else
echo "${1} unlinked."
    stow -D -d $STOW_PATH ${1}
    rm $STOW_PATH/.stow_${1}
  fi
}

stow_link_one() {
  verify_installed $STOW
  stow_link $STOW
}

stow_unlink_one() {
  verify_installed $STOW
  stow_unlink $STOW
}

stow_link_all() {
  for item in $STOW_PATH/*; do
stow_link ${item##*/}
  done
}

stow_unlink_all() {
  for item in $STOW_PATH/*; do
item=${item##*/}
    if [ $item = $STOW_PACKAGE ]; then
echo "${item} not unlinked."
    else
stow_unlink $item
    fi
done
}

# Before removing a package we need to verify it's not linked.
stow_remove() {
  CONTROL_FILE="${STOW_PATH}/.stow_${1}"

  if [ ! -d $STOW_PATH/$STOW ]; then
echo "Package is not installed."
    exit 1
  fi

if [ -f $CONTROL_FILE ]; then
echo "${1} linked. Can't remove."
    exit 1
  else
rm -rf $STOW_PATH/$STOW
    echo "Removed package files."
  fi
}

_install() {
  [ ! -z $_INSTALL ]
}

_uninstall() {
  [ ! -z $_UNINSTALL ]
}

_info() {
  [ ! -z $_INFO ]
}

_link() {
  [ ! -z $_LINK ]
}

resolve_link() {
  $(type -p greadlink readlink | head -1) "$1"
}

abs_dirname() {
  local cwd="$(pwd)"
  local path="$1"

  while [ -n "$path" ]; do
cd "${path%/*}"
    local name="${path##*/}"
    path="$(resolve_link "$name" || true)"
  done

pwd
cd "$cwd"
}

set_options() {
  all=""
  if [ "$1" = "--all" ]; then
all=1
  fi
}
Something went wrong with that request. Please try again.