From 68b792bbb67958c726dd8ebe9cfe12f5e463d160 Mon Sep 17 00:00:00 2001 From: Michele Bologna Date: Tue, 16 Jun 2015 10:48:24 +0200 Subject: [PATCH 1/6] Change to use omz git_prompt* functions Removed references for official git __git_ps1() functions. Change to use omz function git_prompt* functions like: - git_prompt_info() -> branch name - git_prompt_status() -> check if untracked, modified, added, stashed file are in the current git repo - git_remote_status() -> check if current repo is ahead, behind, or diverged. These functions returns string automatically added to your PS1; these are customizable via exporting ZSH_THEME_GIT_PROMPT* --- themes/michelebologna.zsh-theme | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/themes/michelebologna.zsh-theme b/themes/michelebologna.zsh-theme index fec243873..110e3f203 100644 --- a/themes/michelebologna.zsh-theme +++ b/themes/michelebologna.zsh-theme @@ -59,16 +59,17 @@ ZSH_THEME_GIT_PROMPT_PREFIX="" ZSH_THEME_GIT_PROMPT_SUFFIX="" ZSH_THEME_GIT_PROMPT_DIRTY="" ZSH_THEME_GIT_PROMPT_CLEAN="" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%%" -ZSH_THEME_GIT_PROMPT_MODIFIED="*" -ZSH_THEME_GIT_PROMPT_ADDED="+" -ZSH_THEME_GIT_PROMPT_STASHED="$" -ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE="=" +ZSH_THEME_GIT_PROMPT_UNTRACKED="$blue%%" +ZSH_THEME_GIT_PROMPT_MODIFIED="$red*" +ZSH_THEME_GIT_PROMPT_ADDED="$green+" +ZSH_THEME_GIT_PROMPT_STASHED="$blue$" +ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE="$green=" ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">" ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<" -ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="<>" +ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="$red<>" PROMPT='$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)' -PROMPT+='$(__git_ps1)' +GIT_PROMPT='$(out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status);if [[ -n $out ]]; then printf %s " $white($green$out$white)$reset";fi)' +PROMPT+="$GIT_PROMPT" PROMPT+=" $last_command_output%#$reset " RPROMPT='' From 689b5ab3c8c8bf30ee63cafb8401d7d95e41f359 Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Fri, 26 Jun 2015 01:48:17 -0400 Subject: [PATCH 2/6] osx: fix tab* functions so cd works in iTerm2, exit status is correct, and error messages are not discarded. --- plugins/osx/osx.plugin.zsh | 84 ++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index a6e3a83e6..2cbb95977 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -5,29 +5,35 @@ # VERSION: 1.1.0 # ------------------------------------------------------------------------------ -function tab() { - local command="cd \\\"$PWD\\\"; clear; " - (( $# > 0 )) && command="${command}; $*" - - the_app=$( +function _omz_osx_get_frontmost_app() { + local the_app=$( osascript 2>/dev/null </dev/null < 0 )) && command="${command}; $*" + + local the_app=$(_omz_osx_get_frontmost_app) + + if [[ "$the_app" == 'Terminal' ]]; then + # Discarding stdout to quash "tab N of window id XXX" output + osascript >/dev/null </dev/null < 0 )) && command="${command}; $*" - the_app=$( - osascript 2>/dev/null </dev/null <&2 + false + + fi } function split_tab() { - local command="cd \\\"$PWD\\\"" + local command="cd \\\"$PWD\\\"; clear" (( $# > 0 )) && command="${command}; $*" - the_app=$( - osascript 2>/dev/null </dev/null <&2 + false + + fi } function pfd() { From dff03743efa3f49f4ba4b1214d97f9746bb1a0d4 Mon Sep 17 00:00:00 2001 From: Mohnish Jadwani Date: Tue, 7 Jul 2015 09:47:49 +0530 Subject: [PATCH 3/6] adds an alias to search for the rails routes that pattern match a string --- plugins/rails/rails.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/rails/rails.plugin.zsh b/plugins/rails/rails.plugin.zsh index 6824836fc..097578e23 100644 --- a/plugins/rails/rails.plugin.zsh +++ b/plugins/rails/rails.plugin.zsh @@ -58,6 +58,7 @@ alias rdmtc='rake db:migrate db:test:clone' alias rlc='rake log:clear' alias rn='rake notes' alias rr='rake routes' +alias rrg='rake routes | grep ' # legacy stuff alias sstat='thin --stats "/thin/stats" start' From 720fb5b68e186feae24c48283ded7c41b41c73fb Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 9 Jun 2015 11:07:23 +0200 Subject: [PATCH 4/6] Support for 'scw' command (Scaleway CLI) --- plugins/scw/README.md | 7 + plugins/scw/_scw | 333 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 340 insertions(+) create mode 100644 plugins/scw/README.md create mode 100644 plugins/scw/_scw diff --git a/plugins/scw/README.md b/plugins/scw/README.md new file mode 100644 index 000000000..d2312c2e5 --- /dev/null +++ b/plugins/scw/README.md @@ -0,0 +1,7 @@ +## Scaleway CLI autocomplete plugin + +[scw](https://github.com/scaleway/scaleway-cli): Manage Bare Metal servers from Command Line (as easily as with Docker) + +- Adds autocomplete options for all `scw` commands. + +Maintainer : Manfred Touron ([@moul](https://github.com/moul)) diff --git a/plugins/scw/_scw b/plugins/scw/_scw new file mode 100644 index 000000000..f9fdf916e --- /dev/null +++ b/plugins/scw/_scw @@ -0,0 +1,333 @@ +#compdef scw +# +# zsh completion for scw (http://scaleway.com) +# +# Inspired by https://github.com/felixr/docker-zsh-completion + +__scw_get_servers() { + local expl + declare -a servers + servers=(${(f)"$(_call_program commands scw _completion servers-names)"}) + _describe -t servers "servers" servers +} + +__scw_stoppedservers() { + __scw_get_servers +} + +__scw_runningservers() { + __scw_get_servers +} + +__scw_servers () { + __scw_get_servers +} + +__scw_images () { + local expl + declare -a images + images=(${(f)"$(_call_program commands scw _completion images-names)"}) + _describe -t images "images" images +} + +__scw_images_and_snapshots () { + __scw_images + __scw_snapshots +} + +__scw_snapshots () { + local expl + declare -a snapshots + snapshots=(${(f)"$(_call_program commands scw _completion --prefix snapshots-names)"}) + _describe -t snapshots "snapshots" snapshots +} + +__scw_bootscripts () { + local expl + declare -a bootscripts + bootscripts=(${(f)"$(_call_program commands scw _completion bootscripts-names)"}) + _describe -t bootscripts "bootscripts" bootscripts +} + +__scw_tags() { + __scw_images +} + +__scw_repositories_with_tags() { + __scw_images +} + +__scw_search() { + # declare -a scwsearch + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __scw_caching_policy + fi + + local searchterm cachename + searchterm="${words[$CURRENT]%/}" + cachename=_scw-search-$searchterm + + local expl + local -a result + if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ + && ! _retrieve_cache ${cachename#_}; then + _message "Searching for ${searchterm}..." + result=(${${${(f)"$(_call_program commands scw search ${searchterm})"}%% *}[2,-1]}) + _store_cache ${cachename#_} result + fi + _wanted scwsearch expl 'available images' compadd -a result +} + +__scw_caching_policy() +{ + oldp=( "$1"(Nmh+1) ) # 1 hour + (( $#oldp )) +} + + +__scw_repositories () { + __scw_images +} + +__scw_commands () { + # local -a _scw_subcommands + local cache_policy + + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __scw_caching_policy + fi + + if ( [[ ${+_scw_subcommands} -eq 0 ]] || _cache_invalid scw_subcommands) \ + && ! _retrieve_cache scw_subcommands; + then + local -a lines + lines=(${(f)"$(_call_program commands scw 2>&1)"}) + _scw_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) + _scw_subcommands=($_scw_subcommands 'help:Show help for a command') + _store_cache scw_subcommands _scw_subcommands + fi + _describe -t scw-commands "scw command" _scw_subcommands +} + +__scw_subcommand () { + local -a _command_args + case "$words[1]" in + (attach) + _arguments \ + '--no-stdin[Do not attach stdin]' \ + ':servers:__scw_runningservers' + ;; + (commit) + _arguments \ + {-v,--volume=0}'[Volume slot]:volume: ' \ + ':server:__scw_servers' \ + ':repository:__scw_repositories_with_tags' + ;; + (cp) + _arguments \ + ':server:->server' \ + ':hostpath:_files' + case $state in + (server) + if compset -P '*:'; then + _files + else + __scw_servers -qS ":" + fi + ;; + esac + ;; + (exec) + local state ret + _arguments \ + {-T,--timeout=0}'[Set timeout values to seconds]' \ + {-w,--wait}'[Wait for SSH to be ready]' \ + ':servers:__scw_runningservers' \ + '*::command:->anycommand' && ret=0 + + case $state in + (anycommand) + shift 1 words + (( CURRENT-- )) + _normal + ;; + esac + + return ret + ;; + (history) + _arguments \ + '--no-trunc[Do not truncate output]' \ + {-q,--quiet}'[Only show numeric IDs]' \ + '*:images:__scw_images' + ;; + (images) + _arguments \ + {-a,--all}'[Show all images]' \ + '--no-trunc[Do not truncate output]' \ + {-q,--quiet}'[Only show numeric IDs]' \ + ':repository:__scw_repositories' + ;; + (info) + ;; + (inspect) + _arguments \ + {-f,--format=-}'[Format the output using the given go template]:template: ' \ + '*:servers:__scw_servers' + ;; + (kill) + _arguments \ + '*:servers:__scw_runningservers' + ;; + (login) + _arguments \ + {-o,--organization=-}'[Organization]:organization: ' \ + {-t,--token=-}'[Token]:token: ' \ + ':server: ' + ;; + (logout) + _arguments \ + ':server: ' + ;; + (logs) + _arguments \ + '*:servers:__scw_servers' + ;; + (port) + _arguments \ + '1:servers:__scw_runningservers' \ + '2:port:_ports' + ;; + (start) + _arguments \ + {-T,--timeout=0}'[Set timeout values to seconds]' \ + {-w,--wait}'[Wait for SSH to be ready]' \ + '*:servers:__scw_stoppedservers' + ;; + (rm) + _arguments \ + '*:servers:__scw_stoppedservers' + ;; + (rmi) + _arguments \ + '*:images:__scw_images' + ;; + (restart) + _arguments \ + '*:servers:__scw_runningservers' + ;; + (stop) + _arguments \ + {-t,--terminate}'[Stop and trash a server with its volumes]' \ + {-w,--wait}'[Synchronous stop. Wait for server to be stopped]' \ + '*:servers:__scw_runningservers' + ;; + (top) + _arguments \ + '1:servers:__scw_runningservers' \ + '(-)*:: :->ps-arguments' + case $state in + (ps-arguments) + _ps + ;; + esac + ;; + (ps) + _arguments \ + {-a,--all}'[Show all servers. Only running servers are shown by default]' \ + {-l,--latest}'[Show only the latest created server]' \ + '-n[Show n last created servers, include non-running one]:n:(1 5 10 25 50)' \ + '--no-trunc[Do not truncate output]' \ + {-q,--quiet}'[Only show numeric IDs]' + ;; + (tag) + _arguments \ + {-f,--force}'[force]'\ + ':image:__scw_images'\ + ':repository:__scw_repositories_with_tags' + ;; + (create|run) + _arguments \ + {-a,--attach}'[Attach to stdin, stdout or stderr]' \ + '*'{-e,--environment=-}'[Set environment variables]:environment variable: ' \ + '--name=-[Server name]:name: ' \ + '--bootscript=-[Assign a bootscript]:bootscript:__scw_bootscripts ' \ + '*-v[Bind mount a volume]:volume: '\ + '(-):images:__scw_images_and_snapshots' \ + '(-):command: _command_names -e' \ + '*::arguments: _normal' + + case $state in + (link) + if compset -P '*:'; then + _wanted alias expl 'Alias' compadd -E "" + else + __scw_runningservers -qS ":" + fi + ;; + esac + ;; + (rename) + _arguments \ + ':old name:__scw_servers' \ + ':new name: ' + ;; + (search) + _arguments \ + '--no-trunc[Do not truncate output]' \ + ':term: ' + ;; + (wait) + _arguments '*:servers:__scw_runningservers' + ;; + (help) + _arguments ':subcommand:__scw_commands' + ;; + (*) + _message 'Unknown sub command' + esac + +} + +_scw () { + # Support for subservices, which allows for `compdef _scw scw-shell=_scw_servers`. + # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. + if [[ $service != scw ]]; then + _call_function - _$service + return + fi + + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -C \ + '-H[tcp://host:port to bind/connect to]:socket: ' \ + '(-): :->command' \ + '(-)*:: :->option-or-argument' + + if (( CURRENT == 1 )); then + + fi + case $state in + (command) + __scw_commands + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:scw-$words[1]: + __scw_subcommand + ;; + esac +} + +_scw "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 4 +# indent-tabs-mode: nil +# sh-basic-offset: 4 +# End: +# vim: ft=zsh sw=4 ts=4 et From 3f83331c71b9dd8b1065c4e7a58223cd7d5be421 Mon Sep 17 00:00:00 2001 From: Mohnish Jadwani Date: Mon, 17 Aug 2015 06:23:58 +0530 Subject: [PATCH 5/6] removes a trailing white space --- plugins/rails/rails.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/rails/rails.plugin.zsh b/plugins/rails/rails.plugin.zsh index 097578e23..c4ad595e7 100644 --- a/plugins/rails/rails.plugin.zsh +++ b/plugins/rails/rails.plugin.zsh @@ -58,7 +58,7 @@ alias rdmtc='rake db:migrate db:test:clone' alias rlc='rake log:clear' alias rn='rake notes' alias rr='rake routes' -alias rrg='rake routes | grep ' +alias rrg='rake routes | grep' # legacy stuff alias sstat='thin --stats "/thin/stats" start' From d009f24ac395b815287ad10db1b78b1cd9e1cf54 Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Wed, 1 Jul 2015 10:33:08 -0400 Subject: [PATCH 6/6] gnzh theme: fix "eval" and related problems. Switch to normal zsh %F/%f prompt escapes to avoid "eval" and extra variables. Wrap whole thing in anonymous function so the existing `local` statements actually work. Then switch '...' to eager "..." so stuff actually works with local variables. And local-ize the remaining variables that are used only in prompt construction. --- themes/gnzh.zsh-theme | 57 ++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/themes/gnzh.zsh-theme b/themes/gnzh.zsh-theme index ab154c1e5..04b0450a8 100644 --- a/themes/gnzh.zsh-theme +++ b/themes/gnzh.zsh-theme @@ -1,53 +1,50 @@ # ZSH Theme - Preview: http://dl.dropbox.com/u/4109351/pics/gnzh-zsh-theme.png # Based on bira theme -# load some modules -autoload -U zsh/terminfo # Used in the colour alias below setopt prompt_subst -# make some aliases for the colours: (could use normal escape sequences too) -for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do - eval PR_$color='%{$fg[${(L)color}]%}' -done -eval PR_NO_COLOR="%{$terminfo[sgr0]%}" -eval PR_BOLD="%{$terminfo[bold]%}" +() { + +local PR_USER PR_USER_OP PR_PROMPT PR_HOST # Check the UID if [[ $UID -ne 0 ]]; then # normal user - eval PR_USER='${PR_GREEN}%n${PR_NO_COLOR}' - eval PR_USER_OP='${PR_GREEN}%#${PR_NO_COLOR}' - local PR_PROMPT='$PR_NO_COLOR➤ $PR_NO_COLOR' + PR_USER='%F{green}%n%f' + PR_USER_OP='%F{green}%#%f' + PR_PROMPT='%f➤ %f' else # root - eval PR_USER='${PR_RED}%n${PR_NO_COLOR}' - eval PR_USER_OP='${PR_RED}%#${PR_NO_COLOR}' - local PR_PROMPT='$PR_RED➤ $PR_NO_COLOR' + PR_USER='%F{red}%n%f' + PR_USER_OP='%F{red}%#%f' + PR_PROMPT='%F{red}➤ %f' fi # Check if we are on SSH or not if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then - eval PR_HOST='${PR_YELLOW}%M${PR_NO_COLOR}' #SSH + PR_HOST='%F{red}%M%f' # SSH else - eval PR_HOST='${PR_GREEN}%M${PR_NO_COLOR}' # no SSH + PR_HOST='%F{green}%M%f' # no SSH fi -local return_code="%(?..%{$PR_RED%}%? ↵%{$PR_NO_COLOR%})" -local user_host='${PR_USER}${PR_CYAN}@${PR_HOST}' -local current_dir='%{$PR_BOLD$PR_BLUE%}%~%{$PR_NO_COLOR%}' +local return_code="%(?..%F{red}%? ↵%f)" + +local user_host="${PR_USER}%F{cyan}@${PR_HOST}" +local current_dir="%B%F{blue}%~%f%b" local rvm_ruby='' -if ${HOME}/.rvm/bin/rvm-prompt &> /dev/null; then # detect local user rvm installation - rvm_ruby='%{$PR_RED%}‹$(${HOME}/.rvm/bin/rvm-prompt i v g s)›%{$PR_NO_COLOR%}' -elif which rvm-prompt &> /dev/null; then # detect sysem-wide rvm installation - rvm_ruby='%{$PR_RED%}‹$(rvm-prompt i v g s)›%{$PR_NO_COLOR%}' -elif which rbenv &> /dev/null; then # detect Simple Ruby Version management - rvm_ruby='%{$PR_RED%}‹$(rbenv version | sed -e "s/ (set.*$//")›%{$PR_NO_COLOR%}' +if ${HOME}/.rvm/bin/rvm-prompt &> /dev/null; then # detect user-local rvm installation + rvm_ruby='%F{red}‹$(${HOME}/.rvm/bin/rvm-prompt i v g s)›%f' +elif which rvm-prompt &> /dev/null; then # detect system-wide rvm installation + rvm_ruby='%F{red}‹$(rvm-prompt i v g s)›%f' +elif which rbenv &> /dev/null; then # detect Simple Ruby Version Management + rvm_ruby='%F{red}‹$(rbenv version | sed -e "s/ (set.*$//")›%f' fi -local git_branch='$(git_prompt_info)%{$PR_NO_COLOR%}' +local git_branch='$(git_prompt_info)' -#PROMPT="${user_host} ${current_dir} ${rvm_ruby} ${git_branch}$PR_PROMPT " PROMPT="╭─${user_host} ${current_dir} ${rvm_ruby} ${git_branch} ╰─$PR_PROMPT " -RPS1="${return_code}" +RPROMPT="${return_code}" -ZSH_THEME_GIT_PROMPT_PREFIX="%{$PR_YELLOW%}‹" -ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$PR_NO_COLOR%}" +ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}‹" +ZSH_THEME_GIT_PROMPT_SUFFIX="› %f" + +}