-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
276 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,123 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Figure out if we need sudo or not | ||
sudo='' | ||
if [[ $EUID -ne 0 ]]; then | ||
sudo='sudo' | ||
fi | ||
|
||
# Download script from Github | ||
echo "=== Saving executable to /usr/local/bin/rush" | ||
curl_command="curl -s https://raw.githubusercontent.com/DannyBen/rush-cli/master/rush > /usr/local/bin/rush" | ||
$sudo bash -c "$curl_command" | ||
$sudo chmod a+x /usr/local/bin/rush | ||
|
||
# Install completions | ||
if [[ -d "/usr/share/bash-completion/completions" ]]; then | ||
compdir="/usr/share/bash-completion/completions" | ||
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then | ||
compdir="/usr/local/etc/bash_completion.d" | ||
else | ||
compdir='' | ||
fi | ||
|
||
if [[ -n $compdir ]]; then | ||
echo "=== Installing autocompletions to $compdir" | ||
echo "eval \"\$(rush completions)\"" | $sudo tee "${compdir}/rush" >/dev/null | ||
else | ||
echo "=== Completion script was not installed" | ||
echo " To install it manually add this to your startup script:" | ||
echo " eval \"\$(rush completions)\"" | ||
fi | ||
|
||
# Verify | ||
if type rush >/dev/null; then | ||
echo "=== Done. Type 'rush --help' for more info." | ||
else | ||
echo "=== Setup failed." | ||
exit 1 | ||
fi | ||
print_in_color() { | ||
local color="$1" | ||
shift | ||
if [[ -z ${NO_COLOR+x} ]]; then | ||
printf "$color%b\e[0m\n" "$*" | ||
else | ||
printf "%b\n" "$*" | ||
fi | ||
} | ||
|
||
red() { print_in_color "\e[31m" "$*"; } | ||
green() { print_in_color "\e[32m" "$*"; } | ||
green_bold() { print_in_color "\e[1;32m" "$*"; } | ||
blue() { print_in_color "\e[34m" "$*"; } | ||
|
||
section() { | ||
printf "\n=== %s\n" "$(green_bold "$@")" | ||
} | ||
|
||
copy() { | ||
printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2" | ||
cp "$origin/$1" "$2" | ||
} | ||
|
||
sudo_copy() { | ||
printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2" | ||
$sudo cp "$origin/$1" "$2" | ||
} | ||
|
||
copy_executable() { | ||
sudo_copy "$1" "/usr/local/bin/" | ||
$sudo chmod a+x "/usr/local/bin/$1" | ||
} | ||
|
||
copy_man() { | ||
if [[ ! -d "/usr/local/share/man/man1/" ]]; then return; fi | ||
|
||
for file in "$1"/*.1; do | ||
sudo_copy "$file" "/usr/local/share/man/man1/" | ||
done | ||
|
||
if command_exist makewhatis; then | ||
$sudo makewhatis /usr/local/man | ||
fi | ||
} | ||
|
||
install_completions() { | ||
cmd="$1" | ||
dir="$2" | ||
|
||
if [[ -d "/usr/share/bash-completion/completions" ]]; then | ||
compdir="/usr/share/bash-completion/completions" | ||
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then | ||
compdir="/usr/local/etc/bash_completion.d" | ||
else | ||
compdir='' | ||
fi | ||
|
||
if [[ -n $compdir ]]; then | ||
printf "copying to %s\n" "$compdir" | ||
echo "eval \"\$($cmd)\"" | $sudo tee "${compdir}/${dir}" >/dev/null | ||
else | ||
printf "%s %s\n" "$(red WARN)" "skipping completions installation, compdir not found" | ||
echo " install it manually by adding this to your startup script:" | ||
echo " eval \"\$($cmd)\"" | ||
fi | ||
} | ||
|
||
command_exist() { | ||
[[ -x "$(command -v "$1")" ]] | ||
} | ||
|
||
need() { | ||
command_exist "$1" || fail "Cannot run $1" | ||
printf "%s found\n" "$(blue " $1")" | ||
} | ||
|
||
onerror() { | ||
local exit_status=$? | ||
printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")" | ||
exit $exit_status | ||
} | ||
|
||
fail() { | ||
printf "$(red 'ERR') %s\n" "$*" | ||
return 1 | ||
} | ||
|
||
initialize() { | ||
set -e | ||
trap 'onerror' ERR | ||
|
||
# Figure out if we need sudo or not | ||
sudo='' | ||
if [[ $EUID -ne 0 ]]; then | ||
sudo='sudo' | ||
fi | ||
|
||
repo="$1" | ||
repo_url="https://github.com/${repo}.git" | ||
origin=$(mktemp -d) | ||
} | ||
|
||
section "Initializing" | ||
initialize "DannyBen/rush-cli" | ||
|
||
section "Checking for pre-requisites" | ||
need git | ||
|
||
section "Cloning $repo" | ||
git clone --depth 1 "$repo_url" "$origin" | ||
|
||
section "Copying files" | ||
copy_executable 'rush' | ||
copy_man 'doc' | ||
|
||
section "Installing bash completions" | ||
install_completions "rush_completions" "rush" | ||
|
||
section "Done" | ||
rush --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
rush add | ||
|
||
Register a local repository. | ||
|
||
This command adds the specified path to the configuration file. | ||
|
||
Alias: a | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.