Skip to content

Commit

Permalink
Move files around, add ghc and cabal completions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamse committed Dec 10, 2014
1 parent 3bf5a7f commit 345a46a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 94 deletions.
60 changes: 60 additions & 0 deletions zsh/completion/ghc
@@ -0,0 +1,60 @@
# ========================================
# Glasgow Haskell Compiler Bash Completion
# ========================================
#
# For how to use the GHC bash completion, see the README.
#
# This file implements bash completion for both GHC and GHCi.
#
# - We use GHC's --show-options to get a list of the available
# flags. It is aware that some flags are used for GHC, and others for GHCi.
# - We understand when the argument;
# * has to be a directory name (eg. following -hidir)
# * cannot be completed (eg. following -e)
#
# Future work;
# - Some flags needs their argument after an equal sign;
# eg. -fmax-simplifier-iterations=N
# Currently the flag will be completed without knowledge of
# the required argument.
# - Complete package names/ids.
# eg. -package-id <TAB><TAB> should list valid package-ids
# - The +RTS flags are not supported.
# +RTS <TAB><TAB> should list valid RTS flags.

_ghc ()
{
local completions=`$1 --show-options`
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"

# Complete the current flag based on the previous flag.
case "$prev" in
-hidir|-odir|-stubdir|-dumpdir|-outputdir|-tmpdir|-hpcdir|-dylib-install-name|-framework-path)
# Complete only with directory names.
compopt -o dirnames
return 0
;;
-package-name|-package|-hide-package|-ignore-package|-trust|-distrust)
# Should complete package names. Not implemented.
# To do this well, ghc has to be invoked with --show-packages with all
# package related flags the user has provided.
return 0
;;
-e|-x|-hcsuf|-hisuf|-osuf|-framework)
# Do nothing. Next argument is not a flag.
return 0
;;
esac

# Look at the current flag.
if [[ "$cur" == -* ]]; then
# All GHC flags start with a dash, so we want to see this before we start
# suggesting flags. Otherwise we would complete flags when the user might
# want to type a file name.
COMPREPLY=( $( compgen -W "$completions -x" -- "$cur" ) )
fi
}

complete -F _ghc -o default ghc
complete -F _ghc -o default ghci
94 changes: 23 additions & 71 deletions zsh/zshrc → zsh/config 100644 → 100755
Expand Up @@ -14,20 +14,27 @@ ulimit -S -c 0
# Use emacs bindings
bindkey -e

autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line

# COMPLETION
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
zstyle ':completion:*' max-errors 5
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*' special-dirs true

autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line

autoload -Uz compinit
compinit
autoload bashcompinit
compinit
bashcompinit

source ~/.zsh/completion/*
# enable extra completion if available
test -d /usr/local/share/zsh-completions &&
fpath=(/usr/local/share/zsh-completions $fpath)


HISTFILE=~/.histfile
HISTSIZE=100000
SAVEHIST=100000
Expand All @@ -41,20 +48,16 @@ function test_add() {
test -d "$1" && PATH="$1:$PATH"
}

test_add "/usr/texbin"

test_add "$HOME/bin"
test_add "$HOME/local/bin"

test_add "$HOME/local/arcanist/bin"
test_add "$HOME/.rvm/bin"

test_add "/usr/texbin"
test_add "/usr/local/opt/ruby/bin"

test_add "/usr/local/mysql/bin"

test_add "/usr/local/bin"

# Haskell stuff
test_add "$HOME/bin"
test_add "$HOME/local/bin"
test_add "$HOME/local/arcanist/bin"
test_add "$HOME/local/ghc/bin"
test_add "$HOME/.cabal/bin"

Expand All @@ -75,10 +78,6 @@ export FTP_PASSIVE
# ignore backups, CVS directories, python bytecode, vim swap files
FIGNORE="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"

# enable extra completion if available
test -d /usr/local/share/zsh-completions &&
fpath=(/usr/local/share/zsh-completions $fpath)

[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh

# PAGER & EDITOR
Expand Down Expand Up @@ -106,13 +105,10 @@ export PAGER MANPAGER
ACK_PAGER="$PAGER"
ACK_PAGER_COLOR="$PAGER"

# }}}
# ----
# OS SPECIFIC {{{
# ----

# Nix packages
if [ -e /Users/adam/.nix-profile/etc/profile.d/nix.sh ]; then . /Users/adam/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer
# Nix
test -e /Users/adam/.nix-profile/etc/profile.d/nix.sh &&
source /Users/adam/.nix-profile/etc/profile.d/nix.sh

if [ "$UNAME" == "Darwin" ]; then
# we always pass these to ls(1)
Expand All @@ -130,20 +126,13 @@ if [ "$UNAME" == "Linux" ]; then

test "$TERM" = "rxvt-unicode" &&
TERM="xterm"

test -d "$HOME/local/share/perl5" &&
PERL5LIB="$HOME/local/share/perl5:$PERL5LIB"
fi

if [ "$UNAME" == "FreeBSD" ]; then
# we always pass these to ls(1)
LS_COMMON="-hBGF"
fi

# }}}
# ----
# PROMPT {{{
# ----

# Set terminal title
precmd () { print -Pn "\e]0;%n@%m: %~\a" }
Expand All @@ -167,15 +156,11 @@ vcs_info_wrapper() {
}
RPROMPT=$'$(vcs_info_wrapper)'

PROMPT="%F{red}%n%f at %F{yellow}%M%f in %B%F{blue}%~%f%b
PROMPT="%F{red}%n%f at %F{yellow}%M%f in %B%F{blue}%~%f%b
%# "

export PROMPT

# }}}
# ----
# LS & COLORS {{{
# ----

export CLICOLOR="yes"

Expand All @@ -200,20 +185,9 @@ alias l.="ls -d .*"
alias ll.="ls -ld .*"
alias chrome='/usr/bin/open -a "/Applications/Google Chrome.app"'

# }}}
# ----

# MISC COMMANDS {{{
# ----

# push SSH public key to another box
push_ssh_cert() {
local _host
test -f ~/.ssh/id_rsa.pub || ssh-keygen -t rsa
for _host in "$@"; do
echo $_host
ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
done
}


cabal_install_sandbox() {
if [ "$#" -lt "1" ]; then
Expand All @@ -227,25 +201,3 @@ with_sandbox() {
echo PATH="./cabal-sandbox/bin:$PATH" $@
PATH="./cabal-sandbox/bin:$PATH" $@
}

#cabal_sandbox_path() {
#}

# }}}
# ----
# ALIASES {{{
# ----

test -e ~/.aliases && source .aliases

# }}}

# vim: ts=4 sts=4 shiftwidth=4 expandtab

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting


# PLUGINS

# zsh-bd
. $HOME/.zsh/plugins/bd/bd.zsh
23 changes: 0 additions & 23 deletions zsh/ghc-pkg.sh

This file was deleted.

0 comments on commit 345a46a

Please sign in to comment.