From ec12ea611e9643e0a21c88190ea990f53077d9aa Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 11 Apr 2012 10:12:44 -0400 Subject: [PATCH 1/2] Add fasd module --- modules/fasd/init.zsh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 modules/fasd/init.zsh diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh new file mode 100644 index 00000000..ee90d745 --- /dev/null +++ b/modules/fasd/init.zsh @@ -0,0 +1,27 @@ +# https://github.com/clvv/fasd + +omodload 'completion' + +if (( ! $+commands[fasd] )); then + return 1 +fi + +eval "$(fasd --init-zsh)" + +alias a='fasd -a' # any +alias s='fasd -s' # show / search / select +alias d='fasd -d' # directory +alias f='fasd -f' # file +alias z='fasd_cd -d' # cd, same functionality as j in autojump + +alias j='z' # Quickly cd into directories. +alias m='f -e mplayer' # Quickly open files with mplayer. +alias o="a -e $aliases[o]" # Quickly open files with open. +alias v='f -e vim -b viminfo' # Quickly open files with vim. + +for keymap in 'emacs' 'viins'; do + bindkey -M "$keymap" "$key_info[Control]X$key_info[Control]A" fasd-complete # C-x C-a (files and directories) + bindkey -M "$keymap" "$key_info[Control]X$key_info[Control]D" fasd-complete-d # C-x C-d (directories) + bindkey -M "$keymap" "$key_info[Control]X$key_info[Control]F" fasd-complete-f # C-x C-f (files) +done + From 507cf4ce9b7c8b66c2ac44c96179ecddf7667fba Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Thu, 12 Apr 2012 08:04:46 -0400 Subject: [PATCH 2/2] Cache fasd initialization --- modules/fasd/init.zsh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh index ee90d745..11381473 100644 --- a/modules/fasd/init.zsh +++ b/modules/fasd/init.zsh @@ -6,7 +6,29 @@ if (( ! $+commands[fasd] )); then return 1 fi -eval "$(fasd --init-zsh)" +cache_file="${0:h}/cache.zsh" +if [[ ! -s "$cache_file" ]]; then + # fasd is slow; cache its output. + # fasd --init-zsh >! "$cache_file" 2> /dev/null + # fasd --init \ + # posix-alias \ + # zsh-hook \ + # zsh-ccomp \ + # zsh-ccomp-install \ + # zsh-wcomp \ + # zsh-wcomp-install >! "$cache_file" 2> /dev/null + + init_args='posix-alias zsh-hook' + if -t zstyle ':omz:module:completion' loaded; then + init_args+='zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install' + fi + + fasd --init "${(z)init_args[@]}" >! "$cache_file" 2> /dev/null +fi + +source "$cache_file" + +unset cache_file init_args alias a='fasd -a' # any alias s='fasd -s' # show / search / select