1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-22 13:50:09 +00:00

Fixing conflict in rails plugin merge with rake test shortcut

This commit is contained in:
Robby Russell 2015-09-19 08:58:24 -07:00
commit 544eccb5dd
6 changed files with 422 additions and 77 deletions

View file

@ -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 <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[ "$the_app" == 'Terminal' ]] && {
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
tell application "Terminal" to do script "${command}" in front window
end tell
EOF
echo "$the_app"
}
[[ "$the_app" == 'iTerm' ]] && {
osascript 2>/dev/null <<EOF
function tab() {
# Must not have trailing semicolon, for iTerm compatibility
local command="cd \\\"$PWD\\\"; clear"
(( $# > 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 <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
end tell
tell application "Terminal" to do script "${command}" in front window
EOF
elif [[ "$the_app" == 'iTerm' ]]; then
osascript <<EOF
tell application "iTerm"
set current_terminal to current terminal
tell current_terminal
@ -35,29 +41,27 @@ EOF
set current_session to current session
tell current_session
write text "${command}"
keystroke return
end tell
end tell
end tell
EOF
}
else
echo "tab: unsupported terminal app: $the_app"
false
fi
}
function vsplit_tab() {
local command="cd \\\"$PWD\\\""
local command="cd \\\"$PWD\\\"; clear"
(( $# > 0 )) && command="${command}; $*"
the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
local the_app=$(_omz_osx_get_frontmost_app)
[[ "$the_app" == 'iTerm' ]] && {
osascript 2>/dev/null <<EOF
tell application "iTerm" to activate
if [[ "$the_app" == 'iTerm' ]]; then
osascript <<EOF
-- tell application "iTerm" to activate
tell application "System Events"
tell process "iTerm"
@ -65,26 +69,24 @@ EOF
click
end tell
end tell
keystroke "${command}; clear;"
keystroke return
keystroke "${command} \n"
end tell
EOF
}
else
echo "$0: unsupported terminal app: $the_app" >&2
false
fi
}
function split_tab() {
local command="cd \\\"$PWD\\\""
local command="cd \\\"$PWD\\\"; clear"
(( $# > 0 )) && command="${command}; $*"
the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
local the_app=$(_omz_osx_get_frontmost_app)
[[ "$the_app" == 'iTerm' ]] && {
if [[ "$the_app" == 'iTerm' ]]; then
osascript 2>/dev/null <<EOF
tell application "iTerm" to activate
@ -94,11 +96,15 @@ EOF
click
end tell
end tell
keystroke "${command}; clear;"
keystroke return
keystroke "${command} \n"
end tell
EOF
}
else
echo "$0: unsupported terminal app: $the_app" >&2
false
fi
}
function pfd() {

View file

@ -54,12 +54,13 @@ alias rdrs='rake db:reset'
alias rdtc='rake db:test:clone'
alias rdtp='rake db:test:prepare'
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 rt='rake test'
# legacy stuff
alias sstat='thin --stats "/thin/stats" start'
alias sg='ruby script/generate'

7
plugins/scw/README.md Normal file
View file

@ -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))

333
plugins/scw/_scw Normal file
View file

@ -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

View file

@ -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"
}

View file

@ -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=''