Skip to content

Commit

Permalink
Remove explicit new line addition
Browse files Browse the repository at this point in the history
Relies on `append_to_zshrc` to add a new line after the appended text.

`append_to_zshrc()` will accept a second argument (`boolean`) to skip the new
line before the appended text, by default a new line will always be prepended.
  • Loading branch information
kenyonj committed Oct 10, 2014
1 parent 4e7f598 commit 3897ad8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion common-components/check-home-bin
Expand Up @@ -6,4 +6,4 @@ if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi

append_to_zshrc 'export PATH="$HOME/.bin:$PATH"\n'
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
4 changes: 2 additions & 2 deletions common-components/rbenv
Expand Up @@ -2,8 +2,8 @@ if [[ ! -d "$HOME/.rbenv" ]]; then
fancy_echo "Installing rbenv, to change Ruby versions ..."
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

append_to_zshrc 'export PATH="$HOME/.rbenv/bin:$PATH"\n'
append_to_zshrc 'eval "$(rbenv init - zsh --no-rehash)"\n'
append_to_zshrc 'export PATH="$HOME/.rbenv/bin:$PATH"'
append_to_zshrc 'eval "$(rbenv init - zsh --no-rehash)"' 1

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"
Expand Down
7 changes: 6 additions & 1 deletion common-components/shared-functions
Expand Up @@ -4,6 +4,7 @@ fancy_echo() {

append_to_zshrc() {
local text="$1" zshrc
local skip_new_line="$2"

if [[ -w "$HOME/.zshrc.local" ]]; then
zshrc="$HOME/.zshrc.local"
Expand All @@ -12,6 +13,10 @@ append_to_zshrc() {
fi

if ! grep -Fqs "$text" "$zshrc"; then
printf "%s\n" "$text" >> "$zshrc"
if (( skip_new_line )); then
printf "%s\n" "$text" >> "$zshrc"
else
printf "\n%s\n" "$text" >> "$zshrc"
fi
fi
}
13 changes: 9 additions & 4 deletions linux
Expand Up @@ -4,6 +4,7 @@ fancy_echo() {

append_to_zshrc() {
local text="$1" zshrc
local skip_new_line="$2"

if [[ -w "$HOME/.zshrc.local" ]]; then
zshrc="$HOME/.zshrc.local"
Expand All @@ -12,7 +13,11 @@ append_to_zshrc() {
fi

if ! grep -Fqs "$text" "$zshrc"; then
printf "%s\n" "$text" >> "$zshrc"
if (( skip_new_line )); then
printf "%s\n" "$text" >> "$zshrc"
else
printf "\n%s\n" "$text" >> "$zshrc"
fi
fi
}
### end common-components/shared-functions
Expand Down Expand Up @@ -40,7 +45,7 @@ if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi

append_to_zshrc 'export PATH="$HOME/.bin:$PATH"\n'
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
### end common-components/check-home-bin

if ! grep -qiE 'wheezy|jessie|precise|trusty' /etc/os-release; then
Expand Down Expand Up @@ -133,8 +138,8 @@ if [[ ! -d "$HOME/.rbenv" ]]; then
fancy_echo "Installing rbenv, to change Ruby versions ..."
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

append_to_zshrc 'export PATH="$HOME/.rbenv/bin:$PATH"\n'
append_to_zshrc 'eval "$(rbenv init - zsh --no-rehash)"\n'
append_to_zshrc 'export PATH="$HOME/.rbenv/bin:$PATH"'
append_to_zshrc 'eval "$(rbenv init - zsh --no-rehash)"' 1

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"
Expand Down
21 changes: 13 additions & 8 deletions mac
Expand Up @@ -4,6 +4,7 @@ fancy_echo() {

append_to_zshrc() {
local text="$1" zshrc
local skip_new_line="$2"

if [[ -w "$HOME/.zshrc.local" ]]; then
zshrc="$HOME/.zshrc.local"
Expand All @@ -12,7 +13,11 @@ append_to_zshrc() {
fi

if ! grep -Fqs "$text" "$zshrc"; then
printf "%s\n" "$text" >> "$zshrc"
if (( skip_new_line )); then
printf "%s\n" "$text" >> "$zshrc"
else
printf "\n%s\n" "$text" >> "$zshrc"
fi
fi
}
### end common-components/shared-functions
Expand Down Expand Up @@ -40,7 +45,7 @@ if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi

append_to_zshrc 'export PATH="$HOME/.bin:$PATH"\n'
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
### end common-components/check-home-bin

fancy_echo "Changing your shell to zsh ..."
Expand Down Expand Up @@ -99,8 +104,8 @@ if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew, a good OS X package manager ..."
ruby <(curl -fsS https://raw.githubusercontent.com/Homebrew/install/master/install)

append_to_zshrc '\n# recommended by brew doctor\n'
append_to_zshrc 'export PATH="/usr/local/bin:$PATH"\n'
append_to_zshrc '# recommended by brew doctor'
append_to_zshrc 'export PATH="/usr/local/bin:$PATH"' 1
export PATH="/usr/local/bin:$PATH"
else
fancy_echo "Homebrew already installed. Skipping ..."
Expand Down Expand Up @@ -148,8 +153,8 @@ node_version="0.10"
fancy_echo "Installing NVM, Node.js, and NPM, for running apps and installing JavaScript packages ..."
brew_install_or_upgrade 'nvm'

append_to_zshrc 'export PATH="$PATH:/usr/local/lib/node_modules"\n'
append_to_zshrc 'source $(brew --prefix nvm)/nvm.sh\n'
append_to_zshrc 'export PATH="$PATH:/usr/local/lib/node_modules"'
append_to_zshrc 'source $(brew --prefix nvm)/nvm.sh' 1

source $(brew --prefix nvm)/nvm.sh
nvm install "$node_version"
Expand All @@ -166,8 +171,8 @@ if [[ ! -d "$HOME/.rbenv" ]]; then
fancy_echo "Installing rbenv, to change Ruby versions ..."
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

append_to_zshrc 'export PATH="$HOME/.rbenv/bin:$PATH"\n'
append_to_zshrc 'eval "$(rbenv init - zsh --no-rehash)"\n'
append_to_zshrc 'export PATH="$HOME/.rbenv/bin:$PATH"'
append_to_zshrc 'eval "$(rbenv init - zsh --no-rehash)"' 1

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"
Expand Down
4 changes: 2 additions & 2 deletions mac-components/homebrew
Expand Up @@ -2,8 +2,8 @@ if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew, a good OS X package manager ..."
ruby <(curl -fsS https://raw.githubusercontent.com/Homebrew/install/master/install)

append_to_zshrc '\n# recommended by brew doctor\n'
append_to_zshrc 'export PATH="/usr/local/bin:$PATH"\n'
append_to_zshrc '# recommended by brew doctor'
append_to_zshrc 'export PATH="/usr/local/bin:$PATH"' 1
export PATH="/usr/local/bin:$PATH"
else
fancy_echo "Homebrew already installed. Skipping ..."
Expand Down
4 changes: 2 additions & 2 deletions mac-components/packages
Expand Up @@ -36,8 +36,8 @@ node_version="0.10"
fancy_echo "Installing NVM, Node.js, and NPM, for running apps and installing JavaScript packages ..."
brew_install_or_upgrade 'nvm'

append_to_zshrc 'export PATH="$PATH:/usr/local/lib/node_modules"\n'
append_to_zshrc 'source $(brew --prefix nvm)/nvm.sh\n'
append_to_zshrc 'export PATH="$PATH:/usr/local/lib/node_modules"'
append_to_zshrc 'source $(brew --prefix nvm)/nvm.sh' 1

source $(brew --prefix nvm)/nvm.sh
nvm install "$node_version"
Expand Down

0 comments on commit 3897ad8

Please sign in to comment.