Created
December 4, 2009 00:20
-
-
Save jfro/248714 to your computer and use it in GitHub Desktop.
A copy of my zshrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export LC_ALL="en_US.UTF-8" # Use British English... | |
export LC_ALL="en_US.UTF-8" # Use British English... | |
export LANG="en_US.UTF-8" # ...as default language. | |
export TZ="America/New_York" # Force our time zone this location. | |
# this happened to work on iMac just because I had X11 installed | |
if [[ "x$DISPLAY" == "x" ]]; then | |
export EDITOR="vim" | |
else | |
export EDITOR="mate -w" | |
fi | |
export PAGE="less" | |
export FULL_NAME="My Name" | |
export SHORTNAME="jerome" | |
# check if we're at work or at home | |
AMB_CHECK=`echo $HOST | awk -F . '{print $(NF-1)"\."$NF}'` | |
if [[ $AMB_CHECK == "example.com" ]]; then | |
export COMPANY="Example Inc." | |
export EMAIL="someone@example.com" | |
MYSERVERS=("work1.example.com" "work2.example.com" "work3.example.com") | |
else | |
export COMPANY="My Other Company" | |
export EMAIL="jerome@example.com" | |
MYSERVERS=("lonely.example.com") | |
fi | |
export MYSERVERS | |
# where to put/get git repos from. also where we get .zshrc in get_zshrc() | |
export GITSERVER="lonely.example.com" | |
export GITSERVER_PATH="/home/$SHORTNAME/code/" | |
export PATH=/usr/local/git/bin:$PATH | |
# alias server shortname as a ssh shortcut | |
for i in ${MYSERVERS[@]} | |
do | |
NAME=$(echo $i | awk -F . '{print $1}') | |
alias ${NAME}="ssh $SHORTNAME@$i" | |
done | |
# not sure I need these :) | |
export DEBFULLNAME=$NAME # These are used by Debian packaging... | |
export DEBEMAIL=$EMAIL # ...programs. | |
export COLOR_PROMPT=yes | |
export force_colored_prompt=yes | |
export LSCOLORS=dxfxcxdxbxegedabagacad | |
setopt INC_APPEND_HISTORY SHARE_HISTORY | |
setopt APPEND_HISTORY | |
# setopt AUTO_LIST # these two should be turned off | |
# setopt AUTO_REMOVE_SLASH | |
# setopt AUTO_RESUME # tries to resume command of same name | |
unsetopt BG_NICE # do NOT nice bg commands | |
setopt CORRECT # command CORRECTION | |
setopt EXTENDED_HISTORY # puts timestamps in the history | |
# setopt HASH_CMDS # turns on hashing | |
# | |
setopt MENUCOMPLETE | |
setopt ALL_EXPORT | |
setopt nobeep | |
setopt nohup | |
setopt completeinword | |
unsetopt promptcr # Fixes problems in screen | |
# bind up/down to history prefix search | |
# bindkey "\e[B" history-search-forward | |
# bindkey "\e[A" history-search-backward | |
bindkey "\e[B" history-beginning-search-forward | |
bindkey "\e[A" history-beginning-search-backward | |
# zstyle ':completion:*:history-words' stop verbose | |
# zstyle ':completion:*:history-words' remove-all-dups yes | |
# friend had these codes for home/end for some reason | |
# bindkey '\e[7~' beginning-of-line # home | |
# bindkey '\e[8~' end-of-line # end | |
# Terminal.app had to also be setup to send these codes for home/end | |
bindkey '\e[H' beginning-of-line # home | |
bindkey '\e[F' end-of-line # end | |
# control left & right to behave like OS X | |
bindkey '^[[5D' beginning-of-line # home | |
bindkey '^[[5C' end-of-line # end | |
# word jump via 'option-arrows' if option is set as meta in Terminal.app | |
bindkey '\e\e[D' backward-word | |
bindkey '\e[3D' backward-word | |
bindkey '\e\e[C' forward-word | |
bindkey '\e[3C' forward-word | |
# setup vim to no suck | |
if [[ ! -e ~/.vimrc ]]; then | |
echo "set nocindent" >> ~/.vimrc | |
echo "set cinoptions=" >> ~/.vimrc | |
echo "set nosmartindent" >> ~/.vimrc | |
echo "set noautoindent" >> ~/.vimrc | |
echo "set indentexpr=" >> ~/.vimrc | |
echo "filetype indent off" >> ~/.vimrc | |
echo "filetype plugin indent off" >> ~/.vimrc | |
fi | |
# setup ssh for host completion | |
# if [[ -d ~/.ssh ]]; then | |
# echo "HashKnownHosts no" >> ~/.ssh/config | |
# else | |
# mkdir ~/.ssh/ | |
# echo "HashKnownHosts no" > ~/.ssh/config | |
# fi | |
if [[ ! -e ~/.ssh/known_hosts ]]; then | |
touch ~/.ssh/known_hosts | |
fi | |
# Limits. | |
unlimit | |
limit stack 8192 | |
limit core 0 # No coredumps. | |
limit -s | |
# Someone once accused zsh of not being as complete as Emacs, because it | |
## lacks Tetris and an adventure game. | |
autoload -U tetris | |
zle -N tetris | |
bindkey "^Xt" tetris ## C-x-t to play | |
# Set/unset shell options | |
setopt notify globdots correct pushdtohome cdablevars autolist | |
setopt correctall autocd recexact longlistjobs | |
setopt autoresume histignoredups pushdsilent histappend | |
setopt autopushd pushdminus extendedglob rcquotes mailwarning | |
unsetopt bgnice autoparamslash | |
function gitproj { | |
REPO="ssh://${GITSERVER}${GITSERVER_PATH}/$1.git" | |
git clone $REPO | |
} | |
function gitize { | |
PROJECT_NAME=$(basename "`pwd`") | |
# make git repo | |
git init | |
if [ ! -e 'README.markdown' ]; then | |
touch README.markdown | |
fi | |
git add . | |
git commit -m 'First commit' | |
# copy repo to remote server | |
scp -rp .git $GITSERVER:${GITSERVER_PATH}$PROJECT_NAME.git | |
git remote add origin ssh://${GITSERVER}${GITSERVER_PATH}${PROJECT_NAME}.git | |
echo " " | |
echo "Gitize completed." | |
} | |
function publish_zshrc { | |
reload | |
for i in ${MYSERVERS[@]} | |
do | |
echo "Uploading .zshrc to $i ..." | |
scp ~/.zshrc $i:~/ | |
done | |
} | |
function get_zshrc { | |
reload | |
echo "Getting .zshrc from ${GITSERVER} ..." | |
scp $SHORTNAME@${GITSERVER}:~/.zshrc ~/ | |
} | |
# function title { | |
# if [[ $TERM == "screen" ]]; then | |
# # Use these two for GNU Screen: | |
# print -nR $'\033k'$1$'\033'\\\ | |
# | |
# print -nR $'\033]0;'$2$'\a' | |
# elif [[ $TERM == "xterm" || $TERM == "rxvt" || $TERM == "xterm-color" ]]; then | |
# # Use this one instead for XTerms: | |
# print -nR $'\033]0;'$*$'\a' | |
# fi | |
# } | |
function title { | |
a=${(V)1//\%/\%\%} | |
a=$(print -Pn "%40>...>$a" | tr -d "\n") | |
case $TERM in | |
screen) | |
print -Pn "\e]2;$a @ $2\a" # plain xterm title | |
print -Pn "\ek$a\e\\" # screen title (in ^A") | |
print -Pn "\e_$2 \e\\" # screen location | |
;; | |
xterm*|rxvt) | |
print -Pn "\e]2;$2\a" # plain xterm title | |
;; | |
esac | |
} | |
# Process completion | |
#zstyle ':completion:*:*:kill:*' menu yes select | |
#zstyle ':completion:*:kill:*' force-list always | |
zstyle ':completion:*:processes' command 'ps -au$USER' | |
zstyle ':completion:*:*:*:*:processes' menu yes select | |
zstyle ':completion:*:*:*:*:processes' force-list always | |
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' | |
# ZFTP is an ftp client built right in to zsh. *Very* neat. | |
if [[ $ZSH_VERSION > '4.2' ]]; then | |
autoload zfinit ; zfinit | |
# Emailaddress for anonymous-session | |
(( ${+EMAIL_ADDR} )) || export EMAIL_ADDR="$EMAIL" | |
# A `G' for a get operation and a `P' for a put operation. | |
ZFTP_TRANSFER=yes | |
# Default is a reverse progressbar but its very ugly *narf* | |
# Valid options are ``none'', ``bar'' and ``percent''. | |
zstyle ':zftp:*' progress percent | |
# Specifies the minimum time interval between updates of the | |
# progress meters in seconds | |
zstyle ':zftp:*' update true | |
# If set to ``1'', ``yes'' or ``true'', filename generation | |
# (globbing) is performed on the remote maschine instead of | |
# zsh itself. Hell no!!!11! | |
zstyle ':zftp:*' remote-glob false | |
fi | |
# Host completion (code by bkhl) | |
if [[ -f ~/.ssh/known_hosts ]]; then | |
_etchosts=(${(s: :)${(ps:\t:)${${(f)"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}) | |
_sshhosts=(${${${${(f)"$(<~/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*}) | |
_myhosts=($_etchosts $_sshhosts) | |
zstyle ':completion:*' hosts $_myhosts | |
fi | |
# Add colors to completions | |
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} | |
#zmodload zsh/complist | |
autoload zcalc | |
autoload -U zmv | |
# Enable caching | |
zstyle ':completion::complete:*' use-cache 1 | |
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST | |
# To force zsh to realize new commands | |
#zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete | |
# Sweet trick from zshwiki.org :-) | |
cd () { | |
if (( $# != 1 )); then | |
builtin cd "$@" | |
return | |
fi | |
if [[ -f "$1" ]]; then | |
builtin cd "$1:h" | |
else | |
builtin cd "$1" | |
fi | |
} | |
# display some informations | |
function status() | |
{ | |
local system="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)" | |
print "" | |
print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")"" | |
print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)" | |
print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars" | |
print "Login.: $LOGNAME (UID = $EUID) on $HOST" | |
print "System: $system" | |
print "Uptime:$(uptime)" | |
print "" | |
} | |
# Restarting zsh or bash; reloading .zshrc or functions | |
_force_rehash() { | |
(( CURRENT == 1 )) && rehash | |
return 1 # Because we didn't really complete anything | |
} | |
bash () { | |
NO_ZSH="yes" command bash "$@" | |
} | |
restart () { | |
exec $SHELL "$@" | |
} | |
profile () { | |
ZSH_PROFILE_RC=1 $SHELL "$@" | |
} | |
reload () { | |
if [[ "$#*" -eq 0 ]]; then | |
. ~/.zshrc | |
else | |
local fn | |
for fn in "$@"; do | |
unfunction $fn | |
autoload -U $fn | |
done | |
fi | |
} | |
#compdef _functions reload | |
# Usage: simple-extract <file> | |
# Description: extracts archived files (maybe) | |
simple-extract () | |
{ | |
if [[ -f "$1" ]] | |
then | |
case "$1" in | |
*.tar.bz2) bzip2 -v -d "$1" ;; | |
*.tar.gz) tar -xvzf "$1" ;; | |
*.ace) unace e "$1" ;; | |
*.rar) unrar x "$1" ;; | |
*.deb) ar -x "$1" ;; | |
*.bz2) bzip2 -d "$1" ;; | |
*.lzh) lha x "$1" ;; | |
*.gz) gunzip -d "$1" ;; | |
*.tar) tar -xvf "$1" ;; | |
*.tgz) gunzip -d "$1" ;; | |
*.tbz2) tar -jxvf "$1" ;; | |
*.zip) unzip "$1" ;; | |
*.Z) uncompress "$1" ;; | |
*.shar) sh "$1" ;; | |
*) echo "'"$1"' Error. Please go away" ;; | |
esac | |
else | |
echo "'"$1"' is not a valid file" | |
fi | |
} | |
# Usage: smartcompress <file> (<type>) | |
# Description: compresses files or a directory. Defaults to tar.gz | |
smartcompress() | |
{ | |
if [ '$2' ]; then | |
case '$2' in | |
tgz | tar.gz) tar -zcvf$1.$2 '$1' ;; | |
tbz2 | tar.bz2) tar -jcvf$1.$2 '$1' ;; | |
tar.Z) tar -Zcvf$1.$2 '$1' ;; | |
tar) tar -cvf$1.$2 '$1' ;; | |
gz | gzip) gzip '$1' ;; | |
bz2 | bzip2) bzip2 '$1' ;; | |
*) | |
echo "Error: $2 is not a valid compression type" | |
;; | |
esac | |
else | |
smartcompress '$1' tar.gz | |
fi | |
} | |
# Usage: show-archive <archive> | |
# Description: view archive without unpack | |
show-archive() | |
{ | |
if [[ -f $1 ]] | |
then | |
case $1 in | |
*.tar.gz) gunzip -c $1 | tar -tf - -- ;; | |
*.tar) tar -tf $1 ;; | |
*.tgz) tar -ztf $1 ;; | |
*.zip) unzip -l $1 ;; | |
*.bz2) bzless $1 ;; | |
*) echo "'$1' Error. Please go away" ;; | |
esac | |
else | |
echo "'$1' is not a valid archive" | |
fi | |
} | |
function dirsize() | |
{ | |
if [ -z $1 ]; then | |
dir="." | |
else | |
dir=$1 | |
fi | |
find $dir -type d -maxdepth 1 -mindepth 1 -exec du -sh '{}' \; 2>/dev/null \ | |
| perl -pe "s/\t.*\/(.*)$/\t$(echo '\033[01;32m')\1$(echo '\033[0m')/gi" | |
echo | |
echo "Total: " $(du -sh $dir 2>/dev/null | awk '{print $1}') | |
} | |
function pyinst() { | |
sudo python setup.py clean | |
sudo python setup.py build | |
sudo python setup.py install | |
} | |
function mount-iso() { | |
sudo mount -o loop -t iso9660 $1 $2 | |
} | |
function preexec() { | |
if [ $HOME = $PWD ]; | |
then | |
newPWD="~" | |
else | |
newPWD=${PWD:t} | |
fi | |
title "" "%m: %35<...<$newPWD" | |
} | |
precmd() { | |
## Hacky Bazaar and Git info in the prompt | |
export VCS="" | |
export BRANCH="" | |
export RPROMPT="" | |
base="" | |
for i in $(pwd | awk '{ split($0,a,"/"); for (i=1; i<=100; i++) print a[i]}') | |
do | |
base=$base/$i | |
if [[ -d $base/.bzr ]]; | |
then | |
export VCS="bzr:$(basename $base)@rev$(bzr revno) " | |
else | |
if [[ -d $base/.git ]]; | |
then | |
#export VCS=" git:$(basename $(pwd))@rev$(git log | grep Date: | wc -l)" | |
export BRANCH="(`git symbolic-ref HEAD | cut -d'/' -f3`)" | |
export RPROMPT="%{$fg[blue]%}$BRANCH%{$reset_color%}" # I'm sure there will be a builtin for this....care | |
fi | |
fi | |
done | |
if [ $HOME = $PWD ]; | |
then | |
newPWD="~" | |
else | |
newPWD=${PWD:t} | |
fi | |
title "" "%m: %55<...<$newPWD" | |
#export PS1="%{$fg[green]%}%n%{$fg[cyan]%}@%m%{$reset_color%}%{$fg[green]%} $newPWD%{$reset_color%}%{$BRANCH%}$ " | |
export PS1="%{$fg[green]%}%n%{$fg[cyan]%}@%m%{$reset_color%}%{$fg[green]%} $newPWD%{$reset_color%}$ " | |
} | |
## END FUNCTIONS | |
HISTFILE=~/.histfile | |
HISTSIZE=1000 | |
SAVEHIST=1717 | |
alias decaf="/Applications/Espresso.app/Contents/SharedSupport/Tools/decaf" | |
alias untar="tar xzfvv" # for tarballs | |
alias unbz2="tar xvvfj" # for .bz2 archives | |
if [ `uname` = "Darwin" ]; then | |
alias ls="ls -G" | |
elif [ `uname -o` = "GNU/Linux" ]; then | |
alias ls="ls --color=always" | |
fi | |
alias grep="grep --colour=always" | |
bindkey '\e[3~' delete-char | |
bindkey -s '^n^p' $'ncmpc\n' # Launch ncmpc pressing CTRL+{N,P} | |
# Autoload zsh modules when they are referenced | |
zmodload -a zsh/stat stat | |
zmodload -a zsh/zpty zpty | |
zmodload -a zsh/zprof zprof | |
zmodload -ap zsh/mapfile mapfile | |
autoload -U colors; colors | |
# Load the completion system | |
autoload -U compinit; compinit | |
zstyle ':completion::complete:*' use-cache on | |
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST | |
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} | |
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s' | |
zstyle ':completion:*' menu select=1 _complete _ignored _approximate | |
zstyle -e ':completion:*:approximate:*' max-errors \ | |
'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )' | |
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' | |
# Completion Styles | |
# list of completers to use | |
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate | |
# allow one error for every three characters typed in approximate completer | |
zstyle -e ':completion:*:approximate:*' max-errors \ | |
'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )' | |
# insert all expansions for expand completer | |
zstyle ':completion:*:expand:*' tag-order all-expansions | |
# formatting and messages | |
zstyle ':completion:*' verbose yes | |
zstyle ':completion:*:descriptions' format '%B%d%b' | |
zstyle ':completion:*:messages' format '%d' | |
zstyle ':completion:*:warnings' format 'No matches for: %d' | |
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b' | |
zstyle ':completion:*' group-name '' | |
# match uppercase from lowercase | |
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' | |
# offer indexes before parameters in subscripts | |
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters | |
# command for process lists, the local web server details and host completion | |
# on processes completion complete all user processes | |
zstyle ':completion:*:processes' command 'ps -au$USER' | |
## add colors to processes for kill completion | |
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' | |
#zstyle ':completion:*:processes' command 'ps -o pid,s,nice,stime,args' | |
#zstyle ':completion:*:urls' local 'www' '/var/www/htdocs' 'public_html' | |
# | |
#NEW completion: | |
# 1. All /etc/hosts hostnames are in autocomplete | |
# 2. If you have a comment in /etc/hosts like #%foobar.domain, | |
# then foobar.domain will show up in autocomplete! | |
zstyle ':completion:*' hosts $(grep "^#%" /etc/hosts | awk -F% '{print $2}') | |
# Filename suffixes to ignore during completion (except after rm command) | |
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \ | |
'*?.old' '*?.pro' | |
# the same for old style completion | |
#fignore=(.o .c~ .old .pro) | |
knownhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} ) | |
zstyle ':completion:*:(ssh|scp|sftp):*' hosts $knownhosts | |
# ignore completion functions (until the _ignored completer) | |
zstyle ':completion:*:functions' ignored-patterns '_*' | |
zstyle ':completion:*:*:*:users' ignored-patterns \ | |
adm apache bin daemon games gdm halt ident junkbust lp mail mailnull \ | |
named news nfsnobody nobody nscd ntp operator pcap postgres radvd \ | |
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs avahi-autoipd\ | |
avahi backup messagebus beagleindex debian-tor dhcp dnsmasq fetchmail\ | |
firebird gnats haldaemon hplip irc klog list man cupsys postfix\ | |
proxy syslog www-data mldonkey sys snort | |
# SSH Completion | |
zstyle ':completion:*:scp:*' tag-order \ | |
files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *' | |
zstyle ':completion:*:scp:*' group-order \ | |
files all-files users hosts-domain hosts-host hosts-ipaddr | |
zstyle ':completion:*:ssh:*' tag-order \ | |
users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *' | |
zstyle ':completion:*:ssh:*' group-order \ | |
hosts-domain hosts-host users hosts-ipaddr | |
zstyle '*' single-ignored show | |
# fix mac backspace/delete keybindings | |
bindkey '^?' backward-delete-char | |
bindkey '^[[3~' delete-char | |
upgrade () { | |
if [ ! $1 ] ; then | |
print "local upgrade" | |
if [ `uname` = "Darwin" ]; then | |
print "osx_upgrade_local" | |
osx_upgrade_local | |
elif [ `uname -o` = "GNU/Linux" ]; then | |
print "debian_upgrade_local" | |
debian_upgrade_local | |
else | |
print "I don't know what can I do for this type of machine" | |
fi | |
elif [[ $1 = "help" || $1 = "--help" || $1 = "-h" ]] ; then | |
print "local usage for upgrading Mac OS X or debian systems including fink and darwin ports: upgrade and | |
clean" | |
print 'remote usage: upgrade $debian_server' | |
elif [ $1 ]; then | |
print "remote upgrade" | |
if [[ `ssh $1 uname -o 2&>/dev/null` = "GNU/Linux" ]] ; then | |
print "debian_upgrade_remote" | |
debian_upgrade_remote $1 | |
elif [[ `ssh $1 uname 2&>/dev/null` = "Darwin" ]] ; then | |
print "osx_upgrade_remote" | |
osx_upgrade_remote $1 | |
else | |
print "$1 is not a debian nor an osx machine" | |
print "please implement an upgrade function for this kind of machine!" | |
fi | |
fi | |
} | |
# osx local upgrade | |
osx_upgrade_local () { | |
print "=== update Mac systems ===" | |
sudo softwareupdate -i -a | |
#if [ -x /usr/bin/gem ] ; then | |
# sudo /usr/bin/gem update | |
#fi | |
if [ -x /sw/bin/fink ] ; then | |
print "=== fink upgrade ===" | |
sudo fink selfupdate | |
sudo fink update-all | |
sudo fink cleanup | |
fi | |
if [ -x /opt/local/bin/port ] ; then | |
print "=== darwin ports ===" | |
#sudo port sync | |
sudo port -d selfupdate | |
#sudo port -uR upgrade installed | |
sudo port -ucRvpt upgrade installed | |
sudo port clean --all installed | |
if [ -x /opt/local/bin/gem ] ; then | |
sudo /opt/local/bin/gem update | |
fi | |
fi | |
if [ -d /Library/Application\ Support/TextMate/Bundles ]; then | |
pushd /Library/Application\ Support/TextMate/Bundles | |
svn up *.tmbundle | |
popd | |
osascript -e 'tell app "TextMate" to reload bundles' | |
fi | |
} | |
# local debian upgrade | |
debian_upgrade_local (){ | |
print "Upgrading Debian" | |
sudo apt-get update && sudo apt-get -u upgrade | |
print "Cleaning up" | |
sudo apt-get clean | |
} | |
# remote osx upgrade | |
osx_upgrade_remote (){ | |
if [ ! $1 ]; then | |
print "usage: osx_upgrade_remote $osx_server" | |
print "Perhaps you want osx_upgrade_local ?" | |
else | |
# local variables declaration | |
local OSX_UP | |
local FINK_UP | |
local DARWINPORTS_UP | |
# ask before the upgrade | |
until [[ $OSX_UP == 'y' || $OSX_UP == 'n' ]]; do | |
print -n "Process osx upgrade on $1 (y/n)?" | |
read -q OSX_UP | |
done; | |
until [[ $FINK_UP == 'y' || $FINK_UP == 'n' ]]; do | |
print -n "Process fink upgrade on $1 (y/n)?" | |
read -q FINK_UP | |
done; | |
until [[ $DARWINPORTS_UP == 'y' || $DARWINPORTS_UP == 'n' ]]; do | |
print -n "Process darwinports upgrade on $1 (y/n)?" | |
read -q DARWINPORTS_UP | |
done; | |
# upgrade if answer is y | |
if [[ $OSX_UP == "y" ]] ; then | |
print "=== update Mac systems ===" | |
ssh $1 -t /usr/bin/sudo /usr/sbin/softwareupdate -i -a | |
fi | |
if [[ $FINK_UP == "y" ]] ; then | |
print "=== fink upgrade ===" | |
ssh $1 -t /usr/bin/sudo /sw/bin/fink selfupdate | |
ssh $1 -t /usr/bin/sudo /sw/bin/fink update-all | |
ssh $1 -t /usr/bin/sudo /sw/bin/fink cleanup | |
fi | |
if [[ $DARWINPORTS_UP == "y" ]] ; then | |
print "=== darwin ports ===" | |
ssh $1 -t /usr/bin/sudo /opt/local/bin/port selfupdate | |
#ssh $1 -t /usr/bin/sudo /opt/local/bin/port -uR upgrade installed | |
ssh $1 -t /usr/bin/sudo /opt/local/bin/port upgrade installed | |
ssh $1 -t /usr/bin/sudo /opt/local/bin/port clean --all installed | |
fi | |
fi | |
} | |
# remote debian upgrade | |
debian_upgrade_remote (){ | |
if [ ! $1 ]; then | |
print "usage: debian_upgrade_remote $debian_server" | |
print "Perhaps you want debian_upgrade_local ?" | |
else | |
print "remote debian upgrade on $1" | |
ssh $1 -t sudo apt-get update | |
# print what should be upgraded | |
ssh $1 -t "sudo apt-get -s upgrade" | |
# ask before the upgrade | |
local dummy | |
print -n "Process the upgrade y/n ?" | |
read -q dummy | |
if [[ $dummy == "y" ]] ; then | |
ssh $1 -t "sudo apt-get -u upgrade --yes && sudo apt-get clean" | |
print "upgrade on $1 done" | |
fi | |
fi | |
} | |
# Invoke this every time when u change .zshrc to | |
# recompile it. | |
src () | |
{ | |
autoload -U zrecompile | |
[ -f ~/.zshrc ] && zrecompile -p ~/.zshrc | |
[ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump | |
[ -f ~/.zshrc.zwc.old ] && rm -f ~/.zshrc.zwc.old | |
[ -f ~/.zcompdump.zwc.old ] && rm -f ~/.zcompdump.zwc.old | |
source ~/.zshrc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment