Skip to content

Commit

Permalink
Added an awesome auto_reload PROMPT command that watches bashrc for c…
Browse files Browse the repository at this point in the history
…hanges, and reloads automatically

More reorganizing
vims not needed any more
Even more re-organizing
Working on git config setup
control rake task with env variable
Moved ruby dotfiles into symlinked files
made option OVERWRITE_ALL
  • Loading branch information
ndbroadbent committed Jan 15, 2012
1 parent acc445b commit b4d304c
Show file tree
Hide file tree
Showing 93 changed files with 139 additions and 178 deletions.
9 changes: 4 additions & 5 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
h3. Setup scripts and configuration for Ubuntu development machine

* Base packages
* Package installation
* Git & SSH setup
* Well-honed .bashrc
* RVM & ruby 1.9.2
* gedit tweaked to perfection for Ruby on Rails
* .bashrc with a lot of useful aliases / functions
* RVM
* Gnome themes, icons & conky

h2. Run the following command to set up a freshly installed machine:
h2. Run the following command to set up a new machine

bc. sudo apt-get install -ym git-core && git clone https://github.com/ndbroadbent/ubuntu_config.git /tmp/ubuntu_config && cd /tmp/ubuntu_config && ./dev_machine_setup.sh

64 changes: 64 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'rake'

desc "Hook our dotfiles into system-standard positions."
task :install do
# Install symlinks
linkables = Dir.glob('*/**{.symlink}')

skip_all = false
overwrite_all = ENV['OVERWRITE_ALL']
backup_all = false

linkables.each do |linkable|
overwrite = false
backup = false

file = linkable.split('/').last.split('.symlink').last
target = "#{ENV["HOME"]}/.#{file}"

if File.exists?(target) || File.symlink?(target)
unless skip_all || overwrite_all || backup_all
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all"
case STDIN.gets.chomp
when 'o' then overwrite = true
when 'b' then backup = true
when 'O' then overwrite_all = true
when 'B' then backup_all = true
when 'S' then skip_all = true
when 's' then next
end
end
FileUtils.rm_rf(target) if overwrite || overwrite_all
`mv "$HOME/.#{file}" "$HOME/.#{file}.backup"` if backup || backup_all
end
`ln -s "$PWD/#{linkable}" "#{target}"`
end

# Run other install tasks
%w(bashrc git_config).each do |script|
puts "== Running setup/#{script}.sh"
%x[./setup/#{script}.sh]
end
end

task :uninstall do

Dir.glob('**/*.symlink').each do |linkable|

file = linkable.split('/').last.split('.symlink').last
target = "#{ENV["HOME"]}/.#{file}"

# Remove all symlinks created during installation
if File.symlink?(target)
FileUtils.rm(target)
end

# Replace any backups made during installation
if File.exists?("#{ENV["HOME"]}/.#{file}.backup")
`mv "$HOME/.#{file}.backup" "$HOME/.#{file}"`
end

end
end

task :default => 'install'
1 change: 0 additions & 1 deletion assets/bashrc/aliases.sh → bashrc/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ alias ak='ack-grep'
alias aka='ack-grep -a'
alias aki='ack-grep -i'
alias psg='ps ax | grep'
alias vims='vim -c start' # open vim in 'insert' mode
alias e="ge geany"
alias sbrc="source ~/.bashrc"

Expand Down
14 changes: 14 additions & 0 deletions bashrc/auto_reload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Reloads bashrc if anything changes in a monitored directory
auto_reload_bashrc() {
local recent_change="$(bashrc_last_modified)"
if [ "$BASHRC_LAST_UPDATED" != "$recent_change" ]; then
export BASHRC_LAST_UPDATED="$recent_change"
source $HOME/.bashrc
fi
}

bashrc_last_modified() {
find "$DOTFILES_PATH/bashrc" -type f -printf '%T@ %p\n' | sort -n | tail -1
}

PROMPT_COMMAND="auto_reload_bashrc; $PROMPT_COMMAND"
1 change: 0 additions & 1 deletion assets/bashrc/crossroads.sh → bashrc/crossroads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ restart_bamboo() {
ssh [email protected] "/etc/init.d/bamboo restart"
echo "===== Restarted. Bamboo agents will automatically restart."
}

2 changes: 1 addition & 1 deletion assets/bashrc/default.sh → bashrc/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ shopt -s checkwinsize
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt
case "$TERM" in
xterm-color) color_prompt=yes;;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions dev_machine_setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
. _shared.sh
. setup/_shared.sh
# This bash script will set up (or update) your development environment for Ubuntu (v=>9.10)

