Commit e6ccd37b authored by Chris McCuller's avatar Chris McCuller
Browse files

Merge master (rebase being super annoying). Fix conflicts

parents 30ef8566 76a26a2a
......@@ -3,9 +3,9 @@
Oh My Zsh is an open source, community-driven framework for managing your [zsh](http://www.zsh.org/) configuration. That sounds boring. Let's try this again.
__Oh My Zsh is a way of life!__ Once installed, your terminal prompt will become the talk of the town _or your money back!_ Each time you interface with your command prompt, you'll be able take advantage of the hundreds of bundled plugins and pretty themes. Strangers will come up to you in cafés and ask you, _"that is amazing. are you some sort of genius?"_ Finally, you'll begin to get the sort of attention that you always felt that you deserved. ...or maybe you'll just use the time that you saved to start flossing more often.
__Oh My Zsh is a way of life!__ Once installed, your terminal prompt will become the talk of the town _or your money back!_ Each time you interact with your command prompt, you'll be able take advantage of the hundreds of bundled plugins and pretty themes. Strangers will come up to you in cafés and ask you, _"that is amazing. are you some sort of genius?"_ Finally, you'll begin to get the sort of attention that you always felt that you deserved. ...or maybe you'll just use the time that you saved to start flossing more often.
To learn more, visit http://ohmyz.sh and/or follow [ohmyzsh](https://twitter.com/ohmyzsh) on twitter.
To learn more, visit http://ohmyz.sh and/or follow [ohmyzsh](https://twitter.com/ohmyzsh) on Twitter.
## Getting Started
......@@ -43,7 +43,9 @@ If you spot a plugin (or several) that you would like to use with Oh My Zsh, you
For example, this line might begin to look like...
`plugins=(git bundler osx rake ruby)`
```shell
plugins=(git bundler osx rake ruby)
```
#### Using Plugins
......@@ -51,7 +53,7 @@ Most plugins (should! we're working on this) include a __README__, which documen
### Themes
We'll admit it. Early in the Oh My Zsh world... we may have gotten far too theme happy. We have over one hundred themes now bundled. Most of them have [screenshots](https://wiki.github.com/robbyrussell/oh-my-zsh/themes) on the wiki. Check them out!
We'll admit it. Early in the Oh My Zsh world, we may have gotten a bit too theme happy. We have over one hundred themes now bundled. Most of them have [screenshots](https://wiki.github.com/robbyrussell/oh-my-zsh/themes) on the wiki. Check them out!
#### Selecting a Theme
......@@ -59,23 +61,37 @@ _Robby's theme is the default one. It's not the fanciest one. It's not the simpl
Once you find a theme that you want to use, you will need to edit the `~/.zshrc` file. You'll see an environment variable (all caps) in there that looks like:
`ZSH_THEME="robbyrussell"`
```shell
ZSH_THEME="robbyrussell"
```
To use a different theme, simple change the value to match the name of your desired theme. For example:
To use a different theme, simply change the value to match the name of your desired theme. For example:
`ZSH_THEME="agnoster"` (this is one of the fancy ones)
```shell
ZSH_THEME="agnoster" # (this is one of the fancy ones)
```
Open up a new terminal window and your prompt should look something like...
In case you did not find a suitable theme for your needs, please have a look at the wiki for [more themes](https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes).
![Agnoster theme](https://cloud.githubusercontent.com/assets/2618447/6316862/70f58fb6-ba03-11e4-82c9-c083bf9a6574.png)
In case you did not find a suitable theme for your needs, please have a look at the wiki for [more of them](https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes).
If you're feeling feisty, you can let the computer select one randomly for you each time you open a new terminal window.
```shell
ZSH_THEME="random" # (...please let it be pie... please be some pie..)
```
## Advanced Topics
If you're the type that likes to get their hands dirty... these sections might resonate.
If you're the type that likes to get their hands dirty, these sections might resonate.
### Advanced Installation
For those who want to install this manually and/or set custom paths.
Some users may want to change the default path, or manually install Oh My Zsh.
#### Custom Directory
......@@ -83,27 +99,37 @@ The default location is `~/.oh-my-zsh` (hidden in your home directory)
If you'd like to change the install directory with the `ZSH` environment variable, either by running `export ZSH=/your/path` before installing, or by setting it before the end of the install pipeline like this:
`curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | ZSH=~/.dotfiles/zsh sh`
```shell
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | ZSH=~/.dotfiles/zsh sh
```
#### Manual Installation
##### 1. Clone the repository:
`git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh`
```shell
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
```
##### 2. *Optionally*, backup your existing @~/.zshrc@ file:
##### 2. *Optionally*, backup your existing `~/.zshrc` file:
`cp ~/.zshrc ~/.zshrc.orig`
```shell
cp ~/.zshrc ~/.zshrc.orig
```
##### 3. Create a new zsh configuration file
You can create a new zsh config file by copying the template that we included for you.
`cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc`
```shell
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
```
##### 4. Change your default shell
`chsh -s /bin/zsh`
```shell
chsh -s /bin/zsh
```
##### 5. Initialize your new zsh configuration
......@@ -120,7 +146,7 @@ If you have any hiccups installing, here are a few common fixes.
If you want to override any of the default behaviors, just add a new file (ending in `.zsh`) in the `custom/` directory.
If you have many functions that go well together, you can put them as a `abcyzeae.plugin.zsh` file in the `custom/plugins/` directory and then enable this plugin.
If you have many functions that go well together, you can put them as a `XYZ.plugin.zsh` file in the `custom/plugins/` directory and then enable this plugin.
If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`.
......@@ -128,17 +154,23 @@ If you would like to override the functionality of a plugin distributed with Oh
By default, you will be prompted to check for upgrades every few weeks. If you would like `oh-my-zsh` to automatically upgrade itself without prompting you, set the following in your `~/.zshrc`:
`DISABLE_UPDATE_PROMPT=true`
```shell
DISABLE_UPDATE_PROMPT=true
```
To disable automatic upgrades, set the following in your `~/.zshrc`:
`DISABLE_AUTO_UPDATE=true`
```shell
DISABLE_AUTO_UPDATE=true
```
### Manual Updates
If you'd like to upgrade at any point in time (maybe someone just released a new plugin and you don't want to wait a week?)... you just need to run:
If you'd like to upgrade at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run:
`upgrade_oh_my_zsh`
```shell
upgrade_oh_my_zsh
```
Magic!
......@@ -154,7 +186,7 @@ I'm far from being a [Zsh](http://www.zsh.org/) expert and suspect there are man
We also need people to test out pull-requests. So take a look through [the open issues](https://github.com/robbyrussell/oh-my-zsh/issues) and help where you can.
### Do NOT Send Us Themes
### Do NOT send us themes
We have (more than) enough themes for the time being. Please add your theme to the [external themes](https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes) wiki page.
......@@ -166,12 +198,12 @@ Thank you so much!
## Follow Us
We have an [ohmyzsh](https://twitter.com/ohmyzsh) account. You should follow it.
We have an [@ohmyzsh](https://twitter.com/ohmyzsh) Twitter account. You should follow it.
## Merchandise
We have [stickers](http://shop.planetargon.com/products/ohmyzsh-stickers-set-of-3-stickers) and [shirts](http://shop.planetargon.com/products/ohmyzsh-t-shirts) for you to show off your love of Oh My Zsh. Again, this will help you become the talk of the town!
## LICENSE
## License
Oh My Zsh is released under the [MIT license](https://github.com/robbyrussell/oh-my-zsh/blob/master/MIT-LICENSE.txt).
# Handle completions insecurities (i.e., completion-dependent directories with
# insecure ownership or permissions) by:
#
# * Human-readably notifying the user of these insecurities.
# * Moving away all existing completion caches to a temporary directory. Since
# any of these caches may have been generated from insecure directories, they
# are all suspect now. Failing to do so typically causes subsequent compinit()
# calls to fail with "command not found: compdef" errors. (That's bad.)
function handle_completion_insecurities() {
# List of the absolute paths of all unique insecure directories, split on
# newline from compaudit()'s output resembling:
#
# There are insecure directories:
# /usr/share/zsh/site-functions
# /usr/share/zsh/5.0.6/functions
# /usr/share/zsh
# /usr/share/zsh/5.0.6
#
# Since the ignorable first line is printed to stderr and thus not captured,
# stderr is squelched to prevent this output from leaking to the user.
local -aU insecure_dirs
insecure_dirs=( ${(f@):-"$(compaudit 2>/dev/null)"} )
# If no such directories exist, get us out of here.
if (( ! ${#insecure_dirs} )); then
print "[oh-my-zsh] No insecure completion-dependent directories detected."
return
fi
# List ownership and permissions of all insecure directories.
print "[oh-my-zsh] Insecure completion-dependent directories detected:"
ls -ld "${(@)insecure_dirs}"
print "[oh-my-zsh] For safety, completions will be disabled until you manually fix all"
print "[oh-my-zsh] insecure directory permissions and ownership and restart oh-my-zsh."
print "[oh-my-zsh] See the above list for directories with group or other writability.\n"
# Locally enable the "NULL_GLOB" option, thus removing unmatched filename
# globs from argument lists *AND* printing no warning when doing so. Failing
# to do so prints an unreadable warning if no completion caches exist below.
setopt local_options null_glob
# List of the absolute paths of all unique existing completion caches.
local -aU zcompdump_files
zcompdump_files=( "${ZSH_COMPDUMP}"(.) "${ZDOTDIR:-${HOME}}"/.zcompdump* )
# Move such caches to a temporary directory.
if (( ${#zcompdump_files} )); then
# Absolute path of the directory to which such files will be moved.
local ZSH_ZCOMPDUMP_BAD_DIR="${ZSH_CACHE_DIR}/zcompdump-bad"
# List such files first.
print "[oh-my-zsh] Insecure completion caches also detected:"
ls -l "${(@)zcompdump_files}"
# For safety, move rather than permanently remove such files.
print "[oh-my-zsh] Moving to \"${ZSH_ZCOMPDUMP_BAD_DIR}/\"...\n"
mkdir -p "${ZSH_ZCOMPDUMP_BAD_DIR}"
mv "${(@)zcompdump_files}" "${ZSH_ZCOMPDUMP_BAD_DIR}/"
fi
}
......@@ -58,9 +58,13 @@ zstyle ':completion:*:*:*:users' ignored-patterns \
# ... unless we really want to.
zstyle '*' single-ignored show
if [ "x$COMPLETION_WAITING_DOTS" = "xtrue" ]; then
if [[ $COMPLETION_WAITING_DOTS = true ]]; then
expand-or-complete-with-dots() {
echo -n "\e[31m......\e[0m"
# toggle line-wrapping off and back on again
[[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti rmam
print -Pn "%{%F{red}......%f%}"
[[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti smam
zle expand-or-complete
zle redisplay
}
......
# diagnostics.zsh
#
# Diagnostic and debugging support for oh-my-zsh
# omz_diagnostic_dump()
#
# Author: Andrew Janke <andrew@apjanke.net>
#
# Usage:
#
# omz_diagnostic_dump [-v] [-V] [file]
#
# NOTE: This is a work in progress. Its interface and behavior are going to change,
# and probably in non-back-compatible ways.
#
# Outputs a bunch of information about the state and configuration of
# oh-my-zsh, zsh, and the user's system. This is intended to provide a
# bunch of context for diagnosing your own or a third party's problems, and to
# be suitable for posting to public bug reports.
#
# The output is human-readable and its format may change over time. It is not
# suitable for parsing. All the output is in one single file so it can be posted
# as a gist or bug comment on GitHub. GitHub doesn't support attaching tarballs
# or other files to bugs; otherwise, this would probably have an option to produce
# tarballs that contain copies of the config and customization files instead of
# catting them all in to one file.
#
# This is intended to be widely portable, and run anywhere that oh-my-zsh does.
# Feel free to report any portability issues as bugs.
#
# This is written in a defensive style so it still works (and can detect) cases when
# basic functionality like echo and which have been redefined. In particular, almost
# everything is invoked with "builtin" or "command", to work in the face of user
# redefinitions.
#
# OPTIONS
#
# [file] Specifies the output file. If not given, a file in the current directory
# is selected automatically.
#
# -v Increase the verbosity of the dump output. May be specified multiple times.
# Verbosity levels:
# 0 - Basic info, shell state, omz configuration, git state
# 1 - (default) Adds key binding info and configuration file contents
# 2 - Adds zcompdump file contents
#
# -V Reduce the verbosity of the dump output. May be specified multiple times.
#
# TODO:
# * Multi-file capture
# * Add automatic gist uploading
# * Consider whether to move default output file location to TMPDIR. More robust
# but less user friendly.
#
function omz_diagnostic_dump() {
emulate -L zsh
builtin echo "Generating diagnostic dump; please be patient..."
local thisfcn=omz_diagnostic_dump
local -A opts
local opt_verbose opt_noverbose opt_outfile
local timestamp=$(date +%Y%m%d-%H%M%S)
local outfile=omz_diagdump_$timestamp.txt
builtin zparseopts -A opts -D -- "v+=opt_verbose" "V+=opt_noverbose"
local verbose n_verbose=${#opt_verbose} n_noverbose=${#opt_noverbose}
(( verbose = 1 + n_verbose - n_noverbose ))
if [[ ${#*} > 0 ]]; then
opt_outfile=$1
fi
if [[ ${#*} > 1 ]]; then
builtin echo "$thisfcn: error: too many arguments" >&2
return 1
fi
if [[ -n "$opt_outfile" ]]; then
outfile="$opt_outfile"
fi
# Always write directly to a file so terminal escape sequences are
# captured cleanly
_omz_diag_dump_one_big_text &> "$outfile"
if [[ $? != 0 ]]; then
builtin echo "$thisfcn: error while creating diagnostic dump; see $outfile for details"
fi
builtin echo
builtin echo Diagnostic dump file created at: "$outfile"
builtin echo
builtin echo To share this with OMZ developers, post it as a gist on GitHub
builtin echo at "https://gist.github.com" and share the link to the gist.
builtin echo
builtin echo "WARNING: This dump file contains all your zsh and omz configuration files,"
builtin echo "so don't share it publicly if there's sensitive information in them."
builtin echo
}
function _omz_diag_dump_one_big_text() {
local program programs progfile md5
builtin echo oh-my-zsh diagnostic dump
builtin echo
builtin echo $outfile
builtin echo
# Basic system and zsh information
command date
command uname -a
builtin echo OSTYPE=$OSTYPE
builtin echo ZSH_VERSION=$ZSH_VERSION
builtin echo User: $USER
builtin echo umask: $(umask)
builtin echo
_omz_diag_dump_os_specific_version
builtin echo
# Installed programs
programs=(sh zsh ksh bash sed cat grep ls find git posh)
local progfile="" extra_str="" sha_str=""
for program in $programs; do
extra_str="" sha_str=""
progfile=$(builtin which $program)
if [[ $? == 0 ]]; then
if [[ -e $progfile ]]; then
if builtin whence shasum &>/dev/null; then
sha_str=($(command shasum $progfile))
sha_str=$sha_str[1]
extra_str+=" SHA $sha_str"
fi
if [[ -h "$progfile" ]]; then
extra_str+=" ( -> ${progfile:A} )"
fi
fi
builtin printf '%-9s %-20s %s\n' "$program is" "$progfile" "$extra_str"
else
builtin echo "$program: not found"
fi
done
builtin echo
builtin echo Command Versions:
builtin echo "zsh: $(zsh --version)"
builtin echo "this zsh session: $ZSH_VERSION"
builtin echo "bash: $(bash --version | command grep bash)"
builtin echo "git: $(git --version)"
builtin echo "grep: $(grep --version)"
builtin echo
# Core command definitions
_omz_diag_dump_check_core_commands || return 1
builtin echo
# ZSH Process state
builtin echo Process state:
builtin echo pwd: $PWD
if builtin whence pstree &>/dev/null; then
builtin echo Process tree for this shell:
pstree -p $$
else
ps -fT
fi
builtin set | command grep -a '^\(ZSH\|plugins\|TERM\|LC_\|LANG\|precmd\|chpwd\|preexec\|FPATH\|TTY\|DISPLAY\|PATH\)\|OMZ'
builtin echo
#TODO: Should this include `env` instead of or in addition to `export`?
builtin echo Exported:
builtin echo $(builtin export | command sed 's/=.*//')
builtin echo
builtin echo Locale:
command locale
builtin echo
# Zsh installation and configuration
builtin echo Zsh configuration:
builtin echo setopt: $(builtin setopt)
builtin echo
builtin echo zstyle:
builtin zstyle
builtin echo
builtin echo 'compaudit output:'
compaudit
builtin echo
builtin echo '$fpath directories:'
command ls -lad $fpath
builtin echo
# Oh-my-zsh installation
builtin echo oh-my-zsh installation:
command ls -ld ~/.z*
command ls -ld ~/.oh*
builtin echo
builtin echo oh-my-zsh git state:
(cd $ZSH && builtin echo "HEAD: $(git rev-parse HEAD)" && git remote -v && git status | command grep "[^[:space:]]")
if [[ $verbose -ge 1 ]]; then
(cd $ZSH && git reflog --date=default | command grep pull)
fi
builtin echo
if [[ -e $ZSH_CUSTOM ]]; then
local custom_dir=$ZSH_CUSTOM
if [[ -h $custom_dir ]]; then
custom_dir=$(cd $custom_dir && pwd -P)
fi
builtin echo "oh-my-zsh custom dir:"
builtin echo " $ZSH_CUSTOM ($custom_dir)"
(cd ${custom_dir:h} && command find ${custom_dir:t} -name .git -prune -o -print)
builtin echo
fi
# Key binding and terminal info
if [[ $verbose -ge 1 ]]; then
builtin echo "bindkey:"
builtin bindkey
builtin echo
builtin echo "infocmp:"
command infocmp -L
builtin echo
fi
# Configuration file info
local zdotdir=${ZDOTDIR:-$HOME}
builtin echo "Zsh configuration files:"
local cfgfile cfgfiles
# Some files for bash that zsh does not use are intentionally included
# to help with diagnosing behavior differences between bash and zsh
cfgfiles=( /etc/zshenv /etc/zprofile /etc/zshrc /etc/zlogin /etc/zlogout
$zdotdir/.zshenv $zdotdir/.zprofile $zdotdir/.zshrc $zdotdir/.zlogin $zdotdir/.zlogout
~/.zsh.pre-oh-my-zsh
/etc/bashrc /etc/profile ~/.bashrc ~/.profile ~/.bash_profile ~/.bash_logout )
command ls -lad $cfgfiles 2>&1
builtin echo
if [[ $verbose -ge 1 ]]; then
for cfgfile in $cfgfiles; do
_omz_diag_dump_echo_file_w_header $cfgfile
done
fi
builtin echo
builtin echo "Zsh compdump files:"
local dumpfile dumpfiles
command ls -lad $zdotdir/.zcompdump*
dumpfiles=( $zdotdir/.zcompdump*(N) )
if [[ $verbose -ge 2 ]]; then
for dumpfile in $dumpfiles; do
_omz_diag_dump_echo_file_w_header $dumpfile
done
fi
}
function _omz_diag_dump_check_core_commands() {
builtin echo "Core command check:"
local redefined name builtins externals
redefined=()
# All the zsh non-module builtin commands
# These are taken from the zsh reference manual for 5.0.2
# Commands from modules should not be included.
# (For back-compatibility, if any of these are newish, they should be removed,
# or at least made conditional on the version of the current running zsh.)
# "history" is also excluded because OMZ is known to redefine that
builtins=( alias autoload bg bindkey break builtin bye cd chdir command
comparguments compcall compctl compdescribe compfiles compgroups compquote comptags
comptry compvalues continue declare dirs disable disown echo echotc echoti emulate
enable eval exec exit export false fc fg float functions getln getopts hash
integer jobs kill let limit local log logout noglob popd print printf
pushd pushln pwd r read readonly rehash return sched set setopt shift
source suspend test times trap true ttyctl type typeset ulimit umask unalias
unfunction unhash unlimit unset unsetopt vared wait whence where which zcompile
zle zmodload zparseopts zregexparse zstyle )
builtins_fatal=( builtin command local )
externals=( zsh )
for name in $builtins; do
if [[ $(builtin whence -w $name) != "$name: builtin" ]]; then
builtin echo "builtin '$name' has been redefined"
builtin which $name
redefined+=$name
fi
done
for name in $externals; do
if [[ $(builtin whence -w $name) != "$name: command" ]]; then
builtin echo "command '$name' has been redefined"
builtin which $name
redefined+=$name
fi
done
if [[ -n "$redefined" ]]; then
builtin echo "SOME CORE COMMANDS HAVE BEEN REDEFINED: $redefined"
else
builtin echo "All core commands are defined normally"
fi
}
function _omz_diag_dump_echo_file_w_header() {
local file=$1
if [[ ( -f $file || -h $file ) ]]; then
builtin echo "========== $file =========="
if [[ -h $file ]]; then
builtin echo "========== ( => ${file:A} ) =========="
fi
command cat $file
builtin echo "========== end $file =========="
builtin echo
elif [[ -d $file ]]; then
builtin echo "File '$file' is a directory"
elif [[ ! -e $file ]]; then
builtin echo "File '$file' does not exist"
else
command ls -lad "$file"
fi
}
function _omz_diag_dump_os_specific_version() {
local osname osver version_file version_files
case "$OSTYPE" in
darwin*)
osname=$(command sw_vers -productName)
osver=$(command sw_vers -productVersion)
builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)"
;;
cygwin)
command systeminfo | command head -4 | command tail -2
;;
esac
if builtin which lsb_release >/dev/null; then
builtin echo "OS Release: $(command lsb_release -s -d)"
fi
version_files=( /etc/*-release(N) /etc/*-version(N) /etc/*_version(N) )
for version_file in $version_files; do
builtin echo "$version_file:"
command cat "$version_file"
builtin echo
done
}
......@@ -15,6 +15,22 @@ function take() {
cd $1
}
function open_command() {
local open_cmd
# define the open command
case "$OSTYPE" in
darwin*) open_cmd="open" ;;
cygwin*) open_cmd="cygstart" ;;
linux*) open_cmd="xdg-open" ;;
*) echo "Platform $OSTYPE not supported"
return 1
;;
esac
nohup $open_cmd "$@" &>/dev/null
}
#
# Get the value of an alias.
#
......@@ -73,3 +89,135 @@ function env_default() {
env | grep -q "^$1=" && return 0
export "$1=$2" && return 3
}
# Required for $langinfo
zmodload zsh/langinfo
# URL-encode a string
#
# Encodes a string using RFC 2396 URL-encoding (%-escaped).
# See: https://www.ietf.org/rfc/rfc2396.txt
#
# By default, reserved characters and unreserved "mark" characters are
# not escaped by this function. This allows the common usage of passing
# an entire URL in, and encoding just special characters in it, with
# the expectation that reserved and mark characters are used appropriately.
# The -r and -m options turn on escaping of the reserved and mark characters,
# respectively, which allows arbitrary strings to be fully escaped for
# embedding inside URLs, where reserved characters might be misinterpreted.
#
# Prints the encoded string on stdout.
# Returns nonzero if encoding failed.
#
# Usage:
# omz_urlencode [-r] [-m] <string>
#
# -r causes reserved characters (;/?:@&=+$,) to be escaped
#
# -m causes "mark" characters (_.!~*''()-) to be escaped
#
# -P causes spaces to be encoded as '%20' instead of '+'
function omz_urlencode() {
emulate -L zsh
zparseopts -D -E -a opts r m P
local in_str=$1
local url_str=""
local spaces_as_plus
if [[ -z $opts[(r)-P] ]]; then spaces_as_plus=1; fi
local str="$in_str"
# URLs must use UTF-8 encoding; convert str to UTF-8 if required
local encoding=$langinfo[CODESET]
local safe_encodings
safe_encodings=(UTF-8 utf8 US-ASCII)
if [[ -z ${safe_encodings[(r)$encoding]} ]]; then
str=$(echo -E "$str" | iconv -f $encoding -t UTF-8)
if [[ $? != 0 ]]; then
echo "Error converting string from $encoding to UTF-8" >&2
return 1
fi
fi
# Use LC_CTYPE=C to process text byte-by-byte
local i byte ord LC_ALL=C
export LC_ALL
local reserved=';/?:@&=+$,'
local mark='_.!~*''()-'
local dont_escape="[A-Za-z0-9"
if [[ -z $opts[(r)-r] ]]; then
dont_escape+=$reserved
fi
# $mark must be last because of the "-"
if [[ -z $opts[(r)-m] ]]; then
dont_escape+=$mark
fi
dont_escape+="]"
# Implemented to use a single printf call and avoid subshells in the loop,
# for performance (primarily on Windows).
local url_str=""
for (( i = 1; i <= ${#str}; ++i )); do
byte="$str[i]"
if [[ "$byte" =~ "$dont_escape" ]]; then
url_str+="$byte"
else
if [[ "$byte" == " " && -n $spaces_as_plus ]]; then
url_str+="+"
else
ord=$(( [##16] #byte ))
url_str+="%$ord"
fi
fi
done
echo -E "$url_str"
}
# URL-decode a string
#
# Decodes a RFC 2396 URL-encoded (%-escaped) string.
# This decodes the '+' and '%' escapes in the input string, and leaves
# other characters unchanged. Does not enforce that the input is a
# valid URL-encoded string. This is a convenience to allow callers to
# pass in a full URL or similar strings and decode them for human
# presentation.
#
# Outputs the encoded string on stdout.
# Returns nonzero if encoding failed.
#
# Usage:
# omz_urldecode <urlstring> - prints decoded string followed by a newline
function omz_urldecode {
emulate -L zsh
local encoded_url=$1
# Work bytewise, since URLs escape UTF-8 octets
local caller_encoding=$langinfo[CODESET]
local LC_ALL=C
export LC_ALL
# Change + back to ' '
local tmp=${encoded_url:gs/+/ /}
# Protect other escapes to pass through the printf unchanged
tmp=${tmp:gs/\\/\\\\/}
# Handle %-escapes by turning them into `\xXX` printf escapes
tmp=${tmp:gs/%/\\x/}
local decoded
eval "decoded=\$'$tmp'"
# Now we have a UTF-8 encoded string in the variable. We need to re-encode
# it if caller is in a non-UTF-8 locale.
local safe_encodings
safe_encodings=(UTF-8 utf8 US-ASCII)
if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then
decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding)
if [[ $? != 0 ]]; then
echo "Error converting string from UTF-8 to $caller_encoding" >&2
return 1
fi
fi
echo -E "$decoded"
}
......@@ -36,7 +36,10 @@ git_remote_status() {
ahead=$(command git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
behind=$(command git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
if [ $ahead -gt 0 ] && [ $behind -eq 0 ]
if [ $ahead -eq 0 ] && [ $behind -eq 0 ]
then
echo "$ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE"
elif [ $ahead -gt 0 ] && [ $behind -eq 0 ]
then
git_remote_status="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}"
......
......@@ -7,6 +7,9 @@
# (In screen, only short_tab_title is used)
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
function title {
emulate -L zsh
setopt prompt_subst
[[ "$EMACS" == *term* ]] && return
# if $2 is unset use $1 as default
......@@ -23,9 +26,14 @@ function title {
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
# Avoid duplication of directory in terminals with independent dir display
if [[ $TERM_PROGRAM == Apple_Terminal ]]; then
ZSH_THEME_TERM_TITLE_IDLE="%n@%m"
fi
# Runs before showing the prompt
function omz_termsupport_precmd {
emulate -L zsh
if [[ $DISABLE_AUTO_TITLE == true ]]; then
return
fi
......@@ -35,15 +43,15 @@ function omz_termsupport_precmd {
# Runs before executing the command
function omz_termsupport_preexec {
emulate -L zsh
if [[ $DISABLE_AUTO_TITLE == true ]]; then
return
fi
emulate -L zsh
setopt extended_glob
# cmd name only, or if this is sudo or ssh, the next cmd
local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]:gs/%/%%}
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
local LINE="${2:gs/%/%%}"
title '$CMD' '%100>...>$LINE%<<'
......@@ -53,14 +61,28 @@ precmd_functions+=(omz_termsupport_precmd)
preexec_functions+=(omz_termsupport_preexec)
# Runs before showing the prompt, to update the current directory in Terminal.app
function omz_termsupport_cwd {
# Notify Terminal.app of current directory using undocumented OSC sequence
# found in OS X 10.9 and 10.10's /etc/bashrc
if [[ $TERM_PROGRAM == Apple_Terminal ]] && [[ -z $INSIDE_EMACS ]]; then
local PWD_URL="file://$HOSTNAME${PWD// /%20}"
printf '\e]7;%s\a' "$PWD_URL"
fi
}
# Keep Apple Terminal.app's current working directory updated
# Based on this answer: http://superuser.com/a/315029
# With extra fixes to handle multibyte chars and non-UTF-8 locales
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
# Emits the control sequence to notify Terminal.app of the cwd
function update_terminalapp_cwd() {
emulate -L zsh
# Identify the directory using a "file:" scheme URL, including
# the host name to disambiguate local vs. remote paths.
# Percent-encode the pathname.
local URL_PATH=$(omz_urlencode -P $PWD)
[[ $? != 0 ]] && return 1
local PWD_URL="file://$HOST$URL_PATH"
# Undocumented Terminal.app-specific control sequence
printf '\e]7;%s\a' $PWD_URL
}
precmd_functions+=(omz_termsupport_cwd)
# Use a precmd hook instead of a chpwd hook to avoid contaminating output
precmd_functions+=(update_terminalapp_cwd)
# Run once to get initial cwd set
update_terminalapp_cwd
fi
......@@ -11,8 +11,11 @@ then
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty'
elif [[ "$(uname -s)" == "OpenBSD" ]]; then
# On OpenBSD, test if "colorls" is installed (this one supports colors);
# otherwise, leave ls as is, because OpenBSD's ls doesn't support -G
# On OpenBSD, "gls" (ls from GNU coreutils) and "colorls" (ls from base,
# with color and multibyte support) are available from ports. "colorls"
# will be installed on purpose and can't be pulled in by installing
# coreutils, so prefer it to "gls".
gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty'
colorls -G -d . &>/dev/null 2>&1 && alias ls='colorls -G'
else
ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
......
......@@ -8,6 +8,9 @@ fi
# add a function path
fpath=($ZSH/functions $ZSH/completions $fpath)
# Load all stock functions (from $fpath files) called below.
autoload -U compaudit compinit
# Set ZSH_CUSTOM to the path where your custom config files
# and plugins exists, or else we will use the default custom/
if [[ -z "$ZSH_CUSTOM" ]]; then
......@@ -29,11 +32,6 @@ for config_file ($ZSH/lib/*.zsh); do
source $config_file
done
# Load all of your custom configurations from custom/
for config_file ($ZSH_CUSTOM/*.zsh(N)); do
source $config_file
done
unset config_file
is_plugin() {
local base_dir=$1
......@@ -64,9 +62,14 @@ if [ -z "$ZSH_COMPDUMP" ]; then
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
fi
# Load and run compinit
autoload -U compinit
compinit -i -d "${ZSH_COMPDUMP}"
# If completion insecurities exist, warn the user without enabling completions.
if ! compaudit &>/dev/null; then
# This function resides in the "lib/compfix.zsh" script sourced above.
handle_completion_insecurities
# Else, enable and cache completions to the desired file.
else
compinit -d "${ZSH_COMPDUMP}"
fi
# Load all of the plugins that were defined in ~/.zshrc
for plugin ($plugins); do
......@@ -77,6 +80,12 @@ for plugin ($plugins); do
fi
done
# Load all of your custom configurations from custom/
for config_file ($ZSH_CUSTOM/*.zsh(N)); do
source $config_file
done
unset config_file
# Load the theme
if [ "$ZSH_THEME" = "random" ]; then
themes=($ZSH/themes/*zsh-theme)
......
## atom
Plugin for Atom, a cross platform text and code editor, available for Linux, Mac OS X, and Windows.
This plugin makes "at" a useful function for invoking the Atom Editor.
Originally by Github user [aforty](https://github.com/aforty) for OSX, modified to alias 'at' to 'atom' for Linux, since atom already works on the terminal for Linux, and calling 'at' in a non-OSX environment should still work.
### Requirements
......@@ -10,8 +12,12 @@ Plugin for Atom, a cross platform text and code editor, available for Linux, Mac
* If `at` command is called without an argument, launch Atom
* If `at` is passed a directory, `cd` to it and open it in Atom
* If `at` is passed a directory, open it in Atom
* If `at` is passed a file, open it in Atom
* if `att` command is called, it is equivalent to `at .`, opening the current folder in Atom
### Examples
* Open the current dir in atom: `at .`
* Open another dir in atom: `at path/to/folder`
* Open a file: `at filename.extension`
local _atom_paths > /dev/null 2>&1
_atom_paths=(
"$HOME/Applications/Atom.app"
"/Applications/Atom.app"
)
# Gets OS Type
unamestr=$(uname -s)
for _atom_path in $_atom_paths; do
if [[ -a $_atom_path ]]; then
alias at="open -a '$_atom_path'"
break
fi
done
# If OSX
if [[ "$unamestr" == 'Darwin' ]]; then
local _atom_paths > /dev/null 2>&1
_atom_paths=(
"$HOME/Applications/Atom.app"
"/Applications/Atom.app"
)
alias att='at .'
for _atom_path in $_atom_paths; do
if [[ -a $_atom_path ]]; then
alias at="open -a '$_atom_path'"
break
fi
done
# If Linux
elif [[ "$unamestr" == 'Linux' ]]; then
# Alerts the user if 'atom' is not a found command.
type atom >/dev/null 2>&1 && alias at="atom" || { echo >&2 "You have enabled the atom oh-my-zsh plugin on Linux, but atom is not a recognized command. Please make sure you have it installed before using this plugin."; }
fi
......@@ -15,7 +15,7 @@ if [ $commands[autojump] ]; then # check if autojump is installed
. /usr/local/share/autojump/autojump.zsh
elif [ -f /opt/local/etc/profile.d/autojump.zsh ]; then # mac os x with ports
. /opt/local/etc/profile.d/autojump.zsh
elif [ $commands[brew] -a -f `brew --prefix`/etc/autojump.zsh ]; then # mac os x with brew
. `brew --prefix`/etc/autojump.zsh
elif [ $commands[brew] -a -f `brew --prefix`/etc/autojump.sh ]; then # mac os x with brew
. `brew --prefix`/etc/autojump.sh
fi
fi
......@@ -11,11 +11,16 @@ export AWS_HOME=~/.aws
function agp {
echo $AWS_DEFAULT_PROFILE
}
function asp {
local rprompt=${RPROMPT/<aws:$(agp)>/}
export AWS_DEFAULT_PROFILE=$1
export AWS_PROFILE=$1
export RPROMPT="<aws:$AWS_DEFAULT_PROFILE>$RPROMPT"
export RPROMPT="<aws:$AWS_DEFAULT_PROFILE>$rprompt"
}
function aws_profiles {
reply=($(grep profile $AWS_HOME/config|sed -e 's/.*profile \([a-zA-Z0-9_-]*\).*/\1/'))
}
......
......@@ -11,31 +11,38 @@ autoload -Uz add-zsh-hook || { print "can't add zsh hook!"; return }
## definitions ##
if ! (type bgnotify_formatted | grep -q 'function'); then
function bgnotify_formatted {
## exit_status, command, elapsed_time
[ $1 -eq 0 ] && title="#win (took $3 s)" || title="#fail (took $3 s)"
bgnotify "$title" "$2"
if ! (type bgnotify_formatted | grep -q 'function'); then ## allow custom function override
function bgnotify_formatted { ## args: (exit_status, command, elapsed_seconds)
elapsed="$(( $3 % 60 ))s"
(( $3 >= 60 )) && elapsed="$((( $3 % 3600) / 60 ))m $elapsed"
(( $3 >= 3600 )) && elapsed="$(( $3 / 3600 ))h $elapsed"
[ $1 -eq 0 ] && bgnotify "#win (took $elapsed)" "$2" || bgnotify "#fail (took $elapsed)" "$2"
}
fi
currentWindowId () {
if hash osascript 2>/dev/null; then #osx
osascript -e 'tell application (path to frontmost application as text) to id of front window' 2&> /dev/null || echo "0"
elif hash notify-send 2>/dev/null; then #ubuntu!
xprop -root | awk '/NET_ACTIVE_WINDOW/ { print $5; exit }'
elif (hash notify-send 2>/dev/null || hash kdialog 2>/dev/null); then #ubuntu!
xprop -root 2> /dev/null | awk '/NET_ACTIVE_WINDOW/{print $5;exit} END{exit !$5}' || echo "0"
else
echo $EPOCHSECONDS #fallback for windows
fi
}
bgnotify () {
bgnotify () { ## args: (title, subtitle)
if hash terminal-notifier 2>/dev/null; then #osx
terminal-notifier -message "$2" -title "$1"
[[ "$TERM_PROGRAM" == 'iTerm.app' ]] && term_id='com.googlecode.iterm2';
[[ "$TERM_PROGRAM" == 'Apple_Terminal' ]] && term_id='com.apple.terminal';
## now call terminal-notifier, (hopefully with $term_id!)
[ -z "$term_id" ] && terminal-notifier -message "$2" -title "$1" >/dev/null ||
terminal-notifier -message "$2" -title "$1" -activate "$term_id" -sender "$term_id" >/dev/null
elif hash growlnotify 2>/dev/null; then #osx growl
growlnotify -m "$1" "$2"
elif hash notify-send 2>/dev/null; then #ubuntu!
elif hash notify-send 2>/dev/null; then #ubuntu gnome!
notify-send "$1" "$2"
elif hash kdialog 2>/dev/null; then #ubuntu kde!
kdialog -title "$1" --passivepopup "$2" 5
elif hash notifu 2>/dev/null; then #cygwyn support!
notifu /m "$2" /p "$1"
fi
......@@ -46,7 +53,7 @@ bgnotify () {
bgnotify_begin() {
bgnotify_timestamp=$EPOCHSECONDS
bgnotify_lastcmd=$1
bgnotify_lastcmd="$1"
bgnotify_windowid=$(currentWindowId)
}
......@@ -63,5 +70,8 @@ bgnotify_end() {
bgnotify_timestamp=0 #reset it to 0!
}
add-zsh-hook preexec bgnotify_begin
add-zsh-hook precmd bgnotify_end
## only enable if a local (non-ssh) connection
if [ -z "$SSH_CLIENT" ] && [ -z "$SSH_TTY" ]; then
add-zsh-hook preexec bgnotify_begin
add-zsh-hook precmd bgnotify_end
fi
#compdef cap
#compdef shipit
#autoload
if [[ -f config/deploy.rb || -f Capfile ]]; then
if [[ ! -f .cap_tasks~ || config/deploy.rb -nt .cap_tasks~ ]]; then
echo "\nGenerating .cap_tasks~..." > /dev/stderr
cap -v --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~
# Added `shipit` because `cap` is a reserved word. `cap` completion doesn't work.
# http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fcap-Module
local curcontext="$curcontext" state line ret=1
local -a _configs
_arguments -C \
'1: :->cmds' \
'2:: :->args' && ret=0
_cap_tasks() {
if [[ -f config/deploy.rb || -f Capfile ]]; then
if [[ ! -f .cap_tasks~ ]]; then
shipit -v --tasks | sed 's/\(\[\)\(.*\)\(\]\)/\2:/' | awk '{command=$2; $1=$2=$3=""; gsub(/^[ \t\r\n]+/, "", $0); gsub(":", "\\:", command); print command"["$0"]"}' > .cap_tasks~
fi
OLD_IFS=$IFS
IFS=$'\n'
_values 'cap commands' $(< .cap_tasks~)
IFS=$OLD_IFS
# zmodload zsh/mapfile
# _values ${(f)mapfile[.cap_tasks~]}
fi
compadd `cat .cap_tasks~`
fi
}
_cap_stages() {
compadd $(find config/deploy -name \*.rb | cut -d/ -f3 | sed s:.rb::g)
}
case $state in
cmds)
# check if it uses multistage
if [[ -d config/deploy ]]; then
_cap_stages
else
_cap_tasks
fi
ret=0
;;
args)
_cap_tasks
ret=0
;;
esac
return ret
# Added `shipit` because `cap` is a reserved word. `cap` completion doesn't work.
# http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fcap-Module
func shipit() {
if [ -f Gemfile ]
then
bundle exec cap $*
else
cap $*
fi
}
......@@ -45,11 +45,11 @@ _source_from_omz_settings() {
zstyle -s :omz:plugins:chruby path _chruby_path
zstyle -s :omz:plugins:chruby auto _chruby_auto
if ${_chruby_path} && [[ -r ${_chruby_path} ]]; then
if [[ -r ${_chruby_path} ]]; then
source ${_chruby_path}
fi
if ${_chruby_auto} && [[ -r ${_chruby_auto} ]]; then
if [[ -r ${_chruby_auto} ]]; then
source ${_chruby_auto}
fi
}
......
#compdef codeclimate
_codeclimate_all_engines() {
engines_all=(`codeclimate engines:list | tail -n +2 | gawk '{ print $2 }' | gawk -F: '{ print $1 }'`)
}
_codeclimate_installed_engines() {
_codeclimate_all_engines
engines_installed=()
if [ -e .codeclimate.yml ]
then
for engine in $engines_all
do
if grep -q $engine ".codeclimate.yml"
then
engines_installed+=$engine
fi
done
fi
}
_codeclimate_not_installed_engines() {
_codeclimate_all_engines
engines_not_installed=()
if [ -e .codeclimate.yml ]
then
for engine in $engines_all
do
if ! grep -q $engine ".codeclimate.yml"
then
engines_not_installed+=$engine
fi
done
fi
}
local curcontext="$curcontext" state line ret=1
local expl
local -a engines_all engines_installed engines_not_installed
_arguments \
'1: :->cmds' \
'*:: :->args' && ret=0
case $state in
cmds)
_values "bundle command" \
"analyze[Analyze all relevant files in the current working directory]" \
"console[Start an interactive session providing access to the classes within the CLI]" \
"engines\:disable[Prevents the engine from being used in this project]" \
"engines\:enable[This engine will be run the next time your project is analyzed]" \
"engines\:install[Compares the list of engines in your .codeclimate.yml file to those that are currently installed, then installs any missing engines]" \
"engines\:list[Lists all available engines in the Code Climate Docker Hub]" \
"engines\:remove[Removes an engine from your .codeclimate.yml file]" \
"help[Displays a list of commands that can be passed to the Code Climate CLI]" \
"init[Generates a new .codeclimate.yml file in the current working directory]" \
"validate-config[Validates the .codeclimate.yml file in the current working directory]" \
"version[Displays the current version of the Code Climate CLI]"
ret=0
;;
args)
case $line[1] in
engines:enable)
_codeclimate_not_installed_engines
_wanted engines_not_installed expl 'not installed engines' compadd -a engines_not_installed ;;
engines:disable|engines:remove)
_codeclimate_installed_engines
_wanted engines_installed expl 'installed engines' compadd -a engines_installed ;;
analyze)
_arguments \
'-f:Output Format:(text json)'
ret=0
;;
esac
;;
esac
return ret
......@@ -2,11 +2,11 @@
# compile a string of coffeescript and print to output
cf () {
coffee -peb $1
coffee -peb "$1"
}
# compile & copy to clipboard
cfc () {
cf $1 | pbcopy
cf "$1" | pbcopy
}
# compile from pasteboard & print
......
......@@ -49,7 +49,8 @@ function push_future() {
}
# Called by zsh when directory changes
function chpwd() {
chpwd_functions+=(chpwd_dirhistory)
function chpwd_dirhistory() {
push_past $PWD
# If DIRHISTORY_CD is not set...
if [[ -z "${DIRHISTORY_CD+x}" ]]; then
......
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