Skip to content

Commit

Permalink
feat(nvm): add support for nvm in place of direct node install
Browse files Browse the repository at this point in the history
  • Loading branch information
Deavon McCaffery committed Nov 14, 2016
1 parent dcf50a6 commit 5064c06
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 38 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Uber is a prompt for BaSH on *nix distributions that includes a ton of useful fu
* Show available colors (already set as variables for use elsewhere)
* ... and much more.

Note: All "extensions" are implemented as sourced function calls, so it should not interfere with existing
Note: All "extensions" are implemented as sourced function calls, so it should not interfere with existing
customization (aside from the prompt).

### Using Uber
Expand All @@ -50,7 +50,7 @@ cd uber
3) Open a new terminal window, or source the initialization script in the existing terminal:

``` bash
source ~/.ssh/bashrc
source $HOME/.uber/bashrc
```

3) (Optional) Open the included Monokai theme (currently only supported on OS X):
Expand All @@ -59,10 +59,10 @@ source ~/.ssh/bashrc
themes
```

**NOTE**: The installer simply creates a new folder (.ssh) under the root folder, and copies all of the files there.
It will backup this folder to ./backup first. It wires up the "extensions" by adding a source command for ~/.ssh/bashrc
to ~/.bash_profile. It will not duplicate itself, so you can re-run the installer to upgrade at any time. the
~/.bash_profile is also backed up to ./backup/.bash_profile.
**NOTE**: The installer simply creates a new folder (.uber) under the root folder, and copies all of the files there.
It will backup this folder to ./backup first. It wires up the "extensions" by adding a source command for $HOME/.uber/bashrc
to $HOME/.bash_profile. It will not duplicate itself, so you can re-run the installer to upgrade at any time. the
$HOME/.bash_profile is also backed up to ./backup/[date].bash_profile.

## Copright and License

Expand Down
33 changes: 24 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function success() {
}

now=$(date +"%Y%m%d_%H%M%S")
backup_path="backup/$now"

success "Creating backup path : $pwd/backup/$now..."
mkdir -p "backup/$now" 1>/dev/null
Expand All @@ -26,18 +27,18 @@ mkdir -p ~/.uber 1>/dev/null
success "Installing uber to ~/.uber..."
cp -Rf src/* ~/.uber 1>/dev/null

if test -f backup/uber/scripts/bookmarks.sh; then
if test -f $backup_path/scripts/bookmarks.sh; then
success "Restoring bookmarks..."
cp -R backup/uber/scripts/bookmarks.sh ~/.uber/scripts 1>/dev/null
cp -R $backup_path/uber/scripts/bookmarks.sh ~/.uber/scripts 1>/dev/null
fi

for template in template/*; do
name=$(basename "$template")
path=~/.${name}
path=$HOME/.${name}

if test -f $path; then
success "Backing up ${name}..."
cp $path backup/$name
cp $path $backup_path/$name
fi

cat $template > $path
Expand All @@ -61,21 +62,35 @@ if test "$UNAME" = "Darwin"; then
for pkg in git-flow; do
if brew list -1 | grep -q "^${pkg}\$"; then
success "Uninstalling $pkg..."
brew uninstall ${pkg} 1>/dev/null
brew uninstall ${pkg} 1>/dev/null 2>&1
fi
done

for pkg in openssl git git-extras git-flow-avh nvm; do
if brew list -1 | grep -q "^${pkg}\$"; then
success "Upgrading $pkg..."
brew upgrade ${pkg} 1>/dev/null
brew link --overwrite ${pkg} 1>/dev/null
brew upgrade ${pkg} 1>/dev/null 2>&1
brew link --overwrite ${pkg} 1>/dev/null 2>&1
else
success "Installing $pkg..."
brew install ${pkg}
brew install ${pkg} 1>/dev/null 2>&1
fi
done

nvm_path=$(brew --prefix nvm)

if test -d $nvm_path; then
if ! test -d $HOME/.nvm; then
mkdir -p $HOME/.nvm
fi

export NVM_DIR=~/.nvm

. $nvm_path/nvm.sh

nvm use --lts 1>/dev/null
fi

success "Setting git credential helper to use the macOS keychain..."
git config --system credential.helper osxkeychain 1>/dev/null
fi
Expand Down Expand Up @@ -124,7 +139,7 @@ fi

if test -f "$BASH_COMPLETION/$GIT_PROMPT_NAME"; then
success "Removing crappy git-prompt..."
sudo rm -rf "$BASH_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/nullcd ~
sudo rm -rf "$BASH_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null
fi

if ! test -d "$UBER_COMPLETION"; then
Expand Down
12 changes: 8 additions & 4 deletions src/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,27 @@ fi

# turn on advanced completion
if test -f /etc/bash_completion; then
. /etc/bash_completion
source /etc/bash_completion
fi

# determine if bash completion exists elsewhere
if test -f /usr/share/bash-completion/bash_completion; then
. /usr/share/bash-completion/bash_completion
source /usr/share/bash-completion/bash_completion
fi

# source completions
for completion in ~/.uber/completions/*; do
for completion in $HOME/.uber/completions/*; do
source $completion
done

# source scripts
for script in ~/.uber/scripts/*.sh; do
for script in $HOME/.uber/scripts/*.sh; do
source $script
done

# set the prompt
set-prompt

# aliases
# -- prompt for overwrites
alias cp='cp -i'
Expand Down
13 changes: 13 additions & 0 deletions src/scripts/Darwin/add-ssh-keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'add-ssh-keys'
fi
function add-ssh-keys() {
ssh-add -A 2>/dev/null
}

# this is a workaround for the new behavior in macOS Sierra where
# private key pass-phrases are no longer loaded from the keychain
# by default
add-ssh-keys
4 changes: 3 additions & 1 deletion src/scripts/Darwin/flush-dns.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'flush-dns'
fi
Expand All @@ -9,4 +11,4 @@ function flush-dns() {

function flushdns() {
flush-dns
}
}
2 changes: 2 additions & 0 deletions src/scripts/Darwin/git-extras.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'git-extras'
fi
Expand Down
3 changes: 3 additions & 0 deletions src/scripts/Darwin/hide-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'hide-all'
fi

function hide-all() {
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder
Expand Down
24 changes: 24 additions & 0 deletions src/scripts/Darwin/set-nvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'set-nvm'
fi

function set-nvm()
{
nvm_path=$(brew --prefix nvm)

if test -d $nvm_path; then
if ! test -d $HOME/.nvm; then
mkdir -p $HOME/.nvm
fi

export NVM_DIR=$HOME/.nvm

source $nvm_path/nvm.sh
fi

nvm use --lts
}

set-nvm
2 changes: 2 additions & 0 deletions src/scripts/Darwin/show-all.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'show-all'
fi
Expand Down
4 changes: 3 additions & 1 deletion src/scripts/Darwin/themes.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'themes'
fi

function themes() {
open ~/.ssh/themes/terminal/Monokai.terminal
open $HOME/.uber/themes/terminal/Monokai.terminal
}
4 changes: 2 additions & 2 deletions src/scripts/add-bookmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function add-bookmark() {
local b="$1"=\"$(pwd)\"

echo Adding bookmark: $b
echo $b >> ~/.ssh/scripts/bookmarks.sh
source ~/.ssh/scripts/bookmarks.sh
echo $b >> $HOME/.uber/scripts/bookmarks.sh
source $HOME/.uber/scripts/bookmarks.sh
fi
}

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/git-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ git-init() {
git flow init -d 1>/dev/null

# copy the default gitignore and gitattributes
cp ~/.uber/git/gitignore .gitignore 1>/dev/null
cp ~/.uber/git/gitattributes .gitattributes 1>/dev/null
cp $HOME/.uber/git/gitignore .gitignore 1>/dev/null
cp $HOME/.uber/git/gitattributes .gitattributes 1>/dev/null

# add the newly created gitignore and gitattributes
git add . 1>/dev/null
Expand Down
11 changes: 6 additions & 5 deletions src/scripts/remove-bookmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ fi
remove-bookmark() {
local b=$1
local r=
local scripts_path=$HOME/.uber/scripts

if ! test -z "$b"; then
r=$(command grep -s -m 1 ^$b ~/.ssh/scripts/bookmarks.sh)
r=$(command grep -s -m 1 ^$b $scripts_path/bookmarks.sh)
elif test -z "$2"; then
r=$(command grep -s -m 1 \"$PWD\"$ ~/.ssh/scripts/bookmarks.sh)
r=$(command grep -s -m 1 \"$PWD\"$ $scripts_path/bookmarks.sh)
fi

if ! test -z "$r"; then
test -z "$2" && ( echo Removing bookmark: $r )

command grep -s -v $r ~/.ssh/scripts/bookmarks.sh >> ~/.ssh/scripts/bookmarks1.sh
mv -f ~/.ssh/scripts/bookmarks1.sh ~/.ssh/scripts/bookmarks.sh
command grep -s -v $r $scripts_path/bookmarks.sh >> $scripts_path/bookmarks1.sh
mv -f $scripts_path/bookmarks1.sh $scripts_path/bookmarks.sh

source ~/.ssh/scripts/bookmarks.sh
source $scripts_path/bookmarks.sh
else
test -z "$2" && ( echo No bookmark was declared for the specified title or address. )
fi
Expand Down
4 changes: 1 addition & 3 deletions src/scripts/set-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,4 @@ function set-prompt() {
# use the git prompt with the prompt arrow
export PROMPT_COMMAND='__posh_git_ps1 "\n\u@\h : \w\n" "$(emit-prompt-arrow)"'
fi
}

set-prompt
}
2 changes: 1 addition & 1 deletion src/scripts/show-boomarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if test -n "${UBER_DEBUG+1}"; then
fi

function show-bookmarks() {
cat ~/.ssh/scripts/bookmarks.sh
cat $HOME/.uber/scripts/bookmarks.sh
}

function lbm() {
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/show-history.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'show-history'
fi

function show-history() {
history $@
}
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/show-profile.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'show-profile'
fi

function show-profile() {
history | awk '{print \$2}' | awk 'BEGIN{FS=\"|\"}{print \$1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr
}
Expand Down
8 changes: 6 additions & 2 deletions src/scripts/source-uname.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env bash

if test -n "${UBER_DEBUG+1}"; then
echo 'source-uname'
fi

function source-uname() {
local unamepath=~/.ssh/scripts/$(uname)
local unamepath=$HOME/.uber/scripts/$(uname)

if test -d $unamepath; then
for f in $unamepath/*; do
source $f
Expand Down
4 changes: 2 additions & 2 deletions template/bash_profile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

if test -f ~/.uber/bashrc; then
source ~/.uber/bashrc
if test -f $HOME/.uber/bashrc; then
source $HOME/.uber/bashrc
fi

0 comments on commit 5064c06

Please sign in to comment.