From c3ac1174c2dddf7c7c7282b5090c5d4470eb2397 Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Mon, 6 Feb 2012 10:49:43 +1100 Subject: [PATCH] WORK plugin added * before definition of zsh plugins set WORKPLUGIN_DIRS variable with list of your "work" directories relative to your $HOME, such as WORKPLUGIN_DIRS=('work' 'src') * now you can use work command in your zshell, which will change CWD to first occurrence WORKPLUGIN_DIRS sub folders * directories competition is supported * also, you can define WORKPLUGIN_CALLBACK function, which will be called after directory change. In my case, I use it to call virtualenvwrapper's `workon` function --- plugins/work/work.plugin.zsh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 plugins/work/work.plugin.zsh diff --git a/plugins/work/work.plugin.zsh b/plugins/work/work.plugin.zsh new file mode 100644 index 000000000..3dfe98ecb --- /dev/null +++ b/plugins/work/work.plugin.zsh @@ -0,0 +1,27 @@ +typeset -A _WORKPLUGIN_DIRS_FULLPATH + +for dir in $WORKPLUGIN_DIRS; do + _WORKPLUGIN_DIRS_FULLPATH[$dir]="$HOME/$dir" +done + +work() { + local dir + for dir in $_WORKPLUGIN_DIRS_FULLPATH; do + if [[ -d "$dir/$1" ]]; then + builtin cd "$dir/$1" + break + fi + done + if [[ $(type -w "WORKPLUGIN_CALLBACK") == "WORKPLUGIN_CALLBACK: function" ]]; then + WORKPLUGIN_CALLBACK "$1" + fi +} + +_work_comp() { + local dir + for dir in $_WORKPLUGIN_DIRS_FULLPATH; do + compadd $(ls $dir) + done +} + +compdef _work_comp work