Skip to content

Commit

Permalink
Use cache file (for expensive calls)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed May 17, 2017
1 parent d8ea600 commit 946ce7f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.cache.sh
system/.custom
bin/subl
3 changes: 2 additions & 1 deletion install.sh
Expand Up @@ -2,8 +2,9 @@

# Get current dir (so run this script from anywhere)

export DOTFILES_DIR EXTRA_DIR
export DOTFILES_DIR DOTFILES_CACHE EXTRA_DIR
DOTFILES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DOTFILES_CACHE="$DOTFILES_DIR/.cache.sh"
EXTRA_DIR="$HOME/.extra"

# Common functions
Expand Down
3 changes: 3 additions & 0 deletions install/brew.sh
Expand Up @@ -47,3 +47,6 @@ apps=(
)

brew install "${apps[@]}"

export BREW_PREFIX_COREUTILS=`brew --prefix coreutils`
set-config "BREW_PREFIX_COREUTILS" "$BREW_PREFIX_COREUTILS" "$DOTFILES_CACHE"
4 changes: 4 additions & 0 deletions install/npm.sh
Expand Up @@ -4,6 +4,10 @@ if ! is-executable brew -o ! is-executable git; then
fi

brew install nvm

export BREW_PREFIX_NVM=`brew --prefix nvm`
set-config "BREW_PREFIX_NVM" "$BREW_PREFIX_NVM" "$DOTFILES_CACHE"

. "${DOTFILES_DIR}/system/.nvm"
nvm install 6

Expand Down
5 changes: 5 additions & 0 deletions runcom/.bash_profile
Expand Up @@ -25,6 +25,11 @@ else
return
fi

# Read cache

DOTFILES_CACHE="$DOTFILES_DIR/.cache.sh"
[ -f "$DOTFILES_CACHE" ] && . "$DOTFILES_CACHE"

# Finally we can source the dotfiles (order matters)

for DOTFILE in "$DOTFILES_DIR"/system/.{function,function_*,path,env,alias,completion,grep,prompt,nvm,rvm,custom}; do
Expand Down
14 changes: 14 additions & 0 deletions system/.function
Expand Up @@ -29,6 +29,20 @@ prepend-path() {
[ -d $1 ] && PATH="$1:$PATH"
}

# Update config file

set-config() {
local KEY="$1"
local VALUE="$2"
local FILE="$3"
touch "$FILE"
if grep -q "$1=" "$FILE"; then
sed "s@$KEY=.*@$KEY=\"$VALUE\"@" -i "$FILE"
else
echo "export $KEY=$VALUE" >> "$FILE"
fi
}

# Show 256 TERM colors

colors() {
Expand Down
2 changes: 1 addition & 1 deletion system/.nvm
@@ -1,2 +1,2 @@
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
source "$BREW_PREFIX_NVM/nvm.sh"
2 changes: 1 addition & 1 deletion system/.path
Expand Up @@ -8,7 +8,7 @@ is-executable getconf && PATH=$(`command -v getconf` PATH)
prepend-path "/bin"
prepend-path "/usr/bin"
prepend-path "/usr/local/bin"
is-executable brew && prepend-path "$(brew --prefix coreutils)/libexec/gnubin"
is-executable brew && prepend-path "$BREW_PREFIX_COREUTILS/libexec/gnubin"
prepend-path "$DOTFILES_DIR/bin"
prepend-path "$HOME/bin"
prepend-path "/sbin"
Expand Down

0 comments on commit 946ce7f

Please sign in to comment.