Browse Source

zsh - from github/ryanb/dotfiles

windhamdavid 13 years ago
parent
commit
72d211abd1

+ 33 - 0
ndpc.local/zsh/aliases

@@ -0,0 +1,33 @@
+# cd
+alias ..='cd ..'
+
+# ls
+alias ls="ls -F"
+alias l="ls -lAh"
+alias ll="ls -l"
+alias la='ls -A'
+
+# git
+alias gl='git pull'
+alias gp='git push'
+alias gd='git diff'
+alias gc='git commit'
+alias gca='git commit -a'
+alias gco='git checkout'
+alias gb='git branch'
+alias gs='git status'
+alias grm="git status | grep deleted | awk '{print \$3}' | xargs git rm"
+alias changelog='git log `git log -1 --format=%H -- CHANGELOG*`..; cat CHANGELOG*'
+
+# rails
+alias sc='script/console'
+alias ss='script/server'
+alias sg='script/generate'
+alias a='autotest -rails'
+alias tlog='tail -f log/development.log'
+alias scaffold='script/generate nifty_scaffold'
+alias migrate='rake db:migrate db:test:clone'
+alias rst='touch tmp/restart.txt'
+
+# commands starting with % for pasting from web
+alias %=' '

+ 8 - 0
ndpc.local/zsh/completion

@@ -0,0 +1,8 @@
+autoload -U compinit
+compinit
+
+# matches case insensitive for lowercase
+zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
+
+# pasting with tabs doesn't perform completion
+zstyle ':completion:*' insert-tab pending

+ 46 - 0
ndpc.local/zsh/config

