Browse Source

Add 'rc/' from commit 'b0bda43e3aa6fdbcd413b1942bcdfcdddc7bf770'

git-subtree-dir: rc
git-subtree-mainline: e6d92e1f90
git-subtree-split: b0bda43e3a
master
Peter J. Jones 4 years ago
commit
7f18fec20e
42 changed files with 1130 additions and 0 deletions
  1. 32
    0
      GNUmakefile
  2. 35
    0
      app/cltc.zsh
  3. 10
    0
      app/dict.zsh
  4. 10
    0
      app/emacs.zsh
  5. 142
    0
      app/git.zsh
  6. 14
    0
      app/gpg.zsh
  7. 12
    0
      app/mysql.zsh
  8. 70
    0
      app/nix.zsh
  9. 12
    0
      app/ruby.zsh
  10. 7
    0
      app/script.zsh
  11. 1
    0
      app/ssh.zsh
  12. 83
    0
      app/tmux.zsh
  13. 122
    0
      app/virsh.zsh
  14. 33
    0
      app/vmware.zsh
  15. 14
    0
      app/wmctrl.zsh
  16. 8
    0
      app/x11vnc.zsh
  17. 1
    0
      app/xcode.zsh
  18. 22
    0
      dot/zshenv
  19. 62
    0
      dot/zshrc
  20. 22
    0
      func/c
  21. 18
    0
      func/d
  22. 18
    0
      func/get
  23. 17
    0
      func/loop
  24. 9
    0
      func/mkpatches
  25. 33
    0
      func/send-key
  26. 24
    0
      func/st
  27. 20
    0
      func/untar
  28. 18
    0
      lib/agents.zsh
  29. 61
    0
      lib/aliases.zsh
  30. 28
    0
      lib/bindings.zsh
  31. 18
    0
      lib/completion.zsh
  32. 6
    0
      lib/directories.zsh
  33. 15
    0
      lib/history.zsh
  34. 8
    0
      lib/hosts.zsh
  35. 57
    0
      lib/prompt.zsh
  36. 2
    0
      local/beefy.local
  37. 2
    0
      local/skinny.local
  38. 4
    0
      os/darwin
  39. 29
    0
      os/linux
  40. 2
    0
      os/sunos
  41. 19
    0
      util/git-sb-info.zsh
  42. 10
    0
      wids/last-cmd-as-expansion

+ 32
- 0
GNUmakefile View File

@@ -0,0 +1,32 @@
################################################################################
include ../mk/init.mk
include ../mk/files.mk

################################################################################
DEST = $(HOME)/.zsh
HOST = $(shell hostname)
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')

