Commit 18ef1ee6 authored by Dawid Ferenczy's avatar Dawid Ferenczy
Browse files

Merge remote-tracking branch 'robbyrussell/master'

parents eafd5f32 192de6bc
...@@ -5,31 +5,28 @@ zstyle ':completion::complete:wd:*:commands' group-name commands ...@@ -5,31 +5,28 @@ zstyle ':completion::complete:wd:*:commands' group-name commands
zstyle ':completion::complete:wd:*:warp_points' group-name warp_points zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
zstyle ':completion::complete:wd::' list-grouped zstyle ':completion::complete:wd::' list-grouped
# Call `_wd()` when when trying to complete the command `wd`
zmodload zsh/mapfile zmodload zsh/mapfile
function _wd() { function _wd() {
local ret=1
local CONFIG=$HOME/.warprc local CONFIG=$HOME/.warprc
local ret=1
# Stolen from
# http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands
# local curcontext="$curcontext" state line
# typeset -A opt_args
local -a commands local -a commands
local -a warp_points local -a warp_points
warp_points=( "${(f)mapfile[$CONFIG]}" )
# LIST="${mapfile[$FNAME]}" # Not required unless stuff uses it warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
commands=( commands=(
'add:Adds the current working directory to your warp points' 'add:Adds the current working directory to your warp points'
'add!:Overwrites existing warp point' 'add!:Overwrites existing warp point'
'rm:Removes the given warp point' 'rm:Removes the given warp point'
'ls:Outputs all stored warp points' 'list:Outputs all stored warp points'
'show:Outputs all warp points that point to the current directory' 'ls:Show files from given warp point'
'path:Show path to given warp point'
'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
'help:Show this extremely helpful text' 'help:Show this extremely helpful text'
'clean:Remove points warping to nonexistent directories'
'clean!:Remove nonexistent directories without confirmation'
'..:Go back to last directory' '..:Go back to last directory'
) )
...@@ -50,6 +47,15 @@ function _wd() { ...@@ -50,6 +47,15 @@ function _wd() {
add) add)
_message 'Write the name of your warp point' && ret=0 _message 'Write the name of your warp point' && ret=0
;; ;;
show)
_describe -t points "Warp points" warp_points && ret=0
;;
ls)
_describe -t points "Warp points" warp_points && ret=0
;;
path)
_describe -t points "Warp points" warp_points && ret=0
;;
esac esac
;; ;;
esac esac
......
#!/bin/zsh #!/bin/zsh
# WARP # WARP DIRECTORY
# ==== # ==============
# oh-my-zsh plugin # oh-my-zsh plugin
# #
# @github.com/mfaerevaag/wd # @github.com/mfaerevaag/wd
......
#!/bin/zsh #!/bin/zsh
# WARP # WARP DIRECTORY
# ==== # ==============
# Jump to custom directories in terminal # Jump to custom directories in terminal
# because `cd` takes too long... # because `cd` takes too long...
# #
# @github.com/mfaerevaag/wd # @github.com/mfaerevaag/wd
# version
readonly WD_VERSION=0.4
## variables # colors
CONFIG=$HOME/.warprc readonly WD_BLUE="\033[96m"
readonly WD_GREEN="\033[92m"
readonly WD_YELLOW="\033[93m"
readonly WD_RED="\033[91m"
readonly WD_NOC="\033[m"
## colors ## functions
BLUE="\033[96m"
GREEN="\033[92m"
YELLOW="\033[93m"
RED="\033[91m"
NOC="\033[m"
# helpers
wd_yesorno()
{
# variables
local question="${1}"
local prompt="${question} "
local yes_RETVAL="0"
local no_RETVAL="3"
local RETVAL=""
local answer=""
# check if config file exists # read-eval loop
if [[ ! -a $CONFIG ]] while true ; do
then printf $prompt
# if not: create config file read -r answer
touch $CONFIG
fi
## load warp points case ${answer:=${default}} in
typeset -A points Y|y|YES|yes|Yes )
while read line RETVAL=${yes_RETVAL} && \
do break
arr=(${(s,:,)line}) ;;
key=${arr[1]} N|n|NO|no|No )
val=${arr[2]} RETVAL=${no_RETVAL} && \
break
;;
* )
echo "Please provide a valid answer (y or n)"
;;
esac
done
points[$key]=$val return ${RETVAL}
done < $CONFIG }
wd_print_msg()
{
if [[ -z $wd_quiet_mode ]]
then
local color=$1
local msg=$2
## functions if [[ $color == "" || $msg == "" ]]
# prepended wd_ to not conflict with your environment (no sub shell) then
print " ${WD_RED}*${WD_NOC} Could not print message. Sorry!"
else
print " ${color}*${WD_NOC} ${msg}"
fi
fi
}
wd_print_usage()
{
cat <<- EOF
Usage: wd [command] <point>
Commands:
add <point> Adds the current working directory to your warp points
add! <point> Overwrites existing warp point
rm <point> Removes the given warp point
show Print warp points to current directory
show <point> Print path to given warp point
list Print all stored warp points
ls <point> Show files from given warp point
path <point> Show the path to given warp point
clean! Remove points warping to nonexistent directories
-v | --version Print version
-d | --debug Exit after execution with exit codes (for testing)
-c | --config Specify config file (default ~/.warprc)
-q | --quiet Suppress all output
help Show this extremely helpful text
EOF
}
wd_exit_fail()
{
local msg=$1
wd_print_msg $WD_RED $msg
WD_EXIT_CODE=1
}
wd_exit_warn()
{
local msg=$1
wd_print_msg $WD_YELLOW $msg
WD_EXIT_CODE=1
}
wd_getdir()
{
local name_arg=$1
point=$(wd_show $name_arg)
dir=${point:28+$#name_arg+7}
if [[ -z $name_arg ]]; then
wd_exit_fail "You must enter a warp point"
break
elif [[ -z $dir ]]; then
wd_exit_fail "Unknown warp point '${name_arg}'"
break
fi
}
# core
wd_warp() wd_warp()
{ {
if [[ $1 =~ "^\.+$" ]] local point=$1
if [[ $point =~ "^\.+$" ]]
then then
if [[ $#1 < 2 ]] if [ $#1 < 2 ]
then then
wd_print_msg $YELLOW "Warping to current directory?" wd_exit_warn "Warping to current directory?"
else else
(( n = $#1 - 1 )) (( n = $#1 - 1 ))
#wd_print_msg $BLUE "Warping..."
cd -$n > /dev/null cd -$n > /dev/null
fi fi
elif [[ ${points[$1]} != "" ]] elif [[ ${points[$point]} != "" ]]
then then
#wd_print_msg $BLUE "Warping..." cd ${points[$point]}
cd ${points[$1]}
else else
wd_print_msg $RED "Unkown warp point '$1'" wd_exit_fail "Unknown warp point '${point}'"
fi fi
} }
wd_add() wd_add()
{ {
if [[ $2 =~ "^\.+$" || $2 =~ "^\s*$" ]] local force=$1
local point=$2
if [[ $point =~ "^[\.]+$" ]]
then then
wd_print_msg $RED "Illegal warp point (see README)." wd_exit_fail "Warp point cannot be just dots"
elif [[ ${points[$2]} == "" ]] || $1 elif [[ $point =~ "[[:space:]]+" ]]
then then
wd_remove $2 > /dev/null wd_exit_fail "Warp point should not contain whitespace"
print "$2:$PWD" >> $CONFIG elif [[ $point == *:* ]]
wd_print_msg $GREEN "Warp point added" then
wd_exit_fail "Warp point cannot contain colons"
elif [[ $point == "" ]]
then
wd_exit_fail "Warp point cannot be empty"
elif [[ ${points[$2]} == "" ]] || $force
then
wd_remove $point > /dev/null
printf "%q:%s\n" "${point}" "${PWD}" >> $WD_CONFIG
wd_print_msg $WD_GREEN "Warp point added"
# override exit code in case wd_remove did not remove any points
# TODO: we should handle this kind of logic better
WD_EXIT_CODE=0
else else
wd_print_msg $YELLOW "Warp point '$2' already exists. Use 'add!' to overwrite." wd_exit_warn "Warp point '${point}' already exists. Use 'add!' to overwrite."
fi fi
} }
wd_remove() wd_remove()
{ {
if [[ ${points[$1]} != "" ]] local point=$1
if [[ ${points[$point]} != "" ]]
then then
if wd_tmp=`sed "/^$1:/d" $CONFIG` local config_tmp=$WD_CONFIG.tmp
if sed -n "/^${point}:.*$/!p" $WD_CONFIG > $config_tmp && mv $config_tmp $WD_CONFIG
then then
# `>!` forces overwrite wd_print_msg $WD_GREEN "Warp point removed"
# we need this if people use `setopt NO_CLOBBER`
echo $wd_tmp >! $CONFIG
wd_print_msg $GREEN "Warp point removed"
else else
wd_print_msg $RED "Warp point unsuccessfully removed. Sorry!" wd_exit_fail "Something bad happened! Sorry."
fi fi
else else
wd_print_msg $RED "Warp point was not found" wd_exit_fail "Warp point was not found"
fi fi
} }
wd_show()
{
wd_print_msg $BLUE "Warp points to current directory:"
wd_list_all | grep $PWD$
}
wd_list_all() wd_list_all()
{ {
wd_print_msg $BLUE "All warp points:" wd_print_msg $WD_BLUE "All warp points:"
while read line
while IFS= read -r line
do do
if [[ $line != "" ]] if [[ $line != "" ]]
then then
...@@ -112,58 +211,161 @@ wd_list_all() ...@@ -112,58 +211,161 @@ wd_list_all()
key=${arr[1]} key=${arr[1]}
val=${arr[2]} val=${arr[2]}
print "\t" $key "\t -> \t" $val if [[ -z $wd_quiet_mode ]]
then
printf "%20s -> %s\n" $key $val
fi
fi fi
done < $CONFIG done <<< $(sed "s:${HOME}:~:g" $WD_CONFIG)
} }
wd_print_msg() wd_ls()
{
wd_getdir $1
ls $dir
}
wd_path()
{ {
if [[ $1 == "" || $2 == "" ]] wd_getdir $1
echo $(echo $dir | sed "s:${HOME}:~:g")
}
wd_show()
{
local name_arg=$1
# if there's an argument we look up the value
if [[ ! -z $name_arg ]]
then then
print " $RED*$NOC Could not print message. Sorry!" if [[ -z $points[$name_arg] ]]
then
wd_print_msg $WD_BLUE "No warp point named $name_arg"
else
wd_print_msg $WD_GREEN "Warp point: ${WD_GREEN}$name_arg${WD_NOC} -> $points[$name_arg]"
fi
else else
print " $1*$NOC $2" # hax to create a local empty array
local wd_matches
wd_matches=()
# do a reverse lookup to check whether PWD is in $points
if [[ ${points[(r)$PWD]} == $PWD ]]
then
for name in ${(k)points}
do
if [[ $points[$name] == $PWD ]]
then
wd_matches[$(($#wd_matches+1))]=$name
fi
done
wd_print_msg $WD_BLUE "$#wd_matches warp point(s) to current directory: ${WD_GREEN}$wd_matches${WD_NOC}"
else
wd_print_msg $WD_YELLOW "No warp point to $(echo $PWD | sed "s:$HOME:~:")"
fi
fi fi
} }
wd_print_usage() wd_clean() {
{ local force=$1
print "Usage: wd [add|-a|--add] [rm|-r|--remove] [ls|-l|--list] <point>" local count=0
print "\nCommands:" local wd_tmp=""
print "\t add \t Adds the current working directory to your warp points"
print "\t add! \t Overwrites existing warp point" while read line
print "\t rm \t Removes the given warp point" do
print "\t show \t Outputs warp points to current directory" if [[ $line != "" ]]
print "\t ls \t Outputs all stored warp points" then
print "\t help \t Show this extremely helpful text" arr=(${(s,:,)line})
key=${arr[1]}
val=${arr[2]}
if [ -d "$val" ]
then
wd_tmp=$wd_tmp"\n"`echo $line`
else
wd_print_msg $WD_YELLOW "Nonexistent directory: ${key} -> ${val}"
count=$((count+1))
fi
fi
done < $WD_CONFIG
if [[ $count -eq 0 ]]
then
wd_print_msg $WD_BLUE "No warp points to clean, carry on!"
else
if $force || wd_yesorno "Removing ${count} warp points. Continue? (Y/n)"
then
echo $wd_tmp >! $WD_CONFIG
wd_print_msg $WD_GREEN "Cleanup complete. ${count} warp point(s) removed"
else
wd_print_msg $WD_BLUE "Cleanup aborted"
fi
fi
} }
local WD_CONFIG=$HOME/.warprc
local WD_QUIET=0
local WD_EXIT_CODE=0
local WD_DEBUG=0
# Parse 'meta' options first to avoid the need to have them before
# other commands. The `-D` flag consumes recognized options so that
# the actual command parsing won't be affected.
zparseopts -D -E \
c:=wd_alt_config -config:=wd_alt_config \
q=wd_quiet_mode -quiet=wd_quiet_mode \
v=wd_print_version -version=wd_print_version \
d=wd_debug_mode -debug=wd_debug_mode
if [[ ! -z $wd_print_version ]]
then
echo "wd version $WD_VERSION"
fi
## run if [[ ! -z $wd_alt_config ]]
then
WD_CONFIG=$wd_alt_config[2]
fi
# check if config file exists
if [ ! -e $WD_CONFIG ]
then
# if not, create config file
touch $WD_CONFIG
fi
# load warp points
typeset -A points
while read -r line
do
arr=(${(s,:,)line})
key=${arr[1]}
val=${arr[2]}
points[$key]=$val
done < $WD_CONFIG
# get opts # get opts
args=`getopt -o a:r:lhs -l add:,rm:,ls,help,show -- $*` args=$(getopt -o a:r:c:lhs -l add:,rm:,clean\!,list,ls:,path:,help,show -- $*)
# check if no arguments were given # check if no arguments were given, and that version is not set
if [[ $? -ne 0 || $#* -eq 0 ]] if [[ ($? -ne 0 || $#* -eq 0) && -z $wd_print_version ]]
then then
wd_print_usage wd_print_usage
# check if config file is writeable # check if config file is writeable
elif [[ ! -w $CONFIG ]] elif [ ! -w $WD_CONFIG ]
then then
wd_print_msg $RED "\'$CONFIG\' is not writeable." # do nothing
# do nothing => exit
# can't run `exit`, as this would exit the executing shell # can't run `exit`, as this would exit the executing shell
# i.e. your terminal wd_exit_fail "\'$WD_CONFIG\' is not writeable."
else else
#set -- $args # WTF
for i # parse rest of options
for o
do do
case "$i" case "$o"
in in
-a|--add|add) -a|--add|add)
wd_add false $2 wd_add false $2
...@@ -177,20 +379,36 @@ else ...@@ -177,20 +379,36 @@ else
wd_remove $2 wd_remove $2
break break
;; ;;
-l|--list|ls) -l|list)
wd_list_all wd_list_all
break break
;; ;;
-ls|ls)
wd_ls $2
break
;;
-p|--path|path)
wd_path $2
break
;;
-h|--help|help) -h|--help|help)
wd_print_usage wd_print_usage
break break
;; ;;
-s|--show|show) -s|--show|show)
wd_show wd_show $2
break
;;
-c|--clean|clean)
wd_clean false
break
;;
-c!|--clean!|clean!)
wd_clean true
break break
;; ;;
*) *)
wd_warp $i wd_warp $o
break break
;; ;;
--) --)
...@@ -200,10 +418,29 @@ else ...@@ -200,10 +418,29 @@ else
done done
fi fi
## garbage collection ## garbage collection
# if not, next time warp will pick up variables from this run # if not, next time warp will pick up variables from this run
# remember, there's no sub shell # remember, there's no sub shell
unset points
unset wd_warp
unset wd_add
unset wd_remove
unset wd_show
unset wd_list_all
unset wd_print_msg
unset wd_yesorno
unset wd_print_usage
unset wd_alt_config
unset wd_quiet_mode
unset wd_print_version
unset args unset args
unset points
unset val &> /dev/null # fixes issue #1 unset val &> /dev/null # fixes issue #1
if [[ ! -z $wd_debug_mode ]]
then
exit $WD_EXIT_CODE
else
unset wd_debug_mode
fi
# web_search from terminal # web_search from terminal
function web_search() { function web_search() {
emulate -L zsh
# get the open command
local open_cmd # define search engine URLS
if [[ $(uname -s) == 'Darwin' ]]; then typeset -A urls
open_cmd='open' urls=(
else google "https://www.google.com/search?q="
open_cmd='xdg-open' bing "https://www.bing.com/search?q="
fi yahoo "https://search.yahoo.com/search?p="
duckduckgo "https://www.duckduckgo.com/?q="
yandex "https://yandex.ru/yandsearch?text="
github "https://github.com/search?q="
baidu "https://www.baidu.com/s?wd="
)
# check whether the search engine is supported # check whether the search engine is supported
if [[ ! $1 =~ '(google|bing|yahoo|duckduckgo)' ]]; if [[ -z "$urls[$1]" ]]; then
then
echo "Search engine $1 not supported." echo "Search engine $1 not supported."
return 1 return 1
fi fi
local url="http://www.$1.com" # search or go to main page depending on number of arguments passed
if [[ $# -gt 1 ]]; then
# no keyword provided, simply open the search engine homepage # build search url:
if [[ $# -le 1 ]]; then # join arguments passed with '+', then append to search engine URL
$open_cmd "$url" url="${urls[$1]}${(j:+:)@[2,-1]}"
return
fi
if [[ $1 == 'duckduckgo' ]]; then
#slightly different search syntax for DDG
url="${url}/?q="
else else
url="${url}/search?q=" # build main page url:
# split by '/', then rejoin protocol (1) and domain (2) parts with '//'
url="${(j://:)${(s:/:)urls[$1]}[1,2]}"
fi fi
shift # shift out $1
while [[ $# -gt 0 ]]; do
url="${url}$1+"
shift
done
url="${url%?}" # remove the last '+' open_command "$url"
$open_cmd "$url"
} }
...@@ -47,6 +40,10 @@ alias bing='web_search bing' ...@@ -47,6 +40,10 @@ alias bing='web_search bing'
alias google='web_search google' alias google='web_search google'
alias yahoo='web_search yahoo' alias yahoo='web_search yahoo'
alias ddg='web_search duckduckgo' alias ddg='web_search duckduckgo'
alias yandex='web_search yandex'
alias github='web_search github'
alias baidu='web_search baidu'
#add your own !bang searches here #add your own !bang searches here
alias wiki='web_search duckduckgo \!w' alias wiki='web_search duckduckgo \!w'
alias news='web_search duckduckgo \!n' alias news='web_search duckduckgo \!n'
......
# WP-CLI
**Maintainer:** [joshmedeski](https://github.com/joshmedeski)
WordPress Command Line Interface (http://wp-cli.org/)
WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, set up multisite installs and much more, without using a web browser.
## List of Aliases
### Core
- wpcc='wp core config'
- wpcd='wp core download'
- wpci='wp core install'
- wpcii='wp core is-installed'
- wpcmc='wp core multisite-convert'
- wpcmi='wp core multisite-install'
- wpcu='wp core update'
- wpcudb='wp core update-db'
- wpcvc='wp core verify-checksums'
### Cron
- wpcre='wp cron event'
- wpcrs='wp cron schedule'
- wpcrt='wp cron test'
### Menu
- wpmc='wp menu create'
- wpmd='wp menu delete'
- wpmi='wp menu item'
- wpml='wp menu list'
- wpmlo='wp menu location'
### Plugin
- wppa='activate'
- wppda='deactivate'
- wppd='delete'
- wppg='get'
- wppi='install'
- wppis='is-installed'
- wppl='list'
- wppp='path'
- wpps='search'
- wppst='status'
- wppt='toggle'
- wppu='uninstall'
- wppu='update'
### Post
- wppoc='wp post create'
- wppod='wp post delete'
- wppoe='wp post edit'
- wppogen='wp post generate'
- wppog='wp post get'
- wppol='wp post list'
- wppom='wp post meta'
- wppou='wp post update'
- wppou='wp post url'
### Sidebar
- wpsbl='wp sidebar list'
### Theme
- wpta='wp theme activate'
- wptd='wp theme delete'
- wptdis='wp theme disable'
- wpte='wp theme enable'
- wptg='wp theme get'
- wpti='wp theme install'
- wptis='wp theme is-installed'
- wptl='wp theme list'
- wptm='wp theme mod'
- wptp='wp theme path'
- wpts='wp theme search'
- wptst='wp theme status'
- wptu='wp theme updatet'
### User
- wpuac='wp user add-cap'
- wpuar='wp user add-role'
- wpuc='wp user create'
- wpud='wp user delete'
- wpugen='wp user generate'
- wpug='wp user get'
- wpui='wp user import-csv'
- wpul='wp user list'
- wpulc='wp user list-caps'
- wpum='wp user meta'
- wpurc='wp user remove-cap'
- wpurr='wp user remove-role'
- wpusr='wp user set-role'
- wpuu='wp user update'
### Widget
- wpwa='wp widget add'
- wpwda='wp widget deactivate'
- wpwd='wp widget delete'
- wpwl='wp widget list'
- wpwm='wp widget move'
- wpwu='wp widget update'
The entire list of wp-cli commands can be found here: http://wp-cli.org/commands/
I only included the commands that are most used. Please feel free to contribute to this project if you want more commands.
# WP-CLI
# A command line interface for WordPress
# http://wp-cli.org/
# Cache
# Cap
# CLI
# Comment
# Core
alias wpcc='wp core config'
alias wpcd='wp core download'
alias wpci='wp core install'
alias wpcii='wp core is-installed'
alias wpcmc='wp core multisite-convert'
alias wpcmi='wp core multisite-install'
alias wpcu='wp core update'
alias wpcudb='wp core update-db'
alias wpcvc='wp core verify-checksums'
# Cron
alias wpcre='wp cron event'
alias wpcrs='wp cron schedule'
alias wpcrt='wp cron test'
# Db
# Eval
# Eval-File
# Export
# Help
# Import
# Media
# Menu
alias wpmc='wp menu create'
alias wpmd='wp menu delete'
alias wpmi='wp menu item'
alias wpml='wp menu list'
alias wpmlo='wp menu location'
# Network
# Option
# Plugin
alias wppa='wp plugin activate'
alias wppda='wp plugin deactivate'
alias wppd='wp plugin delete'
alias wppg='wp plugin get'
alias wppi='wp plugin install'
alias wppis='wp plugin is-installed'
alias wppl='wp plugin list'
alias wppp='wp plugin path'
alias wpps='wp plugin search'
alias wppst='wp plugin status'
alias wppt='wp plugin toggle'
alias wppu='wp plugin uninstall'
alias wppu='wp plugin update'
# Post
alias wppoc='wp post create'
alias wppod='wp post delete'
alias wppoe='wp post edit'
alias wppogen='wp post generate'
alias wppog='wp post get'
alias wppol='wp post list'
alias wppom='wp post meta'
alias wppou='wp post update'
alias wppou='wp post url'
# Rewrite
# Role
# Scaffold
# Search-Replace
# Shell
# Sidebar
alias wpsbl='wp sidebar list'
# Site
# Super-Admin
# Term
# Theme
alias wpta='wp theme activate'
alias wptd='wp theme delete'
alias wptdis='wp theme disable'
alias wpte='wp theme enable'
alias wptg='wp theme get'
alias wpti='wp theme install'
alias wptis='wp theme is-installed'
alias wptl='wp theme list'
alias wptm='wp theme mod'
alias wptp='wp theme path'
alias wpts='wp theme search'
alias wptst='wp theme status'
alias wptu='wp theme updatet'
# Transient
# User
alias wpuac='wp user add-cap'
alias wpuar='wp user add-role'
alias wpuc='wp user create'
alias wpud='wp user delete'
alias wpugen='wp user generate'
alias wpug='wp user get'
alias wpui='wp user import-csv'
alias wpul='wp user list'
alias wpulc='wp user list-caps'
alias wpum='wp user meta'
alias wpurc='wp user remove-cap'
alias wpurr='wp user remove-role'
alias wpusr='wp user set-role'
alias wpuu='wp user update'
# Widget
alias wpwa='wp widget add'
alias wpwda='wp widget deactivate'
alias wpwd='wp widget delete'
alias wpwl='wp widget list'
alias wpwm='wp widget move'
alias wpwu='wp widget update'
autoload -U +X bashcompinit && bashcompinit
# bash completion for the `wp` command
_wp_complete() {
local cur=${COMP_WORDS[COMP_CWORD]}
IFS=$'\n'; # want to preserve spaces at the end
local opts="$(wp cli completions --line="$COMP_LINE" --point="$COMP_POINT")"
if [[ "$opts" =~ \<file\>\s* ]]
then
COMPREPLY=( $(compgen -f -- $cur) )
elif [[ $opts = "" ]]
then
COMPREPLY=( $(compgen -f -- $cur) )
else
COMPREPLY=( ${opts[*]} )
fi
}
complete -o nospace -F _wp_complete wp
#xc function courtesy of http://gist.github.com/subdigital/5420709 #xc function courtesy of http://gist.github.com/subdigital/5420709
function xc { function xc {
xcode_proj=`find . -name "*.xc*" -d 1 | sort -r | head -1` xcode_proj=`ls | grep "\.xc" | sort -r | head -1`
if [[ `echo -n $xcode_proj | wc -m` == 0 ]] if [[ `echo -n $xcode_proj | wc -m` == 0 ]]
then then
echo "No xcworkspace/xcodeproj file found in the current directory." echo "No xcworkspace/xcodeproj file found in the current directory."
...@@ -16,4 +16,10 @@ function xcsel { ...@@ -16,4 +16,10 @@ function xcsel {
alias xcb='xcodebuild' alias xcb='xcodebuild'
alias xcp='xcode-select --print-path' alias xcp='xcode-select --print-path'
alias simulator='open $(xcode-select -p)/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app' alias xcdd='rm -rf ~/Library/Developer/Xcode/DerivedData/*'
if [[ -d $(xcode-select -p)/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app ]]; then
alias simulator='open $(xcode-select -p)/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app'
else
alias simulator='open $(xcode-select -p)/Applications/iOS\ Simulator.app'
fi
# Yii2 autocomplete plugin
* Adds autocomplete commands and subcommands for yii.
## Requirements
Autocomplete works from directory where your `yii` file contains.
# Yii2 command completion
_yii2_format_command () {
awk '/^- [a-z]+/ { sub(":", "", $2); print $2 }'
}
_yii2 () {
if [ -f ./yii ]; then
_arguments \
'1: :->command'\
'*: :->params'
case $state in
command)
local -a commands
local -a name
if [[ $words[2] == *\/ ]]; then
name=$words[2]
fi
commands=(${(f)"$(./yii help $name --color=0 | _yii2_format_command)"})
compadd -Q -S '' -a -- commands
esac
fi
}
compdef _yii2 yii
\ No newline at end of file
...@@ -42,12 +42,15 @@ ...@@ -42,12 +42,15 @@
* `zsw` aliases `rm .zeus.sock` * `zsw` aliases `rm .zeus.sock`
* `zweep` aliases `rm .zeus.sock` * `zweep` aliases `rm .zeus.sock`
`zdbr` aliases `zeus rake db:reset db:test:prepare` * `zdbr` aliases `zeus rake db:reset db:test:prepare`
`zdbreset` aliases `zeus rake db:reset db:test:prepare` * `zdbreset` aliases `zeus rake db:reset db:test:prepare`
`zdbm` aliases `zeus rake db:migrate db:test:prepare` * `zdbm` aliases `zeus rake db:migrate db:test:prepare`
`zdbmigrate` aliases `zeus rake db:migrate db:test:prepare` * `zdbmigrate` aliases `zeus rake db:migrate db:test:prepare`
`zdbc` aliases `zeus rake db:create` * `zdbc` aliases `zeus rake db:create`
`zdbcm` aliases `zeus rake db:create db:migrate db:test:prepare` * `zdbcm` aliases `zeus rake db:create db:migrate db:test:prepare`
## Installation
Add zeus to the plugins line of your `.zshconfig` file (e.g. `plugins=(rails git zeus)`)
...@@ -19,8 +19,8 @@ alias zsr='zeus server' ...@@ -19,8 +19,8 @@ alias zsr='zeus server'
alias zerver='zeus server' alias zerver='zeus server'
# Rake # Rake
alias zr='zeus rake' alias zr='noglob zeus rake'
alias zake='zeus rake' alias zake='noglob zeus rake'
# Generate # Generate
alias zg='zeus generate' alias zg='zeus generate'
......
# reload zshrc # reload zshrc
function src() function src()
{ {
local cache=$ZSH_CACHE_DIR
autoload -U compinit zrecompile autoload -U compinit zrecompile
compinit -d "$ZSH/cache/zcomp-$HOST" compinit -d "$cache/zcomp-$HOST"
for f in ~/.zshrc "$ZSH/cache/zcomp-$HOST"; do for f in ~/.zshrc "$cache/zcomp-$HOST"; do
zrecompile -p $f && command rm -f $f.zwc.old zrecompile -p $f && command rm -f $f.zwc.old
done done
......
...@@ -7,13 +7,13 @@ export ZSH=$HOME/.oh-my-zsh ...@@ -7,13 +7,13 @@ export ZSH=$HOME/.oh-my-zsh
# time that oh-my-zsh is loaded. # time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell" ZSH_THEME="robbyrussell"
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# Uncomment the following line to use case-sensitive completion. # Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true" # CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks. # Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true" # DISABLE_AUTO_UPDATE="true"
...@@ -26,8 +26,8 @@ ZSH_THEME="robbyrussell" ...@@ -26,8 +26,8 @@ ZSH_THEME="robbyrussell"
# Uncomment the following line to disable auto-setting terminal title. # Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true" # DISABLE_AUTO_TITLE="true"
# Uncomment the following line to disable command auto-correction. # Uncomment the following line to enable command auto-correction.
# DISABLE_CORRECTION="true" # ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion. # Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true" # COMPLETION_WAITING_DOTS="true"
...@@ -48,15 +48,16 @@ ZSH_THEME="robbyrussell" ...@@ -48,15 +48,16 @@ ZSH_THEME="robbyrussell"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse) # Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git) plugins=(git)
source $ZSH/oh-my-zsh.sh
# User configuration # User configuration
export PATH=$HOME/bin:/usr/local/bin:$PATH export PATH=$HOME/bin:/usr/local/bin:$PATH
# export MANPATH="/usr/local/man:$MANPATH" # export MANPATH="/usr/local/man:$MANPATH"
source $ZSH/oh-my-zsh.sh
# You may need to manually set your language environment # You may need to manually set your language environment
# export LANG=en_US.UTF-8 # export LANG=en_US.UTF-8
...@@ -72,3 +73,12 @@ export PATH=$HOME/bin:/usr/local/bin:$PATH ...@@ -72,3 +73,12 @@ export PATH=$HOME/bin:/usr/local/bin:$PATH
# ssh # ssh
# export SSH_KEY_PATH="~/.ssh/dsa_id" # export SSH_KEY_PATH="~/.ssh/dsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
...@@ -32,11 +32,12 @@ function check_git_prompt_info() { ...@@ -32,11 +32,12 @@ function check_git_prompt_info() {
# Determine if we are using a gemset. # Determine if we are using a gemset.
function rvm_gemset() { function rvm_gemset() {
GEMSET=`rvm gemset list | grep '=>' | cut -b4-` if hash rvm 2>/dev/null; then
if [[ -n $GEMSET ]]; then GEMSET=`rvm gemset list | grep '=>' | cut -b4-`
echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|" if [[ -n $GEMSET ]]; then
fi echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|"
fi
fi
} }
# Determine the time since last commit. If branch is clean, # Determine the time since last commit. If branch is clean,
......
...@@ -42,7 +42,7 @@ GREEN_BASE_START="${PR_RESET}${PR_GREY}>${PR_RESET}${PR_GREEN}>${PR_BRIGHT_GREEN ...@@ -42,7 +42,7 @@ GREEN_BASE_START="${PR_RESET}${PR_GREY}>${PR_RESET}${PR_GREEN}>${PR_BRIGHT_GREEN
GREEN_START_P1="${PR_RESET}${GREEN_BASE_START}${PR_RESET} " GREEN_START_P1="${PR_RESET}${GREEN_BASE_START}${PR_RESET} "
DIVISION="${PR_RESET}${PR_RED} < ${PR_RESET}" DIVISION="${PR_RESET}${PR_RED} < ${PR_RESET}"
VCS_DIRTY_COLOR="${PR_RESET}${PR_YELLOW}" VCS_DIRTY_COLOR="${PR_RESET}${PR_YELLOW}"
Vcs_CLEAN_COLOR="${PR_RESET}${PR_GREEN}" VCS_CLEAN_COLOR="${PR_RESET}${PR_GREEN}"
VCS_SUFIX_COLOR="${PR_RESET}${PR_RED}${PR_RESET}" VCS_SUFIX_COLOR="${PR_RESET}${PR_RED}${PR_RESET}"
# ########## COLOR ########### # ########## COLOR ###########
# ########## SVN ########### # ########## SVN ###########
...@@ -69,17 +69,17 @@ function precmd { ...@@ -69,17 +69,17 @@ function precmd {
#Choose from all databases, regardless of whether they are considered "offensive" #Choose from all databases, regardless of whether they are considered "offensive"
fortune -a fortune -a
} }
#obtains the tip #obtains the tip
ps1_command_tip () { ps1_command_tip () {
wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed 1d | sed '/^$/d' wget -qO - http://www.commandlinefu.com/commands/random/plaintext | sed 1d | sed '/^$/d'
} }
prompt_header () { prompt_header () {
if [[ "true" == "$ENABLE_COMMAND_TIP" ]]; then if [[ "true" == "$ENABLE_COMMAND_TIP" ]]; then
ps1_command_tip ps1_command_tip
else else
ps1_fortune ps1_fortune
fi fi
} }
PROMPT_HEAD="${RED_START}${PR_YELLOW}$(prompt_header)${PR_RESET}" PROMPT_HEAD="${RED_START}${PR_YELLOW}$(prompt_header)${PR_RESET}"
# set a simple variable to show when in screen # set a simple variable to show when in screen
if [[ -n "${WINDOW}" ]]; then if [[ -n "${WINDOW}" ]]; then
...@@ -89,9 +89,8 @@ function precmd { ...@@ -89,9 +89,8 @@ function precmd {
# Context: user@directory or just directory # Context: user@directory or just directory
prompt_context () { prompt_context () {
local user=`whoami` if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then echo -n "${PR_RESET}${PR_RED}$USER@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
echo -n "${PR_RESET}${PR_RED}$user@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
else else
echo -n "${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}" echo -n "${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
fi fi
...@@ -100,11 +99,8 @@ prompt_context () { ...@@ -100,11 +99,8 @@ prompt_context () {
set_prompt () { set_prompt () {
# required for the prompt # required for the prompt
setopt prompt_subst setopt prompt_subst
autoload colors zsh/terminfo autoload zsh/terminfo
if [[ "$terminfo[colors]" -gt 8 ]]; then
colors
fi
# ######### PROMPT ######### # ######### PROMPT #########
PROMPT='${PROMPT_HEAD} PROMPT='${PROMPT_HEAD}
${RED_START}$(prompt_context) ${RED_START}$(prompt_context)
......
...@@ -26,7 +26,13 @@ ...@@ -26,7 +26,13 @@
# A few utility functions to make it easy and re-usable to draw segmented prompts # A few utility functions to make it easy and re-usable to draw segmented prompts
CURRENT_BG='NONE' CURRENT_BG='NONE'
SEGMENT_SEPARATOR=''
# Fix odd char on mac
if [[ `uname` == 'Darwin' ]]; then
SEGMENT_SEPARATOR='\ue0b0'
else
SEGMENT_SEPARATOR=''
fi
# Begin a segment # Begin a segment
# Takes two arguments, background and foreground. Both can be omitted, # Takes two arguments, background and foreground. Both can be omitted,
...@@ -60,10 +66,8 @@ prompt_end() { ...@@ -60,10 +66,8 @@ prompt_end() {
# Context: user@hostname (who am I and where am I) # Context: user@hostname (who am I and where am I)
prompt_context() { prompt_context() {
local user=`whoami` if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m"
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
fi fi
} }
...@@ -125,10 +129,10 @@ prompt_hg() { ...@@ -125,10 +129,10 @@ prompt_hg() {
st="" st=""
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g') rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
branch=$(hg id -b 2>/dev/null) branch=$(hg id -b 2>/dev/null)
if `hg st | grep -Eq "^\?"`; then if `hg st | grep -q "^\?"`; then
prompt_segment red black prompt_segment red black
st='±' st='±'
elif `hg st | grep -Eq "^(M|A)"`; then elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black prompt_segment yellow black
st='±' st='±'
else else
......
...@@ -7,7 +7,6 @@ get_git_dirty() { ...@@ -7,7 +7,6 @@ get_git_dirty() {
} }
autoload -Uz vcs_info autoload -Uz vcs_info
autoload -U colors && colors
zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr '%F{red}*' # display this when there are unstaged changes zstyle ':vcs_info:*' unstagedstr '%F{red}*' # display this when there are unstaged changes
zstyle ':vcs_info:*' stagedstr '%F{yellow}+' # display this when there are staged changes zstyle ':vcs_info:*' stagedstr '%F{yellow}+' # display this when there are staged changes
......
...@@ -38,34 +38,32 @@ function _ruby_version() { ...@@ -38,34 +38,32 @@ function _ruby_version() {
# Determine the time since last commit. If branch is clean, # Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time. # use a neutral color, otherwise colors will vary according to time.
function _git_time_since_commit() { function _git_time_since_commit() {
if git rev-parse --git-dir > /dev/null 2>&1; then # Only proceed if there is actually a commit.
# Only proceed if there is actually a commit. if git log -1 > /dev/null 2>&1; then
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then # Get the last commit.
# Get the last commit. last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null)
last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null) now=$(date +%s)
now=$(date +%s) seconds_since_last_commit=$((now-last_commit))
seconds_since_last_commit=$((now-last_commit))
# Totals
# Totals minutes=$((seconds_since_last_commit / 60))
minutes=$((seconds_since_last_commit / 60)) hours=$((seconds_since_last_commit/3600))
hours=$((seconds_since_last_commit/3600))
# Sub-hours and sub-minutes
# Sub-hours and sub-minutes days=$((seconds_since_last_commit / 86400))
days=$((seconds_since_last_commit / 86400)) sub_hours=$((hours % 24))
sub_hours=$((hours % 24)) sub_minutes=$((minutes % 60))
sub_minutes=$((minutes % 60))
if [ $hours -gt 24 ]; then
if [ $hours -gt 24 ]; then commit_age="${days}d"
commit_age="${days}d" elif [ $minutes -gt 60 ]; then
elif [ $minutes -gt 60 ]; then commit_age="${sub_hours}h${sub_minutes}m"
commit_age="${sub_hours}h${sub_minutes}m" else
else commit_age="${minutes}m"
commit_age="${minutes}m"
fi
color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL
echo "$color$commit_age%{$reset_color%}"
fi fi
color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL
echo "$color$commit_age%{$reset_color%}"
fi fi
} }
...@@ -99,4 +97,3 @@ ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[grey]%}" ...@@ -99,4 +97,3 @@ ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[grey]%}"
export LSCOLORS="exfxcxdxbxegedabagacad" export LSCOLORS="exfxcxdxbxegedabagacad"
export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:' export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'
export GREP_COLOR='1;33' export GREP_COLOR='1;33'
# the svn plugin has to be activated for this to work. # the svn plugin has to be activated for this to work.
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)"
PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}$(svn_prompt_info)%{$reset_color%}' PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}$(svn_prompt_info)%{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%})%{$fg[yellow]%} ✗ %{$reset_color%}" ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%})%{$fg[yellow]%} ✗ %{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%}) " ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%}) "
ZSH_PROMPT_BASE_COLOR="%{$fg_bold[blue]%}" ZSH_PROMPT_BASE_COLOR="%{$fg_bold[blue]%}"
ZSH_THEME_REPO_NAME_COLOR="%{$fg_bold[red]%}" ZSH_THEME_REPO_NAME_COLOR="%{$fg_bold[red]%}"
ZSH_THEME_SVN_PROMPT_PREFIX="svn:(" ZSH_THEME_SVN_PROMPT_PREFIX="svn:("
ZSH_THEME_SVN_PROMPT_SUFFIX=")" ZSH_THEME_SVN_PROMPT_SUFFIX=")"
ZSH_THEME_SVN_PROMPT_DIRTY="%{$fg[red]%} ✘ %{$reset_color%}" ZSH_THEME_SVN_PROMPT_DIRTY="%{$fg[red]%} ✘ %{$reset_color%}"
ZSH_THEME_SVN_PROMPT_CLEAN=" " ZSH_THEME_SVN_PROMPT_CLEAN=" "
\ No newline at end of file
...@@ -31,7 +31,7 @@ bureau_git_status () { ...@@ -31,7 +31,7 @@ bureau_git_status () {
if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED" _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi fi
if $(echo "$_INDEX" | grep -E '^\?\? ' &> /dev/null); then if $(echo "$_INDEX" | command grep -E '^\?\? ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED" _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi fi
if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then
...@@ -70,7 +70,7 @@ bureau_git_prompt () { ...@@ -70,7 +70,7 @@ bureau_git_prompt () {
_PATH="%{$fg_bold[white]%}%~%{$reset_color%}" _PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
if [[ "%#" == "#" ]]; then if [[ $EUID -eq 0 ]]; then
_USERNAME="%{$fg_bold[red]%}%n" _USERNAME="%{$fg_bold[red]%}%n"
_LIBERTY="%{$fg[red]%}#" _LIBERTY="%{$fg[red]%}#"
else else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment