From 5064c0602f597f8add5565fa7b9af67d735db540 Mon Sep 17 00:00:00 2001 From: Deavon McCaffery Date: Mon, 14 Nov 2016 10:54:26 -0800 Subject: [PATCH] feat(nvm): add support for nvm in place of direct node install --- README.md | 12 +++++------ install.sh | 33 ++++++++++++++++++++++-------- src/bashrc | 12 +++++++---- src/scripts/Darwin/add-ssh-keys.sh | 13 ++++++++++++ src/scripts/Darwin/flush-dns.sh | 4 +++- src/scripts/Darwin/git-extras.sh | 2 ++ src/scripts/Darwin/hide-all.sh | 3 +++ src/scripts/Darwin/set-nvm.sh | 24 ++++++++++++++++++++++ src/scripts/Darwin/show-all.sh | 2 ++ src/scripts/Darwin/themes.sh | 4 +++- src/scripts/add-bookmark.sh | 4 ++-- src/scripts/git-extensions.sh | 4 ++-- src/scripts/remove-bookmark.sh | 11 +++++----- src/scripts/set-prompt.sh | 4 +--- src/scripts/show-boomarks.sh | 2 +- src/scripts/show-history.sh | 4 ++++ src/scripts/show-profile.sh | 4 ++++ src/scripts/source-uname.sh | 8 ++++++-- template/bash_profile | 4 ++-- 19 files changed, 116 insertions(+), 38 deletions(-) create mode 100644 src/scripts/Darwin/add-ssh-keys.sh create mode 100644 src/scripts/Darwin/set-nvm.sh diff --git a/README.md b/README.md index 7f9572c..4992f7b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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): @@ -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 diff --git a/install.sh b/install.sh index 2cafc0e..3c5da41 100755 --- a/install.sh +++ b/install.sh @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/bashrc b/src/bashrc index 7b4c400..36ecff0 100644 --- a/src/bashrc +++ b/src/bashrc @@ -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' diff --git a/src/scripts/Darwin/add-ssh-keys.sh b/src/scripts/Darwin/add-ssh-keys.sh new file mode 100644 index 0000000..05f69f6 --- /dev/null +++ b/src/scripts/Darwin/add-ssh-keys.sh @@ -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 \ No newline at end of file diff --git a/src/scripts/Darwin/flush-dns.sh b/src/scripts/Darwin/flush-dns.sh index 1ec3d66..1baeffd 100644 --- a/src/scripts/Darwin/flush-dns.sh +++ b/src/scripts/Darwin/flush-dns.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + if test -n "${UBER_DEBUG+1}"; then echo 'flush-dns' fi @@ -9,4 +11,4 @@ function flush-dns() { function flushdns() { flush-dns -} \ No newline at end of file +} diff --git a/src/scripts/Darwin/git-extras.sh b/src/scripts/Darwin/git-extras.sh index 3d2cf35..804b856 100644 --- a/src/scripts/Darwin/git-extras.sh +++ b/src/scripts/Darwin/git-extras.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + if test -n "${UBER_DEBUG+1}"; then echo 'git-extras' fi diff --git a/src/scripts/Darwin/hide-all.sh b/src/scripts/Darwin/hide-all.sh index c871aec..684ef24 100644 --- a/src/scripts/Darwin/hide-all.sh +++ b/src/scripts/Darwin/hide-all.sh @@ -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 diff --git a/src/scripts/Darwin/set-nvm.sh b/src/scripts/Darwin/set-nvm.sh new file mode 100644 index 0000000..19d1570 --- /dev/null +++ b/src/scripts/Darwin/set-nvm.sh @@ -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 \ No newline at end of file diff --git a/src/scripts/Darwin/show-all.sh b/src/scripts/Darwin/show-all.sh index 34754f7..331852d 100644 --- a/src/scripts/Darwin/show-all.sh +++ b/src/scripts/Darwin/show-all.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + if test -n "${UBER_DEBUG+1}"; then echo 'show-all' fi diff --git a/src/scripts/Darwin/themes.sh b/src/scripts/Darwin/themes.sh index 1a11769..c418e23 100644 --- a/src/scripts/Darwin/themes.sh +++ b/src/scripts/Darwin/themes.sh @@ -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 } \ No newline at end of file diff --git a/src/scripts/add-bookmark.sh b/src/scripts/add-bookmark.sh index 49a677a..58c37d0 100644 --- a/src/scripts/add-bookmark.sh +++ b/src/scripts/add-bookmark.sh @@ -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 } diff --git a/src/scripts/git-extensions.sh b/src/scripts/git-extensions.sh index 9842414..99a55ea 100644 --- a/src/scripts/git-extensions.sh +++ b/src/scripts/git-extensions.sh @@ -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 diff --git a/src/scripts/remove-bookmark.sh b/src/scripts/remove-bookmark.sh index f9d616c..bca2d31 100644 --- a/src/scripts/remove-bookmark.sh +++ b/src/scripts/remove-bookmark.sh @@ -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 diff --git a/src/scripts/set-prompt.sh b/src/scripts/set-prompt.sh index b935b69..8372a91 100644 --- a/src/scripts/set-prompt.sh +++ b/src/scripts/set-prompt.sh @@ -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 \ No newline at end of file +} \ No newline at end of file diff --git a/src/scripts/show-boomarks.sh b/src/scripts/show-boomarks.sh index db31a75..731b7ca 100644 --- a/src/scripts/show-boomarks.sh +++ b/src/scripts/show-boomarks.sh @@ -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() { diff --git a/src/scripts/show-history.sh b/src/scripts/show-history.sh index f2c508e..7f862f8 100644 --- a/src/scripts/show-history.sh +++ b/src/scripts/show-history.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +if test -n "${UBER_DEBUG+1}"; then + echo 'show-history' +fi + function show-history() { history $@ } diff --git a/src/scripts/show-profile.sh b/src/scripts/show-profile.sh index 865208f..479765e 100644 --- a/src/scripts/show-profile.sh +++ b/src/scripts/show-profile.sh @@ -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 } diff --git a/src/scripts/source-uname.sh b/src/scripts/source-uname.sh index 5060b06..8042cde 100644 --- a/src/scripts/source-uname.sh +++ b/src/scripts/source-uname.sh @@ -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 diff --git a/template/bash_profile b/template/bash_profile index c3423d0..8990082 100644 --- a/template/bash_profile +++ b/template/bash_profile @@ -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 \ No newline at end of file