@@ -0,0 +1,46 @@
+if [[ -n $SSH_CONNECTION ]]; then
+  export PS1='%m:%3~$(git_info_for_prompt)%# '
+else
+  export PS1='%3~$(git_info_for_prompt)%# '
+fi
+
+export EDITOR='mate_wait'
+export PATH="$HOME/bin:$HOME/.bin:/usr/local/homebrew/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/git/bin:$PATH"
+export MANPATH="/usr/local/man:/usr/local/mysql/man:/usr/local/git/man:$MANPATH"
+
+fpath=(~/.zsh/functions $fpath)
+
+autoload -U ~/.zsh/functions/*(:t)
+
+HISTFILE=~/.zsh_history
+HISTSIZE=1000
+SAVEHIST=1000
+REPORTTIME=10 # print elapsed time when more than 10 seconds
+
+setopt NO_BG_NICE # don't nice background tasks
+setopt NO_HUP
+setopt NO_LIST_BEEP
+setopt LOCAL_OPTIONS # allow functions to have local options
+setopt LOCAL_TRAPS # allow functions to have local traps
+setopt HIST_VERIFY
+setopt SHARE_HISTORY # share history between sessions ???
+setopt EXTENDED_HISTORY # add timestamps to history
+setopt PROMPT_SUBST
+setopt CORRECT
+setopt COMPLETE_IN_WORD
+setopt IGNORE_EOF
+
+setopt APPEND_HISTORY # adds history
+setopt INC_APPEND_HISTORY SHARE_HISTORY  # adds history incrementally and share it across sessions
+setopt HIST_IGNORE_ALL_DUPS  # don't record dupes in history
+setopt HIST_REDUCE_BLANKS
+
+zle -N newtab
+
+bindkey '^[^[[D' backward-word
+bindkey '^[^[[C' forward-word
+bindkey '^[[5D' beginning-of-line
+bindkey '^[[5C' end-of-line
+bindkey '^[[3~' delete-char
+bindkey '^[^N' newtab
+bindkey '^?' backward-delete-char 

+ 65 - 0
ndpc.local/zsh/functions/_brew

@@ -0,0 +1,65 @@
+#compdef brew
+
+# Brew ZSH completion function
+# Drop this somewhere in your $fpath (like /usr/share/zsh/site-functions)
+# and rename it _brew
+#
+# altered from _fink
+
+_brew_all_formulae() {
+  formulae=(`brew search`)
+}
+
+_brew_installed_formulae() {
+  installed_formulae=(`brew list`)
+}
+
+local -a _1st_arguments
+_1st_arguments=(
+  'install:install a formula'
+  'remove:remove a formula'
+  'search:search for a formula (/regex/ or string)'
+  'list:list files in a formula or not-installed formulae'
+  'link:link a formula'
+  'unlink:unlink a formula'
+  'home:visit the homepage of a formula or the brew project'
+  'info:information about a formula'
+  'prune:remove dead links'
+  'update:freshen up links'
+  'log:git commit log for a formula'
+  'create:create a new formula'
+  'edit:edit a formula'
+)
+
+local expl
+local -a formula installed_formulae
+
+_arguments \
+  '(-v --verbose)'{-v,--verbose}'[verbose]' \
+  '(--version)--version[version information]' \
+  '(--prefix)--prefix[where brew lives on this system]' \
+  '(--cache)--cache[brew cache]' \
+  '*:: :->subcmds' && return 0
+
+if (( CURRENT == 1 )); then
+  _describe -t commands "brew subcommand" _1st_arguments
+  return
+fi
+
+case "$words[1]" in
+  list)
+    _arguments \
+      '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
+      '1: :->forms' &&  return 0
+      
+      if [[ "$state" == forms ]]; then
+        _brew_installed_formulae
+        _requested installed_formulae expl 'installed formulae' compadd -a installed_formulae
+      fi ;;
+  install|home|log|info)
+    _brew_all_formulae
+    _wanted formulae expl 'all formulae' compadd -a formulae ;;
+  remove|edit|xo)
+    _brew_installed_formulae
+    _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
+esac

+ 2 - 0
ndpc.local/zsh/functions/_c

@@ -0,0 +1,2 @@
+#compdef c
+_files -W ~/code -/

+ 8 - 0
ndpc.local/zsh/functions/_cap

@@ -0,0 +1,8 @@
+#compdef cap
+if [ -f Capfile ]; then
+  recent=`last_modified .cap_tasks~ Capfile **/deploy.rb`
+  if [[ $recent != '.cap_tasks~' ]]; then
+    cap --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~
+  fi
+  compadd `cat .cap_tasks~`
+fi

+ 2 - 0
ndpc.local/zsh/functions/_gh

@@ -0,0 +1,2 @@
+#compdef gh
+_github

+ 7 - 0
ndpc.local/zsh/functions/_git-rm

@@ -0,0 +1,7 @@
+#compdef git-rm
+_arguments -S -A '-*' \
+  '-f[override the up-to-date check]' \
+  "-n[don't actually remove the files, just show if they exist in the index]" \
+  '-r[allow recursive removal when a leading directory-name is given]' \
+  '--cached[only remove files from the index]' && ret=0
+_files

+ 72 - 0
ndpc.local/zsh/functions/_github

@@ -0,0 +1,72 @@
+#compdef github
+
+_github() {
+  if (( CURRENT > 2 )); then
+    # shift words so _arguments doesn't have to be concerned with second command
+    (( CURRENT-- ))
+    shift words
+    # use _call_function here in case it doesn't exist
+    _call_function 1 _github_${words[1]}
+  else
+    _values "github command" \
+     "fetch[Fetch from a remote to a local branch.]" \
+     "ignore[Ignore a SHA (from 'github network commits')]" \
+     "fetch_all[Fetch all refs from a user]" \
+     "info[Info about this project.]" \
+     "browse[Open this repo in a web browser.]" \
+     "home[Open this repo's master branch in a web browser.]" \
+     "clone[Clone a repo.]" \
+     "pull-request[Generate the text for a pull request.]" \
+     "network[Project network tools.]" \
+     "pull[Pull from a remote.]" \
+     "track[Track another user's repository.]"
+  fi
+}
+
+_github_pull() {
+  _arguments \
+    "--merge[Automatically merge remote's changes into your master.]"
+}
+_github_clone() {
+  _arguments \
+    "--ssh[Clone using the git@github.com style url.]"
+}
+
+_github_track() {
+  _arguments \
+    "--private[Use git@github.com: instead of git://github.com/.]" \
+    "--ssh[Equivalent to --private.]"
+}
+
+_github_network() {
+  if (( CURRENT > 2 )); then
+    # shift words so _arguments doesn't have to be concerned with second command
+    (( CURRENT-- ))
+    shift words
+    # use _call_function here in case it doesn't exist
+    _call_function 1 _github_network_${words[1]}
+  else
+    _values "github network command" \
+     "web[Open network in a web browser.]" \
+     "list[List networked repositories.]" \
+     "fetch[Fetched commits for a given networked repository.]" \
+     "commits[List networked commits not pulled into this repo.]"
+  fi
+}
+
+_github_network_commits() {
+  _arguments \
+    "--project[Filter commits on a certain project.]" \
+    "--author[Filter commits on a email address of author.]" \
+    "--common[Show common branch point.]" \
+    "--nocache[Do not use the cached network data.]" \
+    "--sort[How to sort : date(*), branch, author.]" \
+    "--thisbranch[Look at branches that match the current one]" \
+    "--applies[Filter commits to patches that apply cleanly.]" \
+    "--limit[Only look through the first X heads - useful for really large projects]" \
+    "--before[Only show commits before a certain date.]" \
+    "--after[Only show commits after a certain date.]" \
+    "--shas[Only show shas.]" \
+    "--cache[Use the network data even if it's expired.]" \
+    "--noapply[Filter commits to patches that do not apply cleanly.]"
+}

+ 2 - 0
ndpc.local/zsh/functions/_h

@@ -0,0 +1,2 @@
+#compdef h
+_files -W ~ -/

+ 8 - 0
ndpc.local/zsh/functions/_rake

@@ -0,0 +1,8 @@
+#compdef rake
+if [ -f Rakefile ]; then
+  recent=`last_modified .rake_tasks~ Rakefile **/*.rake`
+  if [[ $recent != '.rake_tasks~' ]]; then
+    rake --silent --tasks | cut -d " " -f 2 > .rake_tasks~
+  fi
+  compadd `cat .rake_tasks~`
+fi

+ 1 - 0
ndpc.local/zsh/functions/c

@@ -0,0 +1 @@
+cd ~/code/$1;

+ 1 - 0
ndpc.local/zsh/functions/gam

@@ -0,0 +1 @@
+curl $1 | git am

+ 1 - 0
ndpc.local/zsh/functions/gfp

@@ -0,0 +1 @@
+git format-patch master --stdout > $1

+ 48 - 0
ndpc.local/zsh/functions/git_info_for_prompt

@@ -0,0 +1,48 @@
+local g="$(git rev-parse --git-dir 2>/dev/null)"
+if [ -n "$g" ]; then
+  local r
+  local b
+  if [ -d "$g/../.dotest" ]
+  then
+    if test -f "$g/../.dotest/rebasing"
+    then
+      r="|REBASE"
+    elif test -f "$g/../.dotest/applying"
+    then
+      r="|AM"
+    else
+      r="|AM/REBASE"
+    fi
+    b="$(git symbolic-ref HEAD 2>/dev/null)"
+  elif [ -f "$g/.dotest-merge/interactive" ]
+  then
+    r="|REBASE-i"
+    b="$(cat "$g/.dotest-merge/head-name")"
+  elif [ -d "$g/.dotest-merge" ]
+  then
+    r="|REBASE-m"
+    b="$(cat "$g/.dotest-merge/head-name")"
+  elif [ -f "$g/MERGE_HEAD" ]
+  then
+    r="|MERGING"
+    b="$(git symbolic-ref HEAD 2>/dev/null)"
+  else
+    if [ -f "$g/BISECT_LOG" ]
+    then
+      r="|BISECTING"
+    fi
+    if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
+    then
+      if ! b="tag: $(git describe --exact-match HEAD 2>/dev/null)"
+      then
+        b="$(cut -c1-7 "$g/HEAD")..."
+      fi
+    fi
+  fi
+ 
+  if [ -n "$1" ]; then
+    printf "$1" "${b##refs/heads/}$r"
+  else
+    printf "[%s]" "${b##refs/heads/}$r"
+  fi
+fi

+ 1 - 0
ndpc.local/zsh/functions/h

@@ -0,0 +1 @@
+cd ~/$1;

+ 1 - 0
ndpc.local/zsh/functions/last_modified

@@ -0,0 +1 @@
+ls -t $* 2> /dev/null | head -n 1

+ 26 - 0
ndpc.local/zsh/functions/newtab

@@ -0,0 +1,26 @@
+savepath
+osascript >/dev/null <<EOF
+on do_submenu(app_name, menu_name, menu_item, submenu_item)
+		-- bring the target application to the front
+		tell application app_name
+			activate
+		end tell
+		tell application "System Events"
+			tell process app_name
+				tell menu bar 1
+					tell menu bar item menu_name
+						tell menu menu_name
+							tell menu item menu_item
+								tell menu menu_item
+									click menu item submenu_item
+								end tell
+							end tell
+						end tell
+					end tell
+				end tell
+			end tell
+		end tell
+end do_submenu
+
+do_submenu("Terminal", "Shell", "New Tab", 1)
+EOF

+ 1 - 0
ndpc.local/zsh/functions/railsapp

@@ -0,0 +1 @@
+rails $2 -m http://github.com/ryanb/rails-templates/raw/master/$1.rb $*[3,-1]

+ 1 - 0
ndpc.local/zsh/functions/savepath

@@ -0,0 +1 @@
+pwd > ~/.current_path~

+ 5 - 0
ndpc.local/zsh/functions/verbose_completion

@@ -0,0 +1,5 @@
+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:*' group-name ''