scripts=""
Expand All @@ -17,13 +17,13 @@ echo -e "

# Prerequisites
# -------------------------------------
# Requires root permissions
# Requires root permissions (requests password here)
sudo true

# '--all' flag installs everything
if [ "$1" = "--all" ]; then
echo "== Setting up default environment..."
scripts="packages dropbox skype keepass2 netrc rc git_config ruby_dotfiles
scripts="packages dropbox skype keepass2 netrc rc git_config
gimp gedit vim gnome conky startup tomate apt-install rvm "
prompt_for_git
prompt_for_netrc
Expand Down Expand Up @@ -77,7 +77,7 @@ for script in $scripts; do
sudo apt-get install -ym $apt_packages | grep -v "is already the newest version"
sudo apt-get autoremove -ym
else
. $script\_setup.sh
. setup/$script.sh
fi
done

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
iPhone="root@nathans-iphone"

cat assets/iphone_bashrc.sh | \
cat ./iphone_bashrc.sh | \
ssh $iPhone 'cat > /var/root/.bashrc && \
if ! (grep "source /var/root/.bashrc" /etc/profile); then \
echo "source /var/root/.bashrc" >> /etc/profile; \
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions keepass2_setup.sh

This file was deleted.

11 changes: 0 additions & 11 deletions netrc_setup.sh

This file was deleted.

35 changes: 0 additions & 35 deletions other_setup_scripts/reddit_wallpapers_setup.sh

This file was deleted.

3 changes: 0 additions & 3 deletions assets/Gemfile → ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# -----------------------------
source :rubygems

# Colorize output
gem 'wirble'

# Colorize and format objects
gem 'awesome_print'

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions ruby/autotest.symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Autotest.add_hook :initialize do |at|
%w{.svn .hg .git vendor}.each {|exception| at.add_exception(exception)}
end
1 change: 1 addition & 0 deletions ruby/caprc.symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'capistrano_colors'
1 change: 1 addition & 0 deletions ruby/gemrc.symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem: --no-ri --no-rdoc
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ruby/rdebugrc.symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set autoeval
set autolist
set autoreload
2 changes: 2 additions & 0 deletions ruby/rvmrc.symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export rvm_path="$HOME/.rvm"
rvm_trust_rvmrcs_flag=1
29 changes: 0 additions & 29 deletions ruby_dotfiles_setup.sh

This file was deleted.

1 change: 1 addition & 0 deletions _shared.sh → setup/_shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if [ -z "$_shared_functions" ]; then
read -p "===== [Git config] Please enter your name: " git_name
read -p "===== [Git config] Please enter your email: " git_email
read -p "===== [Git config] Please enter your github username: " github_user
read -p "===== [Git config] Please enter your github API token: " github_token
}

