Skip to content

Commit

Permalink
add --activate option to install command
Browse files Browse the repository at this point in the history
- silence output and just print path to the activate script
- useful for scripts to install and activate a compiler
  • Loading branch information
MartinNowak committed May 1, 2016
1 parent f61af1c commit d1add62
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ set -ueo pipefail
# ------------------------------------------------------------------------------

log() {
echo "${@//$HOME/\~}"
if [ "$verbosity" -gt 0 ]; then
echo "${@//$HOME/\~}"
fi
}

logV() {
if [ ! -z "$verbose" ]; then
if [ "$verbosity" -gt 1 ]; then
log "$@";
fi
}
Expand All @@ -37,7 +39,7 @@ curl() {

command=
compiler=
verbose=
verbosity=1
path=~/dlang
case $(uname -s) in
Darwin) os=osx;;
Expand Down Expand Up @@ -122,6 +124,10 @@ Description
Download and install a D compiler.
Options
-a --activate Only print the path to the activate script
Examples
install.sh install dmd
Expand Down Expand Up @@ -177,6 +183,7 @@ Description

parse_args() {
local _help=
local _activate=

while [[ $# > 0 ]]; do
case "$1" in
Expand All @@ -192,7 +199,11 @@ parse_args() {
;;

-v | --verbose)
verbose=1
verbosity=2
;;

-a | --activate)
_activate=1
;;

use | install | uninstall | list | update)
Expand All @@ -214,6 +225,14 @@ parse_args() {
[ -z "$command" ] && usage || command_help $command
exit 0
fi
if [ -n "$_activate" ]; then
if [ "${command:-install}" == "install" ]; then
verbosity=0
else
[ -z "$command" ] && usage || command_help $command
exit 1
fi
fi
}

# ------------------------------------------------------------------------------
Expand All @@ -240,10 +259,14 @@ run_command() {
if [ $(basename $SHELL) = fish ]; then
local suffix=.fish
fi
log "
if [ "$verbosity" -eq 0 ]; then
echo "$path/$2/activate${suffix:-}"
else
log "
Run \`source $path/$2/activate${suffix:-}\` in your shell to use $2.
This will setup PATH, LIBRARY_PATH, LD_LIBRARY_PATH, DMD, DC, and PS1 accordingly.
Run \`deactivate\` later on to restore your environment."
fi
;;

uninstall)
Expand Down

0 comments on commit d1add62

Please sign in to comment.