Added readme, updated global functions and pathmunge to work properly

This commit is contained in:
Chris Blackburn 2012-01-26 17:19:11 -06:00
commit 278616e952
3 changed files with 154 additions and 68 deletions

View file

@ -1,86 +1,85 @@
# Add your public SSH key to a remote host
function add_ssh_key_to_host {
if [[ $# -lt 1 ]]; then
echo_warn "Usage: add_ssh_key_to_host [user@]HOSTNAME"
return
fi
if [[ -r ~/.ssh/id_dsa.pub ]]; then
cat ~/.ssh/id_dsa.pub | ssh $1 "cat >> .ssh/authorized_keys"
elif [[ -r ~/.ssh/id_rsa.pub ]]; then
cat ~/.ssh/id_rsa.pub | ssh $1 "cat >> .ssh/authorized_keys"
function load_omzs_on_login {
profile_file="$HOME/.zshrc"
if [[ -f "${profile_file}" ]] &&
! grep '$ZSH/oh-my-zsh.sh' "$profile_file" >/dev/null 2>&1
then
echo '[[ -r $ZSH/oh-my-zsh.sh ]] && . $ZSH/oh-my-zsh.sh' >> "$profile_file"
echo "- oh-my-zsh will now load on login."
else
echo "- oh-my-zsh is already setup to load on login."
fi
return 0
}
# Propagate your entire environment system to a remote host
function propagate_env_to_host {
function load_omzs_on_alias {
profile_file="$HOME/.zshrc"
if [[ -f "${profile_file}" ]] &&
! grep 'alias omzs=". $ZSH/oh-my-zsh.sh"' "$profile_file" >/dev/null 2>&1
then
echo 'alias omzs=". $ZSH/oh-my-zsh.sh"' >> "$profile_file"
echo "- oh-my-zsh will now load when you execute 'omzs'."
else
echo "- oh-my-zsh is already setup to load using the 'omzs' alias."
fi
return 0
}
# Propagate your environment system to a remote host
function propagate_omzs_to_host {
if [[ $# -lt 1 ]]; then
echo_warn "Usage: propagate_env_to_host [user@]HOSTNAME"
echo "Usage: propagate_omzs_to_host [user@]HOSTNAME"
return
fi
host=$1
shift 1
ENVFILE=$HOME/env.tar.gz
OH_MY_ZSH=$HOME/env.tar.gz
PWD=`pwd`
cd $HOME
echo_info "Compressing local environment..."
tar cfvz $ENVFILE .env/ &> /dev/null
echo_info "Copying environment to $host..."
scp $ENVFILE $host:
if [[ $? != 0 ]]; then echo "Copy failed!"; return; fi
echo_info "Installing environment on $host..."
ssh $host "rm -rf ~/.env/ && gunzip < env.tar.gz |tar xfv -" &> /dev/null
echo_warn "Don't forget to add this your .bashrc file:"
echo_warn 'if [[ -n "$PS1" ]]; then'
echo_warn ' [[ -r $HOME/.env/source.sh ]] && . $HOME/.env/source.sh'
echo_warn 'fi'
echo "- compressing local environment..."
tar cfvz $OH_MY_ZSH .oh-my-zsh/ &> /dev/null
echo "- copying environment to $host..."
scp $OH_MY_ZSH $host:
if [[ $? != 0 ]]; then echo "> remote copy failed [scp $OH_MY_ZSH $host]!"; return; fi
echo "- installing environment on $host..."
ssh $host "rm -rf ~/.oh-my-zsh/ && gunzip < env.tar.gz |tar xfv -" &> /dev/null
echo "- done. don't forget to run 'load_omzs_on_login' or 'load_omzs_on_alias'"
cd $PWD
}
function _stub_new_host_environment {
mkdir -p $1
touch "$1/env.sh"
touch "$1/functions.sh"
if [[ ! -f "$1/alias.sh" ]]; then
echo "# Add your host specific aliases here:\n# Example: alias home='cd \$HOME' " >> "$1/alias.sh"
fi
if [[ ! -f "$1/path.sh" ]]; then
echo "# Add paths like this:\n# pathmunge \"/Developer/usr/bin\"" >> "$1/path.sh"
fi
}
# Configure environment settings for your local machine.
function configthis.env {
function config_omzs_for_this_host {
DIR="$DOT_ENV_PATH/host/$HOSTNAME"
mkdir -p "$DIR"
touch "$DIR/env.sh"
touch "$DIR/functions.sh"
if [[ ! -f "$DIR/alias.sh" ]]; then
echo "# Add your specific aliases here:\n# Example: alias home='cd \$HOME' " >> "$DIR/alias.sh"
fi
if [[ ! -f "$DIR/prompt.sh" ]]; then
echo "# Define your prompt here:\n# Example: PS1=\$BLUE\u@\H\$NO_COLOR " >> "$DIR/prompt.sh"
fi
if [[ ! -f "$DIR/path.sh" ]]; then
echo "# Add paths like this:\n# pathmunge \"/Developer/usr/bin\"" >> "$DIR/path.sh"
fi
_stub_new_host_environment $DIR
cd "$DIR"
echo_info "Edit these files to customize your local environment."
echo "- edit these files to customize your local environment."
ls -1AtF
}
# Configure environment settings for a specified HOSTNAME
function confighost.env {
function config_omzs_for_host {
if [[ $# -lt 1 ]]; then
echo_warn "Usage: confighost.env HOSTNAME"
echo_warn "Usage: config_omzs_for_host HOSTNAME"
return
fi
host=$1
shift 1
DIR="$DOT_ENV_PATH/host/$host"
mkdir -p "$DIR"
touch "$DIR/env.sh"
touch "$DIR/functions.sh"
if [[ ! -f "$DIR/alias.sh" ]]; then
echo "# Add your host specific aliases here:\n# Example: alias home='cd \$HOME' " >> "$DIR/alias.sh"
fi
if [[ ! -f "$DIR/prompt.sh" ]]; then
echo "# Define your prompt here:\n# Example: PS1=\$BLUE\u@\H\$NO_COLOR " >> "$DIR/prompt.sh"
fi
if [[ ! -f "$DIR/path.sh" ]]; then
echo "# Add paths like this:\n# pathmunge \"/Developer/usr/bin\"" >> "$DIR/path.sh"
fi
_stub_new_host_environment $DIR
cd "$DIR"
echo_info "Edit these files to customize your [$host] environment."
echo_info "When you are finished run 'propagate_env_to_host $host'."
echo "- edit these files to customize your [$host] environment."
echo "- when you are finished run 'propagate_omzs_to_host $host'."
ls -1AtF
}