################################################################################
FILES = $(wildcard lib/*.zsh)
FILES += $(wildcard app/*.zsh)
FILES += $(wildcard util/*.zsh)
FILES += $(wildcard func/*)
FILES += $(wildcard wids/*.zsh)

################################################################################
$(foreach f,$(FILES),$(eval $(call PMADE_INSTALL_FILE,$(f),$(DEST)/$(f))))
$(eval $(call PMADE_INSTALL_DOT,dot/zshrc))
$(eval $(call PMADE_INSTALL_DOT,dot/zshenv))

################################################################################
# Local (hostname based) Override
ifneq ($(wildcard local/$(HOSTNAME)),)
$(eval $(call PMADE_INSTALL_FILE,local/$(HOSTNAME),$(DEST)/local))
endif

################################################################################
# OS (os name based) Override
ifneq ($(wildcard os/$(OS)),)
$(eval $(call PMADE_INSTALL_FILE,os/$(OS),$(DEST)/os))
endif

+ 35
- 0
app/cltc.zsh View File

@@ -0,0 +1,35 @@
if [ `hostname` = "cltc" ]; then

##############################################################################
function _cltc-app {
name=$1
dir=$HOME/develop/scors/$name

if [ -n "$shellHook" ]; then
echo "ERROR: you're already inside nix-shell"
exit 1
fi

if [ ! -d $dir ]; then
( cd `dirname $dir`
git clone --recursive git@github.ors.sc.gov:ors/${name}.git
)
fi

( export DEV_ENV=$name
cd $dir
nix-shell --command zsh ~/develop/scors/nix/${name}.nix
)
}

##############################################################################
function cltc-phoenix {
_cltc-app cltc-phoenix
}

##############################################################################
function cltc-claims {
_cltc-app cltc-claims
}

fi

+ 10
- 0
app/dict.zsh View File

@@ -0,0 +1,10 @@
################################################################################
dict_it () {
dict --database ita-eng "$@"
}

################################################################################
dict_sounds_like () {
dict --match --strategy soundex "$@"
dict --match --strategy lev "$@"
}

+ 10
- 0
app/emacs.zsh View File

@@ -0,0 +1,10 @@
# Set our EDITOR
if [ -x ~/bin/e ] && which emacsclient > /dev/null 2>&1; then
export EDITOR="e --wait"
elif which emacsclient > /dev/null 2>&1; then
export EDITOR="emacsclient"
elif which vim > /dev/null 2>&1; then
export EDITOR=vim
else
export EDITOR=vi
fi

+ 142
- 0
app/git.zsh View File

@@ -0,0 +1,142 @@
################################################################################
# Git Log
glog ()
{
git log --pretty=format:'%Cgreen%h%Creset %Cred%ci%Creset %Cblue%ae%Creset %s' --graph $@
}

################################################################################
# Resolve conflicts by keeping the local changes and throwing away the
# remote changes
git_resolve_with_local ()
{
if [ $# -eq 0 ]; then
FILES=`git ls-files -u | awk '{if ($3==1) print $4;}'`
test -z "$FILES" && exit
else
FILES=$*
fi

PREFIX=`git rev-parse --show-prefix`

# need the echo below because the files are someone all glued
# together in a single string
for f in `echo $FILES`; do
echo "--> Tossing remote changes for $f"
git cat-file blob ":2:${PREFIX}${f}" >| "$f" 2> /dev/null
touch "$f"
git add -- "$f"
done

echo "now run git commit"
}

################################################################################
# Find out if a repo has uncommitted changes
git_repo_has_changes ()
{
if ! git status|grep -q -F 'working directory clean'; then
return 0
else
return 1
fi
}

################################################################################
# Find out if a repo has changes that haven't been pushed
git_repo_needs_push ()
{
if git status|head -2|grep -q 'ahead of'; then
return 0
else
return 1
fi
}

################################################################################
# Returns the name of the current git branch if we're in a git repo
git_current_branch ()
{
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}

################################################################################
# Create a new branch, and push it to the origin server
git_mk_branch ()
{
if [ $# -eq 0 ]; then
echo "Usage: $0 branch [remote]"
return 1
fi

branch=$1
remote=${2:-origin}

git checkout -b $branch || return 1
git config --add branch.${branch}.remote $remote || return 1
git push $remote $branch || return 1
}

################################################################################
# Delete a branch: FIXME: remove from all remotes
git_rm_branch ()
{
if [ $# -eq 0 ]; then
echo "Usage: $0 branch"
return 1
fi

branch=$1
git branch -d $branch || return 1

if git branch -a | grep -q origin/$branch; then
git push origin :heads/$branch
fi
}

################################################################################
# Pull master, and return to the current branch
git_master_pull ()
{
remote=origin
test $# -eq 1 && remote=$1

branch=`git_current_branch`
echo "==> Leaving branch ${branch}"
git checkout master || return 1
git pull $remote || return 1
git checkout $branch || return 1
}

################################################################################
# List info about each sub-module
function git-sb-info ()
{
git submodule --quiet foreach 'zsh ~/.zsh/util/git-sb-info.zsh'
}

################################################################################
# Create a new remote repo
git_new_repo ()
{
remote_path=$1
remote_name=origin
remote_host=dracula.pmade.com

test $# -gt 1 && remote_name=$2
test $# -gt 2 && remote_host=$3

ssh $remote_host "mkdir -p $remote_path && cd $remote_path && git init --bare"
git remote add $remote_name ${remote_host}:$remote_path
git config --add branch.master.remote $remote_name
git config --add branch.master.merge refs/heads/master
git push $remote_name master
}

################################################################################
# Find out about the current repo.
function git-what ()
{
git describe --long --tags --dirty --always
}

+ 14
- 0
app/gpg.zsh View File

@@ -0,0 +1,14 @@
################################################################################
# Outputs which key was used to encrypt a file.
gpg_which () {
file=$1
key=$(_gpg_which_key $file)
gpg --list-keys $key
}

################################################################################
# Helper function.
_gpg_which_key () {
gpg --batch --decrypt --list-only --status-fd 1 $1 2> /dev/null |\
awk '/ENC_TO/ {print $3}'
}

+ 12
- 0
app/mysql.zsh View File

@@ -0,0 +1,12 @@
# Create a new super user in mySQL
mysql_create_super_user () {
if [ $# -ne 2 ]; then
echo "Usage: $0 username password"
return 1
fi
for user in "'${1}'@'localhost'" "'${1}'@'%'"; do
echo CREATE USER "${user}" IDENTIFIED BY "'${2}'" | mysql -u root
echo GRANT ALL PRIVILEGES ON "*.*" TO "${user}" WITH GRANT OPTION | mysql -u root
done
}

+ 70
- 0
app/nix.zsh View File

@@ -0,0 +1,70 @@
################################################################################
# Functions for making Nix and NixOS a bit easier.
if [ -d /etc/nix ]; then

##############################################################################
function _nix-inside-shell () {
if [[ -n $NIX_BUILD_TOP ]]; then
return 0
else
return 1
fi
}

##############################################################################
# Run a Nix command with the correct options and environment for a
# local copy of nixpkgs.
function _nix-with-nixpkgs () {
command=$1
shift

typeset -a options
options=()

# Automatically add a binary cache when on my home network:
if iwgetid | cut -d: -f2 | grep -q "515"; then
options=($options --option extra-binary-caches http://10.0.1.10:8080)
fi

export NIX_PATH=nixpkgs=$HOME/develop/oss/nixpkgs:$NIX_PATH
$command $options "$@"
}

##############################################################################
# Nix shell with a local clone of nixpkgs.
function nixpkgs-shell () {
_nix-with-nixpkgs nix-shell --command $(which zsh) "$@"
}

##############################################################################
# Nix build with a local clone of nixpkgs.
function nixpkgs-build () {
_nix-with-nixpkgs nix-build "$@"
}

##############################################################################
# Create a `default.nix` file for a Haskell project.
function nix-hs-derivation () {
nixpkgs-shell -p haskellPackages.cabal2nix \
--command "cabal2nix $PWD -fmaintainer $@ > default.nix"
}

##############################################################################
function nix-hs-shell () {
nix-hs-derivation
override=~/.nixpkgs/envs/dev/haskell-cabal.nix
nixpkgs-shell -I pwd=$PWD --pure "$@" $override
}

##############################################################################
# Build a Haskell project with the hsbuild.sh tool.
function nix-hs-build () {
nix-hs-shell --command $(which hsbuild.sh) "$@"
}

################################################################################
else

##############################################################################
function _nix-inside-shell () {return 1}
fi

+ 12
- 0
app/ruby.zsh View File

@@ -0,0 +1,12 @@
################################################################################
# If the rbenv tool is installed, use it.
if [ -d ~/.rbenv/bin ]; then
path=(~/.rbenv/bin $path)
eval "$(rbenv init -)"
fi

################################################################################
alias irb='irb --readline -r irb/completion'

################################################################################
rtags () { command rtags --quiet $(find . -type f -name '*.rb')}

+ 7
- 0
app/script.zsh View File

@@ -0,0 +1,7 @@
# script
script ()
{
script_options='-a'
[[ $OSNAME == "FreeBSD" ]] && script_options="$script_options -k"
(export INSIDE_SCRIPT=yes; command script `eval echo $script_options` $*)
}

+ 1
- 0
app/ssh.zsh View File

@@ -0,0 +1 @@
alias add-key='ssh-add $HOME/.ssh/id_dsa'

+ 83
- 0
app/tmux.zsh View File

@@ -0,0 +1,83 @@
################################################################################
# Mount a virtual machine via SSHFS and then create a tmux session
# inside it.
tmux_mount () {
if [ $# -ne 1 ]; then
echo "Usage: tmux_mount name"
return 1
fi

name=$1
mount_point=$HOME/develop/hosts/$1
mount_options="-oauto_cache,reconnect,ControlMaster=no"
server=${name}.pmade.com

# If the host is a VM and it's not already running, start it.
virsh_is_registered $name && (virsh_running $name || virsh_start $name)

echo "==> Mounting $name on $mount_point"
mkdir -p $mount_point

if ssh $server test -d develop; then
server_dir=develop
elif ssh $server test -d Develop; then
server_dir=Develop
else
server_dir=""
fi

sshfs "${server}:${server_dir}" $mount_point $mount_options || return 1
cp ~/.emacs.d/server/server $mount_point/emacs.server

echo "==> Starting tmux session $name"
(cd $mount_point && tmux new-session -d -s $name)

return $?
}

################################################################################
# Mount and attach to a new session
tmux_mount_attach () {
tmux_mount $1 && tmux attach -t $1
}

################################################################################
# Kill a tmux session and un-mount the sshfs file system.
tmux_umount () {
if [ $# -ne 1 ]; then
echo "Usage: tmux_umount name"
return 1
fi

name=$1
mount_point=$HOME/develop/hosts/$1

if tmux list-sessions | awk '{print $1}' | grep -q ^${name}:\$; then
echo "==> Killing tmux session $name"
tmux kill-session -t $name || return 1
sleep 2 # Wait for all processes accessing the VM to die
fi

# Avoid my 'df' alias below by giving the full path
if /bin/df -P | awk 'NR > 1 {print $6}' | grep -q hosts/$name\$; then
echo "==> Un-mounting $mount_point"
fusermount -u $mount_point || return 1
fi
}

################################################################################
# Runs tmux_umount and then stops the VM
tmux_umount_stop () {
if [ $# -ne 1 ]; then
echo "Usage: tmux_umount_stop name"
return 1
fi

name=$1
tmux_umount $name || return 1

if virsh_running $name; then
echo "==> Stopping $name virtual machine"
virsh_stop $name || return 1
fi
}

+ 122
- 0
app/virsh.zsh View File

@@ -0,0 +1,122 @@
################################################################################
# Returns 0 if a VM is running, otherwise 1.
virsh_running () {
if [ $# -ne 1 ]; then
echo "Usage: virsh_running name"
return 2
fi

name=$1
state=`virsh dominfo $name | grep ^State | awk '{print $2}'`

if [ "$state" = "running" ]; then
return 0
else
return 1
fi
}

################################################################################
# Returns 0 if the given VM is registered with libvirt, otherwise 1.
virsh_is_registered () {
if [ $# -ne 1 ]; then
echo "Usage: virsh_is_registered name"
return 2
fi

name=$1

if virsh dominfo $name > /dev/null 2>&1; then
return 0
else
return 1
fi
}

################################################################################
# Returns 0 if the VM has managed save info, otherwise 1.
virsh_has_managed_save () {
if [ $# -ne 1 ]; then
echo "Usage: virsh_has_managed_save name"
return 2
fi

name=$1
save=`virsh dominfo $name | grep '^Managed save' | awk '{print $3}'`

if [ "$save" = "yes" ]; then
return 0
else
return 1
fi
}

################################################################################
# Returns the current version of libvirt
virsh_version () {
virsh version | head -1 | awk -F: '{print $2}' | awk '{print $2}'
}

################################################################################
# Start a VM and wait for it to be running.
virsh_start () {
if [ $# -ne 1 ]; then
echo "Usage: virsh_start name"
return 1
fi

name=$1
hostname="${name}.pmade.com"

# First check to see if we're already running.
virsh_running $name && return 0

# Record if we have managed state
if virsh_has_managed_save $name; then
with_save=1
else
with_save=0
fi

# Start it and wait for it to be pingable
virsh start $name || return 1
echo "==> Waiting for $name to start..."
[ $with_save -eq 0 ] && sleep 60
ping -c 5 -q -w 120 $hostname
}

################################################################################
# Stop a running VM using managedsave.
virsh_stop () {
if [ $# -ne 1 ]; then
echo "Usage: virsh_stop name"
return 1
fi

name=$1
flags=""

if [ $(virsh_version) != '0.9.8' ]; then
flags="--verbose"
fi

# Can't stop a domain unless it's running
virsh_running $name || return 0

echo "==> Waiting for $name to stop"
virsh managedsave $name $flags
}

################################################################################
# Open a vnc connection to a virtual machine
virsh_vnc () {
if [ $# -ne 1 ]; then
echo "Usage: virsh_vnc name"
return 1
fi

name=$1
port=$(virsh vncdisplay $name|head -1|sed 's/^.*://')
port=$(expr 5900 + $port)
vnc localhost:$port
}

+ 33
- 0
app/vmware.zsh View File

@@ -0,0 +1,33 @@
################################################################################
# Access the vmrun tool.
vmware_vmrun () {
"/Library/Application Support/VMware Fusion/vmrun" $@
}

################################################################################
# Returns the base directory where we mount things.
vmware_base_mount_point () {
echo ~/Develop/hosts
}

################################################################################
# Mount a VMWare virtual machine using sshfs
vmware_mount () {
name=$1

server="sshfs.${name}.pmade.com"
directory=`vmware_base_mount_point`"/$name"
mkdir -p $directory
sshfs "${server}:" $directory -oauto_cache,reconnect,volname=$name
}

################################################################################
# Mount a virtual machine and create a tmux session
vmware_session () {
name=$1
vmware_mount $name || return 1
directory=`vmware_base_mount_point`"/$name"
(cd $directory/develop && tmux new-session -d -s $name)
}

+ 14
- 0
app/wmctrl.zsh View File

@@ -0,0 +1,14 @@
################################################################################
wmctrl_activate_emacs () {
win_id=$(wmctrl -l |awk '$4 ~ /emacs/ && $2 == 0 {print $1}'|head -1)
if [[ -n $win_id ]]; then
wmctrl -ia $win_id
fi
}

################################################################################
# Activates the biggest Conkeror window.
wmctrl_activate_conkeror () {
wmctrl -ia $(wmctrl -lG|grep Conkeror|sort -nk 5|tail -1|awk '{print $1}')
}

+ 8
- 0
app/x11vnc.zsh View File

@@ -0,0 +1,8 @@
################################################################################
function x11vnc-projector () {
projector=`xrandr|egrep '^HDMI1[[:space:]]+connected'|cut -f3 -d' '`

x11vnc -clip "$projector" -viewonly \
-forever -localhost -quiet \
-wirecopyrect -scrollcopyrect
}

+ 1
- 0
app/xcode.zsh View File

@@ -0,0 +1 @@
alias xc='xcodebuild -alltargets -configuration Debug && xcodebuild -alltargets -configuration Release'

+ 22
- 0
dot/zshenv View File

@@ -0,0 +1,22 @@
#!/usr/bin/env zsh

# Set default path
typeset -U path

# Add some standard directories to PATH.
[ -d ~/.cabal/bin ] && path=(~/.cabal/bin $path)

# Another tool which updates my path...
[ -r ~/local/paths ] && eval $(~/bin/local-paths.sh ~/local/paths)

# Always keep ~/bin at the head of the list.
path=(~/bin $path)

# Load agent environment variables.
source ~/.zsh/lib/agents.zsh

# Load in optional operating system override
[ -r ~/.zsh/os ] && source ~/.zsh/os

# Load in optional local override file
[ -r ~/.zsh/local ] && source ~/.zsh/local

+ 62
- 0
dot/zshrc View File

@@ -0,0 +1,62 @@
#!/usr/local/bin/zsh

# keep some arrays unique
typeset -U fpath
typeset -U cdpath
typeset -U manpath

# some variables to export
export OSNAME=`uname -s`
export LESS="-SRiJMW"
export PAGER=less

# add our function path
functions_directory=~/.zsh/func
widgets_directory=~/.zsh/wids
fpath=($functions_directory $widgets_directory $fpath)

# clober stuff
setopt no_clobber
setopt hist_allow_clobber

# other options
setopt alwaystoend
setopt auto_cd
setopt auto_list
setopt completeinword
setopt correct
setopt magic_equal_subst
setopt mark_dirs
setopt multios
setopt no_auto_remove_slash
setopt no_beep
setopt no_correct_all
setopt rematch_pcre

# job control
setopt no_hup
setopt no_check_jobs

# autoload my functions
autoload -U ${fpath[1]}/*(:t)

# load some useful modules
zmodload zsh/datetime

# bring in other files
source ~/.zsh/lib/bindings.zsh
source ~/.zsh/lib/aliases.zsh
source ~/.zsh/lib/hosts.zsh
source ~/.zsh/lib/completion.zsh
source ~/.zsh/lib/directories.zsh
source ~/.zsh/lib/history.zsh
source ~/.zsh/lib/prompt.zsh

# Application files are autoloaded, if I can get it to freaking work:
# http://zsh.sourceforge.net/Doc/Release/Functions.html
# fpath=(~/.zsh/app $fpath)

for file in $(find ~/.zsh/app -type f -name '*.zsh'); do
source $file
#autoload -w $file
done

+ 22
- 0
func/c View File

@@ -0,0 +1,22 @@
#!/usr/local/bin/zsh

####
#
# Help print out columns
#
####

if [ "$#" -eq 1 ]; then
awk "{print \$$1}"
else
read -A cols
read -t -k 1 && cat > /dev/null

echo 1 | \
(
PROMPT3=""
select i in $cols; do
break
done
)
fi

+ 18
- 0
func/d View File

@@ -0,0 +1,18 @@
#!zsh

#
# change to a directory in the directory stack
#

typeset -a dlist
dlist=(`dirs`)
shift dlist

PROMPT3="Choose a directory: "

select i in $dlist; do
cd_to=$i
break
done

eval "cd $cd_to"

+ 18
- 0
func/get View File

@@ -0,0 +1,18 @@
#!/usr/local/bin/zsh

if which wget > /dev/null; then
wget $1

elif which curl > /dev/null; then
curl -o `basename $1` $1

elif which fetch > /dev/null; then
fetch $1

elif which lftpget > /dev/null; then
lftpget $1

else
echo "no http/ftp program installed"

fi

+ 17
- 0
func/loop View File

@@ -0,0 +1,17 @@
#!/usr/bin/env zsh

sleep_for=30
[ $# -eq 1 ] && sleep_for=$1

hist_number=1
while :; do
[ $hist_number -eq 10 ] && return
the_command=`fc -l -$hist_number -$hist_number|sed 's/ *[0-9]* *//'`
[[ $the_command != loop* ]] && break
let "hist_number++"
done

while :; do
eval $the_command
sleep $sleep_for
done

+ 9
- 0
func/mkpatches View File

@@ -0,0 +1,9 @@
#!/usr/local/bin/zsh

for orig in `find . -name '*.orig'`; do
name=`echo $orig | sed 's/\.orig$//g'`
patch="$name.patch"

echo "$orig $name ==> $patch"
diff -u $orig $name > $patch
done

+ 33
- 0
func/send-key View File

@@ -0,0 +1,33 @@
#!zsh

#
# send your SSH public key to another host
#
if [ $# -lt 1 ]; then
echo "Usage: $0 <host> [ssh-options]"
return 1
fi

to_host=$1
shift

tmp=newkey
agent_key=$(ssh-add -L|awk '{print $3}'|head -1)

if [ -r "$agent_key".pub ]; then
src="$agent_key".pub
elif [ -r ~/.ssh/id_dsa.pub ]; then
src=~/.ssh/id_dsa.pub
elif [ -r ~/.ssh/id_rsa.pub ]; then
src=~/.ssh/id_rsa.pub
else
echo "ERROR: no public key found"
return 1
fi

cat $src | ssh $@ $to_host "
mkdir -p ~/.ssh;
chmod 700 ~/.ssh;
cat >> ~/.ssh/authorized_keys;
chmod 600 ~/.ssh/authorized_keys;
"

+ 24
- 0
func/st View File

@@ -0,0 +1,24 @@
#!/usr/bin/env zsh

typeset -axU st

OLD_IFS=$IFS
IFS="
"

if [ -d .svn ]; then
# Subversion Status
st=(`svn status --ignore-externals | egrep -v '^X'`)
index=1

while [ $index -le $#st ]; do
printf "%2d %s\n" $index "$st[$index]"
st[$index]=`echo $st[$index] | sed 's/^[^[:space:]]*[[:space:]]*//'`
let "++index"
done
else
# Git Status
git status
fi

IFS=$OLD_IFS

+ 20
- 0
func/untar View File

@@ -0,0 +1,20 @@
#!/usr/local/bin/zsh

if [[ $1 == *.gz || $1 == *.tgz ]]; then
gunzip -c $1 | tar xvf -

elif [[ $1 == *.bz2 ]]; then
bunzip2 -c $1 | tar xvf -

elif [[ $1 == *.xz ]]; then
xz --decompress --stdout $1 | tar xvf -

elif [[ $1 == *.zip ]]; then
unzip $1

elif [[ $1 == *.tar ]]; then
cat $1 | tar xvf -

else
echo "Unknow file type: $1"
fi

+ 18
- 0
lib/agents.zsh View File

@@ -0,0 +1,18 @@
# Some variables to always export.
export SSH_AGENT_PID
export SSH_AUTH_SOCK
export GPG_AGENT_INFO

# Only load these files in an GUI session
if [ -n "$DISPLAY" ]; then

# Load SSH agent environment vars.
if [ -r ~/.ssh/agent ]; then
eval `cat ~/.ssh/agent | egrep -v ^echo`
fi

# Load GPG agent environment vars.
if [ -r ~/.gpg-agent-info ]; then
eval `cat ~/.gpg-agent-info`
fi
fi

+ 61
- 0
lib/aliases.zsh View File

@@ -0,0 +1,61 @@
# stuff for every os
alias vared="IFS=\$'\n' vared"
alias bc='bc -q'
alias lc='fc -lnD -1'
alias h='history -fdD'
alias j='jobs -l'
alias f="find . -name"
alias g="egrep"

# ls command
if [[ $OSNAME == "FreeBSD" || $OSNAME == "Darwin" ]]; then
alias ls='ls -G'
alias l='ls -lFGh'
alias ll='ls -lFGh'
alias la='ls -lFGha'

elif [[ $OSNAME == "Linux" || $OSNAME == "CYGWIN_NT-5.0" ]]; then
alias ls='\ls --color=auto --group-directories-first'
alias lsa='ls -A'
alias l='\ls -lhF --color=auto --group-directories-first'
alias ll='l'
alias la='l -A'
alias _df_awk="awk '{print \$2 \"\\t\" \$4 \"\\t\" \$5 \"\\t\" \$6}'"
alias df="df -hP|_df_awk"
else
alias l='ls -lF'
alias ll='ls -lF'
alias la='ls -lFa'

fi

# ps
if [[ $OSNAME == "FreeBSD" ]]; then
alias p='ps -axwwopid,ppid,user,pcpu,vsz,rss,comm,args'
elif [[ $OSNAME == "Darwin" ]]; then
alias p='ps -axwwopid,ppid,user,pcpu,vsz,rss,command'
elif [[ $OSNAME == "Linux" || $OSNAME == "CYGWIN_NT-5.0" ]]; then
alias p='ps -ewwopid,ppid,user,pcpu,vsz,rss,comm,args'
elif [[ $OSNAME == "AIX" || $OSNAME == "HP-UX" ]]; then
alias p='ps -eopid,ppid,user,pcpu,vsz,comm,args'
else
alias p='ps -eopid,ppid,user,pcpu,vsz,rss,comm,args'
fi

# ps | grep
alias pg="p|g"

# ldd
if [[ $OSNAME == "Darwin" ]]; then
alias ldd='otool -L'
fi

# More complicated aliases that need to be functions.
dl () {dict "$@" | less}

# Just to shorten typing
alias tclock="tty-clock -c -C 4 -f '%b. %d, %Y'"
alias scclock='env TZ=America/New_York tty-clock -C 0 -c -f "South Carolina"'
alias iss_payload='chromium --app=http://www.ustream.tv/channel/iss-hdev-payload/pop-out'
alias rtm='chromium --app=https://www.rememberthemilk.com'
alias mrs='mr -d ~ status'

+ 28
- 0
lib/bindings.zsh View File

@@ -0,0 +1,28 @@
# fix ^w
export WORDCHARS="*?_-.[]~={}<>"
autoload backward-kill-word-match select-word-style match-words-by-style
zle -N backward-kill-word-match
select-word-style normal
match-words-by-style normal

# my widgets
for widget in last-cmd-as-expansion; do
autoload $widget
zle -N $widget
done

# default key binding is emacs
bindkey -e

# Edit command lines in EDITOR.
autoload edit-command-line
zle -N edit-command-line

# Insert some custom keybindings
bindkey -e ^xe edit-command-line
bindkey -e ^xp push-line-or-edit
bindkey -e ^xh run-help
bindkey -e ^r history-incremental-search-backward
bindkey -e ^w backward-kill-word-match
bindkey -e ^o last-cmd-as-expansion
bindkey -e ^i expand-or-complete-prefix

+ 18
- 0
lib/completion.zsh View File

@@ -0,0 +1,18 @@
zstyle ':completion:*' group-name ''
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache

# prevent CVS directories from being auto completed
zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'

# other stuff for cd(1)
zstyle ':completion:*:cd:*' ignore-parents parent pwd

# ignore functions that begin with _
zstyle ':completion:*:functions' ignored-patterns '_*'

autoload -U compinit; compinit

+ 6
- 0
lib/directories.zsh View File

@@ -0,0 +1,6 @@
# Directory stuff
DIRSTACKSIZE=16
setopt auto_pushd
setopt pushd_minus
setopt pushd_silent
setopt pushd_ignore_dups

+ 15
- 0
lib/history.zsh View File

@@ -0,0 +1,15 @@
# History stuff
HISTSIZE=100
SAVEHIST=100
HISTFILE=~/.zsh/history
setopt append_history
setopt inc_append_history
setopt extended_history
setopt hist_find_no_dups
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt hist_ignore_space
setopt hist_no_store
setopt no_hist_beep
setopt hist_save_no_dups
unsetopt share_history

+ 8
- 0
lib/hosts.zsh View File

@@ -0,0 +1,8 @@
# Keep unique
typeset -U ssh_hosts

# Suck in hostnames from known_hosts
if [ -r ~/.ssh/known_hosts ]; then
ssh_hosts=(`awk -F'[:, ]' '{gsub(/\[|\]/, "", $1); print($1)}' < ~/.ssh/known_hosts` $hosts)
zstyle ':completion:*' hosts $ssh_hosts
fi

+ 57
- 0
lib/prompt.zsh View File

@@ -0,0 +1,57 @@
# Prompt magic
autoload -U colors; colors

if [ "x$INSIDE_SCRIPT" = "x" ]; then
setopt prompt_percent
setopt prompt_subst
prompt_newline=$'\n%{\r%}'
prompt_backtick='\`'

precmd () {
# Begin prompt with user@host.
prompt="%F{cyan}.---(%F{blue}%n%F{red}@%F{green}%m%F{cyan})"

# Add conditional last process status
prompt="${prompt}%(?..-[%F{red}%B%?%b%F{cyan}])"

# Add the current directory two levels deep.
prompt="${prompt}-%F{cyan}(%F{yellow}%20<..<%2~%<<%F{cyan})"

# Various flags to show.
flags=""

# Maybe add in the current Git branch.
branch=$(git_current_branch 2> /dev/null)

if [[ ${#branch} -ne 0 ]]; then
if git_repo_has_changes; then
color=red
else
color=green
fi

if [[ $branch == "master" && $color == "green" ]]; then
flags="${flags}%F{${color}}G"
else
prompt="${prompt}-%F{cyan}(%F{${color}}%12<..<$branch%<<%F{cyan})"
fi
fi

# Maybe add info about the current nix-shell.
if _nix-inside-shell; then
flags="${flags}%F{magenta}N"
fi

# Incorporate flags.
if [[ -n $flags ]]; then
prompt="${prompt}-%F{cyan}{${flags}%F{cyan}}"
fi

# Move to the next line and present the command prompt.
prompt="${prompt}${prompt_newline}${prompt_backtick}-%F{white}>%f "
PS1=$prompt
RPROMPT=""
}
else
PS1="$ "
fi

+ 2
- 0
local/beefy.local View File

@@ -0,0 +1,2 @@
#!/usr/bin/env zsh
# My desktop (Mac Pro)

+ 2
- 0
local/skinny.local View File

@@ -0,0 +1,2 @@
#!/usr/bin/env zsh
# My laptop (MacBook Pro)

+ 4
- 0
os/darwin View File

@@ -0,0 +1,4 @@
#!/usr/bin/env zsh

# Correct path for Mac OS X
path=(~/bin /usr/texbin /usr/local/bin $path)

+ 29
- 0
os/linux View File

@@ -0,0 +1,29 @@
#!/usr/bin/env zsh

################################################################################
# Set NIX_PATH to use my local channel, if I'm on NixOS.
if [ -n "$NIX_PATH" ]; then
# NixOS
NIX_PATH="nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs:$NIX_PATH"
else
# Make sure these directories are in PATH.
path=($path /usr/local/bin /usr/local/sbin /usr/games /usr/bin /usr/sbin /bin /sbin)
fi

################################################################################
# NixOS internally knows where to search for man pages. Help zsh auto
# complete on them.
if [ -d ~/.nix-profile ]; then
MANPATH=`man -w`
fi

################################################################################
# Some aliases for Linux
alias vnc="ssvncviewer -escape Alt_L"

################################################################################
# Allow more control keys through in the terminal
if [ -t 1 ]; then
stty stop undef
stty start undef
fi

+ 2
- 0
os/sunos View File

@@ -0,0 +1,2 @@
#!/usr/bin/env zsh
path=(/sbin /usr/sbin /var/ruby/1.8/gem_home/bin $path)

+ 19
- 0
util/git-sb-info.zsh View File

@@ -0,0 +1,19 @@
# This script is called by git_sb_info in rc/zsh/app/git.zsh

source ~/.zsh/app/git.zsh
top=$(cd ..; git rev-parse --show-toplevel)
ref=$(git_current_branch)
name=$(pwd | sed "s|$top/||")
state=clean

if [[ ${#ref} -eq 0 ]]; then
ref="(no branch)"
fi

if git_repo_has_changes; then
state=dirty
elif git_repo_needs_push; then
state=push
fi

printf '%15s %5s %s\n' $ref $state $name

+ 10
- 0
wids/last-cmd-as-expansion View File

@@ -0,0 +1,10 @@
#!/usr/bin/env zsh

last_command='$('`fc -l -1|sed 's/ *[0-9]* *//'`')'

if [[ -z $BUFFER ]]; then
BUFFER=" $last_command"
CURSOR=0
else
BUFFER="$BUFFER $last_command"
fi

Loading…
Cancel
Save