Skip to content

Instantly share code, notes, and snippets.

@zamber
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zamber/b7294cc0e76338aea364 to your computer and use it in GitHub Desktop.
Save zamber/b7294cc0e76338aea364 to your computer and use it in GitHub Desktop.
ZSH expanding aliases in emacs mode
################################################################################
# Change java version
################################################################################
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
# set java for new shell instances
setjdk 1.6
alias getjdk="java -version && /usr/libexec/java_home -V"
################################################################################
# Exapandable aliases - ealias
# https://wiki.math.cmu.edu/iki/wiki/tips/20140625-zsh-expand-alias.html
################################################################################
typeset -a ealiases
ealiases=()
function ealias() {
alias $1
ealiases+=(${1%%\=*})
}
function expand-ealias() {
if [[ $LBUFFER =~ "(^|[;|&])\s*(${(j:|:)ealiases})\$" ]]; then
zle _expand_alias
zle expand-word
fi
zle magic-space
}
zle -N expand-ealias
bindkey -M emacs ' ' expand-ealias
bindkey -M emacs '^ ' magic-space # control-space to bypass completion
bindkey -M isearch " " magic-space # normal space during searches
################################################################################
# Aliases
################################################################################
# normal
alias zshrc="subl -w ~/.zshrc && reload"
alias reload=". ~/.zshrc && echo 'ZSH config reloaded from ~/.zshrc'"
# expanding!
ealias ezshrc="subl -w ~/.zshrc && reload"
ealias ereload=". ~/.zshrc && echo 'ZSH config reloaded from ~/.zshrc'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment