From 358224c76481d9d1ee8ea52dd4b7becb6dde1d9a Mon Sep 17 00:00:00 2001 From: dongweiming Date: Sun, 23 Jun 2013 00:05:16 +0800 Subject: [PATCH 1/3] Add powerline.zsh --- .gitignore | 2 +- custom/powerline.zsh | 168 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 custom/powerline.zsh diff --git a/.gitignore b/.gitignore index 51a5ee6c3..f01154095 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ locals.zsh log/.zsh_history projects.zsh -custom/* +#custom/* !custom/example !custom/example.zsh *.swp diff --git a/custom/powerline.zsh b/custom/powerline.zsh new file mode 100644 index 000000000..e2b726c16 --- /dev/null +++ b/custom/powerline.zsh @@ -0,0 +1,168 @@ +autoload promptinit && promptinit || return 1 + +zmodload zsh/parameter + +# has it been loaded correctly? if not, bail out early. +(( $+functions[prompt_powerline_setup] )) || return 2 + +# we can never know for sure powerline font is installed, but if we're on +# rxvt-unicode, chances are good. note that most zstyles have to be set before +# the prompt is loaded since they are not continuously re-evaluated. +#[[ $TERM == "rxvt-unicode-256color" ]] || return 3 + +### additional zstyles + +# set some fixed host colors +zstyle ':prompt:*:twilight*' host-color 093 +zstyle ':prompt:*:pinkie*' host-color 201 +zstyle ':prompt:*:rarity' host-color white +zstyle ':prompt:*:applejack' host-color 208 +zstyle ':prompt:*:fluttershy' host-color 226 + +# only show username on remote server or if it's different from my default +[[ -n $SSH_CONNECTION || $USER == valodim ]] && zstyle ':prompt:powerline:ps1' hide-user 1 + +# enable check-for-changes, for the ¹² indicators in git +zstyle ':vcs_info:*:powerline:*' check-for-changes true + + +### additional git info hooks + + +# Show remote ref name and number of commits ahead-of or behind ++vi-git-tracking () { + local ahead behind remote tmp + local -a formats + + # Get tracking-formats, or bail out immediately + zstyle -a ":vcs_info:${vcs}:${usercontext}:${rrn}" trackingformats formats || return 0 + + # Are we on a remote-tracking branch? + remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \ + --symbolic-full-name 2>/dev/null)/refs\/remotes\/} + + if [[ -n ${remote} ]] ; then +ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) + behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) + if (( ahead && behind )); then +zformat -f tmp $formats[3] a:$ahead b:$behind + elif (( ahead )); then +zformat -f tmp $formats[1] a:$ahead + elif (( behind )); then +zformat -f tmp $formats[2] b:$behind + fi + +hook_com[branch]+=$tmp + fi +} + +# Show count of stashed changes ++vi-git-stash () { + local -a stashes + local -a format + + zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" stashformat format || return 0 + + if [[ -n $format && -s ${hook_com[base]}/.git/refs/stash ]] ; then + # find number of stashed commits + stashes=$(git stash list 2>/dev/null | wc -l) + (( stashes )) || return 0 + + # add to misc + zformat -f tmp $format s:$stashes + hook_com[misc]+=$tmp + fi +} + +# install git hooks +zstyle ':vcs_info:git+set-message:*' hooks git-tracking git-stash + + +### lofi hook + + +# this is a hook which stops vcs_info right after the vcs detection step. +# +# this allows displaying a piece of information that the current PWD is inside +# a vcs repository and its type, without loading the heavyweight vcs data. +# +# this function was hardly tested with anything besides git, and probably has +# bugs. +# ++vi-lofi () { + + # locals + local msg basedir subdir + local -i i + local -xA hook_com + local -xa msgs + + # lofi mode enabled? + if ! zstyle -t ":vcs_info:${vcs}:${usercontext}:${PWD}" lofi ; then + # if not, just leave. + return 0 + fi + + # get lofi styles + zstyle -a ":vcs_info:${vcs}:${usercontext}:${rrn}" lofiformats msgs + + # if no lofi styles are set, better chicken out here + (( $#msgs == 0 )) && return 0 + + # git has the only detect mechanism that does not set the basedir. sheesh. + if (( $+vcs_comm[gitdir] )); then +basedir=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}} + elif (( $+vcs_comm[basedir] )); then +basedir=$vcs_comm[basedir] + else + # no set? huh. just assume it's PWD, then... + basedir=$PWD + fi + # get subdir within repo tree + subdir="$(VCS_INFO_reposub ${basedir})" + + # process the messages as usual, but with only the vcs name as %s + (( ${#msgs} > maxexports )) && msgs[$(( maxexports + 1 )),-1]=() + for i in {1..${#msgs}} ; do +if VCS_INFO_hook "set-lofi-message" $(( $i - 1 )) "${msgs[$i]}"; then +zformat -f msg ${msgs[$i]} s:${vcs} R:${basedir} S:${subdir} + msgs[$i]=${msg} + else +msgs[$i]=${hook_com[message]} + fi +done + + # this from msgs + VCS_INFO_set + + # this is the value passed back up to vcs_info, which stops further processing + ret=1 + return 1 +} + +# function which disables lofi for this particular directory +prompt-unlofi-pwd () { + # disable lofi mode for this directory and all subdirs + zstyle ":vcs_info:*:*:$PWD*" lofi false + + # if this is run as a widget, ... + if zle; then + # manually re-run all prompt precmd functions (so vcs_info is + # reevaluated as well), and reset prompt to update status. + for f in ${(M)precmd_functions#prompt_*_precmd}; $f + zle .reset-prompt + fi +} +zle -N prompt-unlofi-pwd +bindkey '^G^L' prompt-unlofi-pwd + +# lofi every directory by default +zstyle ':vcs_info:*' lofi true +# but not .zsh, that's small we always wanna see it +zstyle ":vcs_info:*:$HOME/.zsh*" lofi true +zstyle ':vcs_info-static_hooks:pre-get-data' hooks lofi + + +### actually select the prompt + +prompt powerline From f4a2f9d6e64c00df09be1aa993d7f64c25dc0c70 Mon Sep 17 00:00:00 2001 From: dongweiming Date: Tue, 25 Jun 2013 21:12:01 +0800 Subject: [PATCH 2/3] Add celery completion --- plugins/celery/_celery | 129 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 plugins/celery/_celery diff --git a/plugins/celery/_celery b/plugins/celery/_celery new file mode 100644 index 000000000..63af9fad5 --- /dev/null +++ b/plugins/celery/_celery @@ -0,0 +1,129 @@ +#compdef celery +#autoload + +#celery zsh completion + +_celery () { +local -a _1st_arguments ifargs dopts controlargs + +typeset -A opt_args + +_1st_arguments=('worker' 'events' 'beat' 'shell' 'multi' 'amqp' 'status' 'inspect' \ + 'control' 'purge' 'list' 'migrate' 'call' 'result' 'report') +ifargs=('--app=' '--broker=' '--loader=' '--config=' '--version') +dopts=('--detach' '--umask=' '--gid=' '--uid=' '--pidfile=' '--logfile=' '--loglevel=') +controlargs=('--timeout' '--destination') +_arguments \ + '(-A --app=)'{-A,--app}'[app instance to use (e.g. module.attr_name):APP]' \ + '(-b --broker=)'{-b,--broker}'[url to broker. default is "amqp://guest@localhost//":BROKER]' \ + '(--loader)--loader[name of custom loader class to use.:LOADER]' \ + '(--config)--config[Name of the configuration module:CONFIG]' \ + '(--workdir)--workdir[Optional directory to change to after detaching.:WORKING_DIRECTORY]' \ + '(-q --quiet)'{-q,--quiet}'[Don"t show as much output.]' \ + '(-C --no-color)'{-C,--no-color}'[Don"t display colors.]' \ + '(--version)--version[show program"s version number and exit]' \ + '(- : *)'{-h,--help}'[show this help message and exit]' \ + '*:: :->subcmds' && return 0 + +if (( CURRENT == 1 )); then + _describe -t commands "celery subcommand" _1st_arguments + return +fi + +case "$words[1]" in + worker) + _arguments \ + '(-C --concurrency=)'{-C,--concurrency=}'[Number of child processes processing the queue. The default is the number of CPUs.]' \ + '(--pool)--pool=:::(processes eventlet gevent threads solo)' \ + '(--purge --discard)'{--discard,--purge}'[Purges all waiting tasks before the daemon is started.]' \ + '(-f --logfile=)'{-f,--logfile=}'[Path to log file. If no logfile is specified, stderr is used.]' \ + '(--loglevel=)--loglevel=:::(critical error warning info debug)' \ + '(-N --hostname=)'{-N,--hostname=}'[Set custom hostname, e.g. "foo.example.com".]' \ + '(-B --beat)'{-B,--beat}'[Also run the celerybeat periodic task scheduler.]' \ + '(-s --schedule=)'{-s,--schedule=}'[Path to the schedule database if running with the -B option. Defaults to celerybeat-schedule.]' \ + '(-S --statedb=)'{-S,--statedb=}'[Path to the state database.Default: None]' \ + '(-E --events)'{-E,--events}'[Send events that can be captured by monitors like celeryev, celerymon, and others.]' \ + '(--time-limit=)--time-limit=[nables a hard time limit (in seconds int/float) for tasks]' \ + '(--soft-time-limit=)--soft-time-limit=[Enables a soft time limit (in seconds int/float) for tasks]' \ + '(--maxtasksperchild=)--maxtasksperchild=[Maximum number of tasks a pool worker can execute before it"s terminated and replaced by a new worker.]' \ + '(-Q --queues=)'{-Q,--queues=}'[List of queues to enable for this worker, separated by comma. By default all configured queues are enabled.]' \ + '(-I --include=)'{-I,--include=}'[Comma separated list of additional modules to import.]' \ + '(--pidfile=)--pidfile=[Optional file used to store the process pid.]' \ + '(--autoscale=)--autoscale=[Enable autoscaling by providing max_concurrency, min_concurrency.]' \ + '(--autoreload)--autoreload[Enable autoreloading.]' \ + '(--no-execv)--no-execv[Don"t do execv after multiprocessing child fork.]' + compadd -a ifargs + ;; + inspect) + _values -s \ + 'active[dump active tasks (being processed)]' \ + 'active_queues[dump queues being consumed from]' \ + 'ping[ping worker(s)]' \ + 'registered[dump of registered tasks]' \ + 'report[get bugreport info]' \ + 'reserved[dump reserved tasks (waiting to be processed)]' \ + 'revoked[dump of revoked task ids]' \ + 'scheduled[dump scheduled tasks (eta/countdown/retry)]' \ + 'stats[dump worker statistics]' + compadd -a controlargs ifargs + ;; + control) + _values -s \ + 'add_consumer[tell worker(s) to start consuming a queue]' \ + 'autoscale[change autoscale settings]' \ + 'cancel_consumer[tell worker(s) to stop consuming a queue]' \ + 'disable_events[tell worker(s) to disable events]' \ + 'enable_events[tell worker(s) to enable events]' \ + 'pool_grow[start more pool processes]' \ + 'pool_shrink[use less pool processes]' \ + 'rate_limit[tell worker(s) to modify the rate limit for a task type]' \ + 'time_limit[tell worker(s) to modify the time limit for a task type.]' + compadd -a controlargs ifargs + ;; + multi) + _values -s \ + '--nosplash[Don"t display program info.]' \ + '--verbose[Show more output.]' \ + '--no-color[Don"t display colors.]' \ + '--quiet[Don"t show as much output.]' \ + 'start' 'restart' 'stopwait' 'stop' 'show' \ + 'names' 'expand' 'get' 'kill' + compadd -a ifargs + ;; + amqp) + _values -s \ + 'queue.declare' 'queue.purge' 'exchange.delete' 'basic.publish' \ + 'exchange.declare' 'queue.delete' 'queue.bind' 'basic.get' + ;; + list) + _values -s, 'bindings' + ;; + shell) + _values -s \ + '--ipython[force iPython.]' \ + '--bpython[force bpython.]' \ + '--python[force default Python shell.]' \ + '--without-tasks[don"t add tasks to locals.]' \ + '--eventlet[use eventlet.]' \ + '--gevent[use gevent.]' + compadd -a ifargs + ;; + beat) + _arguments \ + '(-s --schedule=)'{-s,--schedule=}'[Path to the schedule database. Defaults to celerybeat-schedule.]' \ + '(-S --scheduler=)'{-S,--scheduler=}'[Scheduler class to use. Default is celery.beat.PersistentScheduler.]' \ + '(--max-interval)--max-interval[]' + compadd -a dopts fargs + ;; + events) + _arguments \ + '(-d --dump)'{-d,--dump}'[Dump events to stdout.]' \ + '(-c --camera=)'{-c,--camera=}'[Take snapshots of events using this camera.]' \ + '(-F --frequency=)'{-F,--frequency=}'[Camera: Shutter frequency. Default is every 1.0 seconds.]' \ + '(-r --maxrate=)'{-r,--maxrate=}'[Camera: Optional shutter rate limit (e.g. 10/m).]' + compadd -a dopts fargs + ;; + *) + ;; + esac +} From 152954dd95653b087027628af6bac90cf06c5dac Mon Sep 17 00:00:00 2001 From: dongweiming Date: Fri, 28 Jun 2013 11:35:48 +0800 Subject: [PATCH 3/3] The current version of bower is completely unavailable, plugin depth modification --- plugins/bower/bower.plugin.zsh | 91 +++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/plugins/bower/bower.plugin.zsh b/plugins/bower/bower.plugin.zsh index ed9c04840..68a67a3cc 100644 --- a/plugins/bower/bower.plugin.zsh +++ b/plugins/bower/bower.plugin.zsh @@ -2,37 +2,80 @@ alias bi="bower install" alias bl="bower list" alias bs="bower search" -bower_package_list='' - +_bower_installed_packages () { + bower_package_list=$(bower ls --no-color 2>/dev/null| awk 'NR>3{print p}{p=$0}'| cut -d ' ' -f 2|sed 's/#.*//') +} _bower () { - local curcontext="$curcontext" state line - typeset -A opt_args + local -a _1st_arguments _no_color _dopts _save_dev _force_lastest _production + local expl + typeset -A opt_args - _arguments -C \ - ':command:->command' \ - '*::options:->options' + _no_color=('--no-color[Do not print colors (available in all commands)]') - case $state in - (command) + _dopts=( + '(--save)--save[Save installed packages into the project"s bower.json dependencies]' + '(--force)--force[Force fetching remote resources even if a local copy exists on disk]' + ) - local -a subcommands - subcommands=(${=$(bower help | grep help | sed -e 's/,//g')}) - _describe -t commands 'bower' subcommands - ;; + _save_dev=('(--save-dev)--save-dev[Save installed packages into the project"s bower.json devDependencies]') - (options) - case $line[1] in + _force_lastest=('(--force-latest)--force-latest[Force latest version on conflict]') + + _production=('(--production)--production[Do not install project devDependencies]') + + _1st_arguments=( + 'cache-clean:Clean the Bower cache, or the specified package caches' \ + 'help:Display help information about Bower' \ + 'info:Version info and description of a particular package' \ + 'init:Interactively create a bower.json file' \ + 'install:Install a package locally' \ + 'link:Symlink a package folder' \ + 'lookup:Look up a package URL by name' \ + 'register:Register a package' \ + 'search:Search for a package by name' \ + 'uninstall:Remove a package' \ + 'update:Update a package' \ + {ls,list}:'[List all installed packages]' + ) + _arguments \ + $_no_color \ + '*:: :->subcmds' && return 0 + + if (( CURRENT == 1 )); then + _describe -t commands "bower subcommand" _1st_arguments + return + fi + + case "$words[1]" in + install) + _arguments \ + $_dopts \ + $_save_dev \ + $_force_lastest \ + $_no_color \ + $_production + ;; + update) + _arguments \ + $_dopts \ + $_no_color \ + $_force_lastest + _bower_installed_packages + compadd "$@" $(echo $bower_package_list) + ;; + uninstall) + _arguments \ + $_no_color \ + $_dopts + _bower_installed_packages + compadd "$@" $(echo $bower_package_list) + ;; + *) + $_no_color \ + ;; + esac - (install) - if [ -z "$bower_package_list" ];then - bower_package_list=$(bower search | awk 'NR > 2' | cut -d '-' -f 2 | cut -d ' ' -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g") - fi - compadd "$@" $(echo $bower_package_list) - ;; - esac - ;; - esac } compdef _bower bower