function prompt_for_netrc() {
Expand Down
29 changes: 10 additions & 19 deletions rc_setup.sh → setup/bashrc.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/bash
echo "== Installing ~/.bashrc & other related dot files..."
echo "== Installing ~/.bashrc ..."
this_dir=$(pwd)

IFS=" "

bashrc_parts="default prompt aliases functions ruby_on_rails crossroads"
rc_files="inputrc ackrc irbrc livereload"
bashrc_parts="default prompt aliases functions auto_reload ruby_on_rails crossroads"

cat /dev/null > ~/.bashrc

Expand All @@ -15,33 +14,25 @@ for part in $bashrc_parts; do
cat assets/bashrc/$part.sh >> ~/.bashrc
else
# Source bashrc from parts
echo "source '$this_dir/assets/bashrc/$part.sh'" >> ~/.bashrc
echo "source '$this_dir/bashrc/$part.sh'" >> ~/.bashrc
fi
done

# Add scm_breeze
echo '[[ -s "$HOME/.scm_breeze/scm_breeze.sh" ]] && . "$HOME/.scm_breeze/scm_breeze.sh"' >> ~/.bashrc

# Export ubuntu_config_path
echo "export UBUNTU_CONFIG_PATH=\"$this_dir\"" >> ~/.bashrc

# Append dynamic update command
# Append dynamic footer
cat >> ~/.bashrc <<EOF
# Export path of dotfiles repo
export DOTFILES_PATH="$this_dir"
# Set bashrc autoreload variable at start
export BASHRC_LAST_UPDATED="\$(bashrc_last_modified)"
# Update this file from GitHub
alias pull_bashrc='cd $this_dir && git pull origin master && . bashrc_setup.sh && cd -'
EOF

for rc in $rc_files; do
rm -f ~/.$rc
if [ "$1" = "copy" ]; then
# Copy other *rc files
cp -f "$this_dir/assets/$rc" "$HOME/.$rc"
else
# Symlink other *rc files
ln -fs "$this_dir/assets/$rc" "$HOME/.$rc"
fi
done


# If run from dev_machine_setup, we cannot update current shell.
if ! [[ "$0" =~ "dev_machine_setup.sh" ]]; then
Expand Down
5 changes: 3 additions & 2 deletions conky_setup.sh → setup/conky.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
. _shared.sh
if [ "$(basename $(pwd))" = "setup" ]; then . _shared.sh; else . setup/_shared.sh; fi;

echo "== Setting up conky..."

# Queue or install apt packages
Expand All @@ -22,7 +23,7 @@ fi

# Copy conky config files.
sudo rm -rf ~/.conkycolors
cp -rf assets/conkycolors ~/.conkycolors
cp -rf conky/conkycolors ~/.conkycolors

# Set home directory placeholder
sed "s%@HOME@%$HOME%g" -i ~/.conkycolors/conkyrc
Expand Down
2 changes: 1 addition & 1 deletion dropbox_setup.sh → setup/dropbox.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
. _shared.sh
if [ "$(basename $(pwd))" = "setup" ]; then . _shared.sh; else . setup/_shared.sh; fi;
# Install Dropbox Nautilus Extension
# -------------------------------------------
echo "== Installing dropbox nautilus extension..."
Expand Down
2 changes: 1 addition & 1 deletion dropbox_links_setup.sh → setup/dropbox_links.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
. _shared.sh
if [ "$(basename $(pwd))" = "setup" ]; then . _shared.sh; else . setup/_shared.sh; fi;
# Create symlinks for Dropbox synced directories
# ----------------------------------------------
echo "== Creating Dropbox symlinks..."
Expand Down
2 changes: 1 addition & 1 deletion gedit_setup.sh → setup/gedit.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
. _shared.sh
if [ "$(basename $(pwd))" = "setup" ]; then . _shared.sh; else . setup/_shared.sh; fi;
# Sets up gedit for RoR development.
# -------------------------------------------
echo "== Setting up gedit plugins, settings and assets (RoR colors, etc)..."
Expand Down
2 changes: 1 addition & 1 deletion gimp_setup.sh → setup/gimp.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
. _shared.sh
if [ "$(basename $(pwd))" = "setup" ]; then . _shared.sh; else . setup/_shared.sh; fi;
# Install latest version of Gimp
# -------------------------------------------
echo "== Installing latest version of gimp from ppa..."
Expand Down
Loading

0 comments on commit b4d304c

Please sign in to comment.