Unverified Commit 18ee5dff authored by Marc Cornellà's avatar Marc Cornellà Committed by GitHub
Browse files

Merge branch 'master' into clipboard

parents d81cd753 368198b7
...@@ -9,6 +9,7 @@ alias arco='arc cover' ...@@ -9,6 +9,7 @@ alias arco='arc cover'
alias arci='arc commit' alias arci='arc commit'
alias ard='arc diff' alias ard='arc diff'
alias ardc='arc diff --create'
alias ardnu='arc diff --nounit' alias ardnu='arc diff --nounit'
alias ardnupc='arc diff --nounit --plan-changes' alias ardnupc='arc diff --nounit --plan-changes'
alias ardpc='arc diff --plan-changes' alias ardpc='arc diff --plan-changes'
......
# Autoenv plugin
This plugin loads the [Autoenv](https://github.com/inishchith/autoenv).
To use it, add `autoenv` to the plugins array in your zshrc file:
```zsh
plugins=(... autoenv)
```
## Requirements
In order to make this work, you will need to have the autoenv installed.
More info on the usage and install: https://github.com/inishchith/autoenv
(( $+commands[autojump] )) || {
echo '[oh-my-zsh] Please install autojump first (https://github.com/wting/autojump)'
return
}
declare -a autojump_paths declare -a autojump_paths
autojump_paths=( autojump_paths=(
$HOME/.autojump/etc/profile.d/autojump.zsh # manual installation $HOME/.autojump/etc/profile.d/autojump.zsh # manual installation
......
...@@ -10,7 +10,8 @@ function asp() { ...@@ -10,7 +10,8 @@ function asp() {
return return
fi fi
local available_profiles=($(aws_profiles)) local -a available_profiles
available_profiles=($(aws_profiles))
if [[ -z "${available_profiles[(r)$1]}" ]]; then if [[ -z "${available_profiles[(r)$1]}" ]]; then
echo "${fg[red]}Profile '$1' not found in '${AWS_CONFIG_FILE:-$HOME/.aws/config}'" >&2 echo "${fg[red]}Profile '$1' not found in '${AWS_CONFIG_FILE:-$HOME/.aws/config}'" >&2
echo "Available profiles: ${(j:, :)available_profiles:-no profiles found}${reset_color}" >&2 echo "Available profiles: ${(j:, :)available_profiles:-no profiles found}${reset_color}" >&2
......
...@@ -7,23 +7,25 @@ ...@@ -7,23 +7,25 @@
# Email: neuralsandwich@gmail.com # # Email: neuralsandwich@gmail.com #
# Modified to add support for Apple Mac # # Modified to add support for Apple Mac #
########################################### ###########################################
# Author: J (927589452) #
# Modified to add support for FreeBSD #
###########################################
if [[ "$OSTYPE" = darwin* ]] ; then if [[ "$OSTYPE" = darwin* ]]; then
function battery_pct() { function battery_is_charging() {
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes'
typeset -F maxcapacity=$(echo $smart_battery_status | grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //')
typeset -F currentcapacity=$(echo $smart_battery_status | grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //')
integer i=$(((currentcapacity/maxcapacity) * 100))
echo $i
} }
function plugged_in() { function battery_pct() {
[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ] local battery_status="$(ioreg -rc AppleSmartBattery)"
local -i capacity=$(sed -n -e '/MaxCapacity/s/^.*"MaxCapacity"\ =\ //p' <<< $battery_status)
local -i current=$(sed -n -e '/CurrentCapacity/s/^.*"CurrentCapacity"\ =\ //p' <<< $battery_status)
echo $(( current * 100 / capacity ))
} }
function battery_pct_remaining() { function battery_pct_remaining() {
if plugged_in ; then if battery_is_charging; then
echo "External Power" echo "External Power"
else else
battery_pct battery_pct
...@@ -32,9 +34,9 @@ if [[ "$OSTYPE" = darwin* ]] ; then ...@@ -32,9 +34,9 @@ if [[ "$OSTYPE" = darwin* ]] ; then
function battery_time_remaining() { function battery_time_remaining() {
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then
timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //') timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
if [ $timeremaining -gt 720 ] ; then if [ $timeremaining -gt 720 ]; then
echo "::" echo "::"
else else
echo "~$((timeremaining / 60)):$((timeremaining % 60))" echo "~$((timeremaining / 60)):$((timeremaining % 60))"
...@@ -45,39 +47,36 @@ if [[ "$OSTYPE" = darwin* ]] ; then ...@@ -45,39 +47,36 @@ if [[ "$OSTYPE" = darwin* ]] ; then
} }
function battery_pct_prompt () { function battery_pct_prompt () {
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then local battery_pct color
b=$(battery_pct_remaining) if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then
if [ $b -gt 50 ] ; then battery_pct=$(battery_pct_remaining)
if [[ $battery_pct -gt 50 ]]; then
color='green' color='green'
elif [ $b -gt 20 ] ; then elif [[ $battery_pct -gt 20 ]]; then
color='yellow' color='yellow'
else else
color='red' color='red'
fi fi
echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}" echo "%{$fg[$color]%}[${battery_pct}%%]%{$reset_color%}"
else else
echo "∞" echo "∞"
fi fi
} }
function battery_is_charging() { elif [[ "$OSTYPE" = freebsd* ]]; then
[[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]]
}
elif [[ "$OSTYPE" = linux* ]] ; then
function battery_is_charging() { function battery_is_charging() {
! [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] [[ $(sysctl -n hw.acpi.battery.state) -eq 2 ]]
} }
function battery_pct() { function battery_pct() {
if (( $+commands[acpi] )) ; then if (( $+commands[sysctl] )); then
echo "$(acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')" sysctl -n hw.acpi.battery.life
fi fi
} }
function battery_pct_remaining() { function battery_pct_remaining() {
if [ ! $(battery_is_charging) ] ; then if ! battery_is_charging; then
battery_pct battery_pct
else else
echo "External Power" echo "External Power"
...@@ -85,76 +84,128 @@ elif [[ "$OSTYPE" = linux* ]] ; then ...@@ -85,76 +84,128 @@ elif [[ "$OSTYPE" = linux* ]] ; then
} }
function battery_time_remaining() { function battery_time_remaining() {
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then local remaining_time
echo $(acpi 2>/dev/null | cut -f3 -d ',') remaining_time=$(sysctl -n hw.acpi.battery.time)
if [[ $remaining_time -ge 0 ]]; then
((hour = $remaining_time / 60 ))
((minute = $remaining_time % 60 ))
printf %02d:%02d $hour $minute
fi fi
} }
function battery_pct_prompt() { function battery_pct_prompt() {
b=$(battery_pct_remaining) local battery_pct color
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then battery_pct=$(battery_pct_remaining)
if [ $b -gt 50 ] ; then if battery_is_charging; then
echo "∞"
else
if [[ $battery_pct -gt 50 ]]; then
color='green' color='green'
elif [ $b -gt 20 ] ; then elif [[ $battery_pct -gt 20 ]]; then
color='yellow' color='yellow'
else else
color='red' color='red'
fi fi
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}" echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
else fi
echo "∞" }
elif [[ "$OSTYPE" = linux* ]]; then
function battery_is_charging() {
! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging'
}
function battery_pct() {
if (( $+commands[acpi] )); then
acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -E '^Battery.*(Disc|C)harging' | cut -f2 -d ',' | tr -cd '[:digit:]'
fi fi
} }
else
# Empty functions so we don't cause errors in prompts
function battery_pct_remaining() { function battery_pct_remaining() {
if ! battery_is_charging; then
battery_pct
else
echo "External Power"
fi
} }
function battery_time_remaining() { function battery_time_remaining() {
if ! battery_is_charging; then
acpi 2>/dev/null | command grep -v "rate information unavailable" | cut -f3 -d ','
fi
} }
function battery_pct_prompt() { function battery_pct_prompt() {
local battery_pct color
battery_pct=$(battery_pct_remaining)
if battery_is_charging; then
echo "∞"
else
if [[ $battery_pct -gt 50 ]]; then
color='green'
elif [[ $battery_pct -gt 20 ]]; then
color='yellow'
else
color='red'
fi
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
fi
} }
else
# Empty functions so we don't cause errors in prompts
function battery_is_charging { false }
function battery_pct \
battery_pct_remaining \
battery_time_remaining \
battery_pct_prompt { }
fi fi
function battery_level_gauge() { function battery_level_gauge() {
local gauge_slots=${BATTERY_GAUGE_SLOTS:-10}; local gauge_slots=${BATTERY_GAUGE_SLOTS:-10}
local green_threshold=${BATTERY_GREEN_THRESHOLD:-6}; local green_threshold=${BATTERY_GREEN_THRESHOLD:-$(( gauge_slots * 0.6 ))}
local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-4}; local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-$(( gauge_slots * 0.4 ))}
local color_green=${BATTERY_COLOR_GREEN:-%F{green}}; local color_green=${BATTERY_COLOR_GREEN:-%F{green}}
local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}}; local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}}
local color_red=${BATTERY_COLOR_RED:-%F{red}}; local color_red=${BATTERY_COLOR_RED:-%F{red}}
local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}}; local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}}
local battery_prefix=${BATTERY_GAUGE_PREFIX:-'['}; local battery_prefix=${BATTERY_GAUGE_PREFIX:-'['}
local battery_suffix=${BATTERY_GAUGE_SUFFIX:-']'}; local battery_suffix=${BATTERY_GAUGE_SUFFIX:-']'}
local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'▶'}; local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'▶'}
local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-'▷'}; local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-'▷'}
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}; local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'}; local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'}
local battery_remaining_percentage=$(battery_pct); local battery_remaining_percentage=$(battery_pct)
local filled empty gauge_color
if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then
local filled=$(((( $battery_remaining_percentage + $gauge_slots - 1) / $gauge_slots))); filled=$(( ($battery_remaining_percentage * $gauge_slots) / 100 ))
local empty=$(($gauge_slots - $filled)); empty=$(( $gauge_slots - $filled ))
if [[ $filled -gt $green_threshold ]]; then local gauge_color=$color_green; if [[ $filled -gt $green_threshold ]]; then
elif [[ $filled -gt $yellow_threshold ]]; then local gauge_color=$color_yellow; gauge_color=$color_green
else local gauge_color=$color_red; elif [[ $filled -gt $yellow_threshold ]]; then
gauge_color=$color_yellow
else
gauge_color=$color_red
fi fi
else else
local filled=$gauge_slots; filled=$gauge_slots
local empty=0; empty=0
filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'}; filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'}
fi fi
local charging=' ' && battery_is_charging && charging=$charging_symbol; local charging=' '
battery_is_charging && charging=$charging_symbol
# Charging status and prefix
printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%} printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%}
printf ${filled_symbol//\%/\%\%}'%.0s' {1..$filled} # Filled slots
[[ $filled -gt 0 ]] && printf ${filled_symbol//\%/\%\%}'%.0s' {1..$filled}
# Empty slots
[[ $filled -lt $gauge_slots ]] && printf ${empty_symbol//\%/\%\%}'%.0s' {1..$empty} [[ $filled -lt $gauge_slots ]] && printf ${empty_symbol//\%/\%\%}'%.0s' {1..$empty}
# Suffix
printf ${color_reset//\%/\%\%}${battery_suffix//\%/\%\%}${color_reset//\%/\%\%} printf ${color_reset//\%/\%\%}${battery_suffix//\%/\%\%}${color_reset//\%/\%\%}
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- adds completion for basic bundler commands - adds completion for basic bundler commands
- adds short aliases for common bundler commands - adds short aliases for common bundler commands
- `be` aliased to `bundle exec`. - `be` aliased to `bundle exec`.
It also supports aliases (if `rs` is `rails server`, `be rs` will bundle-exec `rails server`). It also supports aliases (if `rs` is `rails server`, `be rs` will bundle-exec `rails server`).
- `bl` aliased to `bundle list` - `bl` aliased to `bundle list`
- `bp` aliased to `bundle package` - `bp` aliased to `bundle package`
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
- calls `bundle exec <gem executable>` otherwise - calls `bundle exec <gem executable>` otherwise
Common gems wrapped by default (by name of the executable): Common gems wrapped by default (by name of the executable):
`annotate`, `cap`, `capify`, `cucumber`, `foodcritic`, `guard`, `hanami`, `irb`, `jekyll`, `kitchen`, `knife`, `middleman`, `nanoc`, `pry`, `puma`, `rackup`, `rainbows`, `rake`, `rspec`, `shotgun`, `sidekiq`, `spec`, `spork`, `spring`, `strainer`, `tailor`, `taps`, `thin`, `thor`, `unicorn` and `unicorn_rails`. `annotate`, `cap`, `capify`, `cucumber`, `foodcritic`, `guard`, `hanami`, `irb`, `jekyll`, `kitchen`, `knife`, `middleman`, `nanoc`, `pry`, `puma`, `rackup`, `rainbows`, `rake`, `rspec`, `rubocop`, `shotgun`, `sidekiq`, `spec`, `spork`, `spring`, `strainer`, `tailor`, `taps`, `thin`, `thor`, `unicorn` and `unicorn_rails`.
## Configuration ## Configuration
...@@ -42,7 +42,7 @@ This will exclude the `foreman` and `spin` gems (i.e. their executable) from bei ...@@ -42,7 +42,7 @@ This will exclude the `foreman` and `spin` gems (i.e. their executable) from bei
## Excluded gems ## Excluded gems
These gems should not be called with `bundle exec`. Please see [issue #2923](https://github.com/robbyrussell/oh-my-zsh/pull/2923) on GitHub for clarification. These gems should not be called with `bundle exec`. Please see [issue #2923](https://github.com/ohmyzsh/ohmyzsh/pull/2923) on GitHub for clarification.
`berks` `berks`
`foreman` `foreman`
......
...@@ -27,6 +27,7 @@ bundled_commands=( ...@@ -27,6 +27,7 @@ bundled_commands=(
rainbows rainbows
rake rake
rspec rspec
rubocop
shotgun shotgun
sidekiq sidekiq
spec spec
...@@ -81,7 +82,7 @@ _bundler-installed() { ...@@ -81,7 +82,7 @@ _bundler-installed() {
_within-bundled-project() { _within-bundled-project() {
local check_dir="$PWD" local check_dir="$PWD"
while [ "$check_dir" != "/" ]; do while [ "$check_dir" != "/" ]; do
[ -f "$check_dir/Gemfile" ] && return [ -f "$check_dir/Gemfile" -o -f "$check_dir/gems.rb" ] && return
check_dir="$(dirname $check_dir)" check_dir="$(dirname $check_dir)"
done done
false false
...@@ -94,7 +95,7 @@ _binstubbed() { ...@@ -94,7 +95,7 @@ _binstubbed() {
_run-with-bundler() { _run-with-bundler() {
if _bundler-installed && _within-bundled-project; then if _bundler-installed && _within-bundled-project; then
if _binstubbed $1; then if _binstubbed $1; then
./bin/$@ ./bin/${^^@}
else else
bundle exec $@ bundle exec $@
fi fi
......
# Bwana
This plugin provides a function to open `man` pages directly with [Bwana](https://www.bruji.com/bwana/).
To use it add bwana to the plugins array in your zshrc file.
```bash
plugins=(... bwana)
```
The `bwana` function opens the man page of the passed argument in the Bwana app.
For example: `bwana ln` opens the man page for `ln` in Bwana.
#
# Requires https://www.bruji.com/bwana/
#
if [[ -e /Applications/Bwana.app ]] ||
( system_profiler -detailLevel mini SPApplicationsDataType | grep -q Bwana )
then
function bwana() {
open "man:$1"
}
else
echo "Bwana lets you read man files in Safari through a man: URI scheme"
echo "To use it within Zsh, install it from https://www.bruji.com/bwana/"
fi
# cakephp3 plugin
The plugin adds aliases and autocompletion for [cakephp3](https://book.cakephp.org/3.0/en/index.html).
To use it, add `cakephp3` to the plugins array of your zshrc file:
```
plugins=(... cakephp3)
```
## Aliases
| Alias | Command |
|-----------|-------------------------------|
| c3 | `bin/cake` |
| c3cache | `bin/cake orm_cache clear` |
| c3migrate | `bin/cake migrations migrate` |
...@@ -2,489 +2,367 @@ ...@@ -2,489 +2,367 @@
autoload -U regexp-replace autoload -U regexp-replace
zstyle -T ':completion:*:*:cargo:*' tag-order && \
zstyle ':completion:*:*:cargo:*' tag-order 'common-commands'
_cargo() { _cargo() {
local context state state_descr line local curcontext="$curcontext" ret=1
typeset -A opt_args local -a command_scope_spec common parallel features msgfmt triple target registry
local -a state line state_descr # These are set by _arguments
# leading items in parentheses are an exclusion list for the arguments following that arg typeset -A opt_args
# See: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions
# - => exclude all other options common=(
# 1 => exclude positional arg 1 '(-q --quiet)*'{-v,--verbose}'[use verbose output]'
# * => exclude all other args '(-q --quiet -v --verbose)'{-q,--quiet}'[no output printed to stdout]'
# +blah => exclude +blah '-Z+[pass unstable (nightly-only) flags to cargo]: :_cargo_unstable_flags'
_arguments \ '--frozen[require that Cargo.lock and cache are up-to-date]'
'(- 1 *)'{-h,--help}'[show help message]' \ '--locked[require that Cargo.lock is up-to-date]'
'(- 1 *)--list[list installed commands]' \ '--color=[specify colorization option]:coloring:(auto always never)'
'(- 1 *)'{-V,--version}'[show version information]' \ '(- 1 *)'{-h,--help}'[show help message]'
{-v,--verbose}'[use verbose output]' \ )
--color'[colorization option]' \
'(+beta +nightly)+stable[use the stable toolchain]' \ # leading items in parentheses are an exclusion list for the arguments following that arg
'(+stable +nightly)+beta[use the beta toolchain]' \ # See: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions
'(+stable +beta)+nightly[use the nightly toolchain]' \ # - => exclude all other options
'1: :->command' \ # 1 => exclude positional arg 1
'*:: :->args' # * => exclude all other args
# +blah => exclude +blah
case $state in _arguments -s -S -C $common \
command) '(- 1 *)--list[list installed commands]' \
_alternative 'common-commands:common:_cargo_cmds' 'all-commands:all:_cargo_all_cmds' '(- 1 *)--explain=[provide a detailed explanation of an error message]:error code' \
;; '(- 1 *)'{-V,--version}'[show version information]' \
'(+beta +nightly)+stable[use the stable toolchain]' \
args) '(+stable +nightly)+beta[use the beta toolchain]' \
case $words[1] in '(+stable +beta)+nightly[use the nightly toolchain]' \
bench) '1: :_cargo_cmds' \
_arguments \ '*:: :->args'
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \ # These flags are mutually exclusive specifiers for the scope of a command; as
'(-h, --help)'{-h,--help}'[show help message]' \ # they are used in multiple places without change, they are expanded into the
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ # appropriate command's `_arguments` where appropriate.
"${command_scope_spec[@]}" \ command_scope_spec=(
'--manifest-path=[path to manifest]: :_files -/' \ '(--bin --example --test --lib)--bench=[specify benchmark name]: :_cargo_benchmark_names'
'--no-default-features[do not build the default features]' \ '(--bench --bin --test --lib)--example=[specify example name]:example name'
'--no-run[compile but do not run]' \ '(--bench --example --test --lib)--bin=[specify binary name]:binary name'
'(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \ '(--bench --bin --example --test)--lib=[specify library name]:library name'
'--target=[target triple]' \ '(--bench --bin --example --lib)--test=[specify test name]:test name'
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ )
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--color=:colorization option:(auto always never)' \ parallel=(
;; '(-j --jobs)'{-j+,--jobs=}'[specify number of parallel jobs]:jobs [# of CPUs]'
)
build)
_arguments \ features=(
'--features=[space separated feature list]' \ '(--all-features)--features=[specify features to activate]:feature'
'--all-features[enable all available features]' \ '(--features)--all-features[activate all available features]'
'(-h, --help)'{-h,--help}'[show help message]' \ "--no-default-features[don't build the default features]"
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ )
"${command_scope_spec[@]}" \
'--manifest-path=[path to manifest]: :_files -/' \ msgfmt='--message-format=[specify error format]:error format [human]:(human json short)'
'--no-default-features[do not build the default features]' \ triple='--target=[specify target triple]:target triple'
'(-p,--package)'{-p=,--package=}'[package to build]:packages:_get_package_names' \ target='--target-dir=[specify directory for all generated artifacts]:directory:_directories'
'--release=[build in release mode]' \ manifest='--manifest-path=[specify path to manifest]:path:_directories'
'--target=[target triple]' \ registry='--registry=[specify registry to use]:registry'
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ case $state in
'--color=:colorization option:(auto always never)' \ args)
;; curcontext="${curcontext%:*}-${words[1]}:"
case ${words[1]} in
check) bench)
_arguments \ _arguments -s -A "^--" $common $parallel $features $msgfmt $triple $target $manifest \
'--features=[space separated feature list]' \ "${command_scope_spec[@]}" \
'--all-features[enable all available features]' \ '--all-targets[benchmark all targets]' \
'(-h, --help)'{-h,--help}'[show help message]' \ "--no-run[compile but don't run]" \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ '(-p --package)'{-p+,--package=}'[specify package to run benchmarks for]:package:_cargo_package_names' \
"${command_scope_spec[@]}" \ '--exclude=[exclude packages from the benchmark]:spec' \
'--manifest-path=[path to manifest]: :_files -/' \ '--no-fail-fast[run all benchmarks regardless of failure]' \
'--no-default-features[do not check the default features]' \ '1: :_guard "^-*" "bench name"' \
'(-p,--package)'{-p=,--package=}'[package to check]:packages:_get_package_names' \ '*:args:_default'
'--release=[check in release mode]' \ ;;
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ build)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--color=:colorization option:(auto always never)' \ '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
;; "${command_scope_spec[@]}" \
'(-p --package)'{-p+,--package=}'[specify package to build]:package:_cargo_package_names' \
clean) '--release[build in release mode]' \
_arguments \ '--build-plan[output the build plan in JSON]' \
'(-h, --help)'{-h,--help}'[show help message]' \ ;;
'--manifest-path=[path to manifest]: :_files -/' \
'(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \ check)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--release[whether or not to clean release artifacts]' \ '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
'--target=[target triple(default:all)]' \ "${command_scope_spec[@]}" \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-p --package)'{-p+,--package=}'[specify package to check]:package:_cargo_package_names' \
'--color=:colorization option:(auto always never)' \ '--release[check in release mode]' \
;; ;;
doc) clean)
_arguments \ _arguments -s -S $common $triple $target $manifest \
'--features=[space separated feature list]' \ '(-p --package)'{-p+,--package=}'[specify package to clean]:package:_cargo_package_names' \
'--all-features[enable all available features]' \ '--release[clean release artifacts]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--doc[clean just the documentation directory]'
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ ;;
'--manifest-path=[path to manifest]: :_files -/' \
'--no-deps[do not build docs for dependencies]' \ doc)
'--no-default-features[do not build the default features]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--open[open docs in browser after the build]' \ '--no-deps[do not build docs for dependencies]' \
'(-p, --package)'{-p,--package}'=[package to document]' \ '--document-private-items[include non-public items in the documentation]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--open[open docs in browser after the build]' \
'--release[build artifacts in release mode, with optimizations]' \ '(-p --package)'{-p+,--package=}'[specify package to document]:package:_cargo_package_names' \
'--target=[build for the target triple]' \ '--release[build artifacts in release mode, with optimizations]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ ;;
'--color=:colorization option:(auto always never)' \
;; fetch)
_arguments -s -S $common $triple $manifest
fetch) ;;
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \ fix)
'--manifest-path=[path to manifest]: :_files -/' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ "${command_scope_spec[@]}" \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--broken-code[fix code even if it already has compiler errors]' \
'--color=:colorization option:(auto always never)' \ '--edition[fix in preparation for the next edition]' \
;; '--edition-idioms[fix warnings to migrate to the idioms of an edition]' \
'--allow-no-vcs[fix code even if a VCS was not detected]' \
generate-lockfile) '--allow-dirty[fix code even if the working directory is dirty]' \
_arguments \ '--allow-staged[fix code even if the working directory has staged changes]'
'(-h, --help)'{-h,--help}'[show help message]' \ ;;
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ generate-lockfile)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $manifest
'--color=:colorization option:(auto always never)' \ ;;
;;
git-checkout)
git-checkout) _arguments -s -S $common \
_arguments \ '--reference=:reference' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--url=:url:_urls'
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ ;;
'--reference=[REF]' \
'--url=[URL]' \ help)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _cargo_cmds
'--color=:colorization option:(auto always never)' \ ;;
;;
init)
help) _arguments -s -S $common $registry \
_arguments \ '--lib[use library template]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--edition=[specify edition to set for the crate generated]:edition:(2015 2018)' \
'*: :_cargo_cmds' \ '--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil none)' \
;; '--name=[set the resulting package name]:name' \
'1:path:_directories'
init) ;;
_arguments \
'--bin[use binary template]' \ install)
'--vcs:initialize a new repo with a given VCS:(git hg none)' \ _arguments -s -S $common $parallel $features $triple $registry \
'(-h, --help)'{-h,--help}'[show help message]' \ '(-f --force)'{-f,--force}'[force overwriting of existing crates or binaries]' \
'--name=[set the resulting package name]' \ '--bin=[only install the specified binary]:binary' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--branch=[branch to use when installing from git]:branch' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--debug[build in debug mode instead of release mode]' \
'--color=:colorization option:(auto always never)' \ '--example=[install the specified example instead of binaries]:example' \
;; '--git=[specify URL from which to install the crate]:url:_urls' \
'--path=[local filesystem path to crate to install]: :_directories' \
install) '--rev=[specific commit to use when installing from git]:commit' \
_arguments \ '--root=[directory to install packages into]: :_directories' \
'--bin=[only install the specified binary]' \ '--tag=[tag to use when installing from git]:tag' \
'--branch=[branch to use when installing from git]' \ '--vers=[version to install from crates.io]:version' \
'--color=:colorization option:(auto always never)' \ '--list[list all installed packages and their versions]' \
'--debug[build in debug mode instead of release mode]' \ '*: :_guard "^-*" "crate"'
'--example[install the specified example instead of binaries]' \ ;;
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \ locate-project)
'--git=[URL from which to install the crate]' \ _arguments -s -S $common $manifest
'(-h, --help)'{-h,--help}'[show help message]' \ ;;
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
'--no-default-features[do not build the default features]' \ login)
'--path=[local filesystem path to crate to install]: :_files -/' \ _arguments -s -S $common $registry \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '*: :_guard "^-*" "token"'
'--rev=[specific commit to use when installing from git]' \ ;;
'--root=[directory to install packages into]: :_files -/' \
'--tag=[tag to use when installing from git]' \ metadata)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $features $manifest \
'--vers=[version to install from crates.io]' \ "--no-deps[output information only about the root package and don't fetch dependencies]" \
;; '--format-version=[specify format version]:version [1]:(1)'
;;
locate-project)
_arguments \ new)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common $registry \
'--manifest-path=[path to manifest]: :_files -/' \ '--lib[use library template]' \
;; '--vcs:initialize a new repo with a given VCS:(git hg none)' \
'--name=[set the resulting package name]'
login) ;;
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \ owner)
'--host=[Host to set the token for]' \ _arguments -s -S $common $registry \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '(-a --add)'{-a,--add}'[specify name of a user or team to invite as an owner]:name' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--index=[specify registry index]:index' \
'--color=:colorization option:(auto always never)' \ '(-l --list)'{-l,--list}'[list owners of a crate]' \
;; '(-r --remove)'{-r,--remove}'[specify name of a user or team to remove as an owner]:name' \
'--token=[specify API token to use when authenticating]:token' \
metadata) '*: :_guard "^-*" "crate"'
_arguments \ ;;
'(-h, --help)'{-h,--help}'[show help message]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ package)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $parallel $features $triple $target $manifest \
"--no-deps[output information only about the root package and don't fetch dependencies]" \ '(-l --list)'{-l,--list}'[print files included in a package without making one]' \
'--no-default-features[do not include the default feature]' \ '--no-metadata[ignore warnings about a lack of human-usable metadata]' \
'--manifest-path=[path to manifest]: :_files -/' \ '--allow-dirty[allow dirty working directories to be packaged]' \
'--features=[space separated feature list]' \ "--no-verify[don't build to verify contents]"
'--all-features[enable all available features]' \ ;;
'--format-version=[format version(default: 1)]' \
'--color=:colorization option:(auto always never)' \ pkgid)
;; _arguments -s -S $common $manifest \
'(-p --package)'{-p+,--package=}'[specify package to get ID specifier for]:package:_cargo_package_names' \
new) '*: :_guard "^-*" "spec"'
_arguments \ ;;
'--bin[use binary template]' \
'--vcs:initialize a new repo with a given VCS:(git hg none)' \ publish)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common $parallel $features $triple $target $manifest $registry \
'--name=[set the resulting package name]' \ '--index=[specify registry index]:index' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--allow-dirty[allow dirty working directories to be packaged]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ "--no-verify[don't verify the contents by building them]" \
'--color=:colorization option:(auto always never)' \ '--token=[specify token to use when uploading]:token' \
;; '--dry-run[perform all checks without uploading]'
;;
owner)
_arguments \ read-manifest)
'(-a, --add)'{-a,--add}'[add owner LOGIN]' \ _arguments -s -S $common $manifest
'(-h, --help)'{-h,--help}'[show help message]' \ ;;
'--index[registry index]' \
'(-l, --list)'{-l,--list}'[list owners of a crate]' \ run)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-r, --remove)'{-r,--remove}'[remove owner LOGIN]' \ '--example=[name of the bin target]:name' \
'--token[API token to use when authenticating]' \ '--bin=[name of the bin target]:name' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-p --package)'{-p+,--package=}'[specify package with the target to run]:package:_cargo_package_names' \
'--color=:colorization option:(auto always never)' \ '--release[build in release mode]' \
;; '*: :_default'
;;
package)
_arguments \ rustc)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-l, --list)'{-l,--list}'[print files included in a package without making one]' \ '(-p --package)'{-p+,--package=}'[specify package to build]:package:_cargo_package_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '--profile=[specify profile to build the selected target for]:profile' \
'--no-metadata[ignore warnings about a lack of human-usable metadata]' \ '--release[build artifacts in release mode, with optimizations]' \
'--no-verify[do not build to verify contents]' \ "${command_scope_spec[@]}" \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '*: : _dispatch rustc rustc -default-'
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ ;;
'--color=:colorization option:(auto always never)' \
;; rustdoc)
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
pkgid) '--document-private-items[include non-public items in the documentation]' \
_arguments \ '--open[open the docs in a browser after the operation]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '(-p --package)'{-p+,--package=}'[specify package to document]:package:_cargo_package_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '--release[build artifacts in release mode, with optimizations]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ "${command_scope_spec[@]}" \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '*: : _dispatch rustdoc rustdoc -default-'
'--color=:colorization option:(auto always never)' \ ;;
;;
search)
publish) _arguments -s -S $common $registry \
_arguments \ '--index=[specify registry index]:index' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--limit=[limit the number of results]:results [10]' \
'--host=[Host to set the token for]' \ '*: :_guard "^-*" "query"'
'--manifest-path=[path to manifest]: :_files -/' \ ;;
'--no-verify[Do not verify tarball until before publish]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ test)
'--token[token to use when uploading]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--test=[test name]: :_cargo_test_names' \
'--color=:colorization option:(auto always never)' \ '--no-fail-fast[run all tests regardless of failure]' \
;; '--no-run[compile but do not run]' \
'(-p --package)'{-p+,--package=}'[package to run tests for]:package:_cargo_package_names' \
read-manifest) '--all[test all packages in the workspace]' \
_arguments \ '--release[build artifacts in release mode, with optimizations]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '1: :_cargo_test_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '(--doc --bin --example --test --bench)--lib[only test library]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(--lib --bin --example --test --bench)--doc[only test documentation]' \
'--color=:colorization option:(auto always never)' \ '(--lib --doc --example --test --bench)--bin=[binary name]' \
;; '(--lib --doc --bin --test --bench)--example=[example name]' \
'(--lib --doc --bin --example --bench)--test=[test name]' \
run) '(--lib --doc --bin --example --test)--bench=[benchmark name]' \
_arguments \ '*: :_default'
'--example=[name of the bin target]' \ ;;
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \ uninstall)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ '(-p --package)'{-p+,--package=}'[specify package to uninstall]:package:_cargo_package_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '--bin=[only uninstall the specified binary]:name' \
'--bin=[name of the bin target]' \ '--root=[directory to uninstall packages from]: :_files -/' \
'--no-default-features[do not build the default features]' \ '*:crate:_cargo_installed_crates -F line'
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ ;;
'--release=[build in release mode]' \
'--target=[target triple]' \ update)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $manifest \
'--color=:colorization option:(auto always never)' \ '--aggressive=[force dependency update]' \
'*: :_normal' \ "--dry-run[don't actually write the lockfile]" \
;; '(-p --package)'{-p+,--package=}'[specify package to update]:package:_cargo_package_names' \
'--precise=[update single dependency to precise release]:release'
rustc) ;;
_arguments \
'--color=:colorization option:(auto always never)' \ verify-project)
'--features=[features to compile for the package]' \ _arguments -s -S $common $manifest
'--all-features[enable all available features]' \ ;;
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \ version)
'--manifest-path=[path to the manifest to fetch dependencies for]: :_files -/' \ _arguments -s -S $common
'--no-default-features[do not compile default features for the package]' \ ;;
'(-p, --package)'{-p,--package}'=[profile to compile for]' \
'--profile=[profile to build the selected target for]' \ yank)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $registry \
'--release[build artifacts in release mode, with optimizations]' \ '--vers=[specify yank version]:version' \
'--target=[target triple which compiles will be for]' \ '--undo[undo a yank, putting a version back into the index]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--index=[specify registry index to yank from]:registry index' \
"${command_scope_spec[@]}" \ '--token=[specify API token to use when authenticating]:token' \
;; '*: :_guard "^-*" "crate"'
;;
rustdoc) *)
_arguments \ # allow plugins to define their own functions
'--color=:colorization option:(auto always never)' \ if ! _call_function ret _cargo-${words[1]}; then
'--features=[space-separated list of features to also build]' \ # fallback on default completion for unknown commands
'--all-features[enable all available features]' \ _default && ret=0
'(-h, --help)'{-h,--help}'[show help message]' \ fi
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \ (( ! ret ))
'--manifest-path=[path to the manifest to document]: :_files -/' \ ;;
'--no-default-features[do not build the `default` feature]' \ esac
'--open[open the docs in a browser after the operation]' \ ;;
'(-p, --package)'{-p,--package}'=[package to document]' \ esac
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ }
'--release[build artifacts in release mode, with optimizations]' \
'--target=[build for the target triple]' \ _cargo_unstable_flags() {
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ local flags
"${command_scope_spec[@]}" \ flags=( help ${${${(M)${(f)"$(_call_program flags cargo -Z help)"}:#*--*}/ #-- #/:}##*-Z } )
;; _describe -t flags 'unstable flag' flags
search)
_arguments \
'--color=:colorization option:(auto always never)' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--host=[host of a registry to search in]' \
'--limit=[limit the number of results]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
test)
_arguments \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to manifest]: :_files -/' \
'--test=[test name]: :_test_names' \
'--no-default-features[do not build the default features]' \
'--no-fail-fast[run all tests regardless of failure]' \
'--no-run[compile but do not run]' \
'(-p,--package)'{-p=,--package=}'[package to run tests for]:packages:_get_package_names' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
'1: :_test_names' \
'(--doc --bin --example --test --bench)--lib[only test library]' \
'(--lib --bin --example --test --bench)--doc[only test documentation]' \
'(--lib --doc --example --test --bench)--bin=[binary name]' \
'(--lib --doc --bin --test --bench)--example=[example name]' \
'(--lib --doc --bin --example --bench)--test=[test name]' \
'(--lib --doc --bin --example --test)--bench=[benchmark name]' \
'--message-format:error format:(human json short)' \
'--frozen[require lock and cache up to date]' \
'--locked[require lock up to date]'
;;
uninstall)
_arguments \
'--bin=[only uninstall the binary NAME]' \
'--color=:colorization option:(auto always never)' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-q, --quiet)'{-q,--quiet}'[less output printed to stdout]' \
'--root=[directory to uninstall packages from]: :_files -/' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
update)
_arguments \
'--aggressive=[force dependency update]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
'(-p,--package)'{-p=,--package=}'[package to update]:packages:__get_package_names' \
'--precise=[update single dependency to PRECISE]: :' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
;;
verify-project)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
;;
version)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
;;
yank)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--index[registry index]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--token[API token to use when authenticating]' \
'--undo[undo a yank, putting a version back into the index]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
'--vers[yank version]' \
;;
esac
;;
esac
} }
_cargo_cmds(){ _cargo_installed_crates() {
local -a commands;commands=( local expl
'bench:execute all benchmarks of a local package' _description crates expl 'crate'
'build:compile the current package' compadd "$@" "$expl[@]" - ${${${(f)"$(cargo install --list)"}:# *}%% *}
'check:check the current package without compiling'
'clean:remove generated artifacts'
'doc:build package documentation'
'fetch:fetch package dependencies'
'generate-lockfile:create lockfile'
'git-checkout:git checkout'
'help:get help for commands'
'init:create new package in current directory'
'install:install a Rust binary'
'locate-project:print "Cargo.toml" location'
'login:login to remote server'
'metadata:the metadata for a package in json'
'new:create a new package'
'owner:manage the owners of a crate on the registry'
'package:assemble local package into a distributable tarball'
'pkgid:print a fully qualified package specification'
'publish:upload package to the registry'
'read-manifest:print manifest in JSON format'
'run:run the main binary of the local package'
'rustc:compile a package and all of its dependencies'
'rustdoc:build documentation for a package'
'search:search packages on crates.io'
'test:execute all unit and tests of a local package'
'uninstall:remove a Rust binary'
'update:update dependencies'
'verify-project:check Cargo.toml'
'version:show version information'
'yank:remove pushed file from index'
)
_describe -t common-commands 'common commands' commands
} }
_cargo_all_cmds(){ _cargo_cmds() {
local -a commands;commands=($(cargo --list)) local -a commands
_describe -t all-commands 'all commands' commands # This uses Parameter Expansion Flags, which are a built-in Zsh feature.
# See more: http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
# and http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion
#
# # How this work?
#
# First it splits the result of `cargo --list` at newline, then it removes the first line.
# Then it removes indentation (4 whitespaces) before each items. (Note the x## pattern [1]).
# Then it replaces those spaces between item and description with a `:`
#
# [1]: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#patterns
commands=( ${${${(M)"${(f)$(_call_program commands cargo --list)}":# *}/ ##/}/ ##/:} )
_describe -t commands 'command' commands
} }
#FIXME: Disabled until fixed #FIXME: Disabled until fixed
#gets package names from the manifest file #gets package names from the manifest file
_get_package_names() _cargo_package_names() {
{ _message -e packages package
}
#TODO:see if it makes sense to have 'locate-project' to have non-json output.
#strips package name from json stuff
_locate_manifest(){
local manifest=`cargo locate-project 2>/dev/null`
regexp-replace manifest '\{"root":"|"\}' ''
echo $manifest
} }
# Extracts the values of "name" from the array given in $1 and shows them as # Extracts the values of "name" from the array given in $1 and shows them as
# command line options for completion # command line options for completion
_get_names_from_array() _cargo_names_from_array() {
{ # strip json from the path
local -a filelist; local manifest=${${${"$(cargo locate-project)"}%\"\}}##*\"}
local manifest=$(_locate_manifest)
if [[ -z $manifest ]]; then if [[ -z $manifest ]]; then
return 0 return 0
fi fi
...@@ -494,51 +372,36 @@ _get_names_from_array() ...@@ -494,51 +372,36 @@ _get_names_from_array()
local in_block=false local in_block=false
local block_name=$1 local block_name=$1
names=() names=()
while read line while read -r line; do
do
if [[ $last_line == "[[$block_name]]" ]]; then if [[ $last_line == "[[$block_name]]" ]]; then
in_block=true in_block=true
else else
if [[ $last_line =~ '.*\[\[.*' ]]; then if [[ $last_line =~ '\s*\[\[.*' ]]; then
in_block=false in_block=false
fi fi
fi fi
if [[ $in_block == true ]]; then if [[ $in_block == true ]]; then
if [[ $line =~ '.*name.*=' ]]; then if [[ $line =~ '\s*name\s*=' ]]; then
regexp-replace line '^.*name *= *|"' "" regexp-replace line '^\s*name\s*=\s*|"' ''
names+=$line names+=( "$line" )
fi fi
fi fi
last_line=$line last_line=$line
done < $manifest done < "$manifest"
_describe $block_name names _describe "$block_name" names
} }
#Gets the test names from the manifest file #Gets the test names from the manifest file
_test_names() _cargo_test_names() {
{ _cargo_names_from_array "test"
_get_names_from_array "test"
} }
#Gets the bench names from the manifest file #Gets the bench names from the manifest file
_benchmark_names() _cargo_benchmark_names() {
{ _cargo_names_from_array "bench"
_get_names_from_array "bench"
} }
# These flags are mutually exclusive specifiers for the scope of a command; as
# they are used in multiple places without change, they are expanded into the
# appropriate command's `_arguments` where appropriate.
set command_scope_spec
command_scope_spec=(
'(--bin --example --test --lib)--bench=[benchmark name]: :_benchmark_names'
'(--bench --bin --test --lib)--example=[example name]'
'(--bench --example --test --lib)--bin=[binary name]'
'(--bench --bin --example --test)--lib=[library name]'
'(--bench --bin --example --lib)--test=[test name]'
)
_cargo _cargo
...@@ -17,10 +17,10 @@ Plugin for displaying images on the terminal using the the `catimg.sh` script pr ...@@ -17,10 +17,10 @@ Plugin for displaying images on the terminal using the the `catimg.sh` script pr
) )
``` ```
2. Reload the source file or restart your Terminal session: 2. Restart the shell or restart your Terminal session:
```console ```console
$ source ~/.zshrc $ exec zsh
$ $
``` ```
......
# chruby plugin
This plugin loads [chruby](https://github.com/postmodern/chruby), a tool that changes the
current Ruby version, and completion and a prompt function to display the Ruby version.
Supports brew and manual installation of chruby.
To use it, add `chruby` to the plugins array in your zshrc file:
```zsh
plugins=(... chruby)
```
## Usage
If you'd prefer to specify an explicit path to load chruby from
you can set variables like so:
```
zstyle :omz:plugins:chruby path /local/path/to/chruby.sh
zstyle :omz:plugins:chruby auto /local/path/to/auto.sh
```
# CloudApp plugin
[CloudApp](https://www.getcloudapp.com) brings screen recording, screenshots, and GIF creation to the cloud, in an easy-to-use enterprise-level app. The CloudApp plugin allows you to upload a file to your CloadApp account from the command line.
To use it, add `cloudapp` to the plugins array of your `~/.zshrc` file:
```
plugins=(... cloudapp)
```
## Requirements
1. [Aaron Russell's `cloudapp_api` gem](https://github.com/aaronrussell/cloudapp_api#installation)
2. That you set your CloudApp credentials in `~/.cloudapp` as a simple text file like below:
```
email
password
```
## Usage
- `cloudapp <filename>`: uploads `<filename>` to your CloudApp account, and if you're using
macOS, copies the URL to your clipboard.
# codeclimate plugin
This plugin adds autocompletion for the [`codeclimate` CLI](https://github.com/codeclimate/codeclimate).
To use it, add `codeclimate` to the plugins array in your zshrc file:
```zsh
plugins=(... codeclimate)
```
# Colemak plugin
This plugin remaps keys in `zsh`'s [`vi`-style navigation mode](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Keymaps)
for a [Colemak](https://colemak.com/) keyboard layout, to match the QWERTY position:
![Colemak layout on a US keyboard](https://colemak.com/wiki/images/6/6c/Colemak2.png)
To use it, add it to the plugins array in your `~/.zshrc` file:
```
plugins=(... colemak)
```
You will also need to enable `vi` mode, so add another line to `~/.zshrc`:
```
bindkey -v
```
Restart your shell and hit the `<ESC>` key to activate `vicmd` (navigation) mode,
and start navigating `zsh` with your new keybindings!
## Key bindings for vicmd
| Old | New | Binding | Description |
|------------|------------|---------------------------|----------------------------------------------------|
| `CTRL`+`j` | `CTRL`+`n` | accept-line | Insert new line |
| `j` | `n` | down-line-or-history | Move one line down or command history forwards |
| `k` | `e` | up-line-or-history | Move one line up or command history backwards |
| `l` | `i` | vi-forward-char | Move one character to the right |
| `n` | `k` | vi-repeat-search | Repeat command search forwards |
| `N` | `K` | vi-rev-repeat-search | Repeat command search backwards |
| `i` | `u` | vi-insert | Enter insert mode |
| `I` | `U` | vi-insert-bol | Move to first non-blank char and enter insert mode |
| `<none>` | `l` | vi-undo-change | Undo change |
| `J` | `N` | vi-join | Join the current line with the next one |
| `e` | `j` | vi-forward-word-end | Move to the end of the next word |
| `E` | `J` | vi-forward-blank-word-end | Move to end of the current or next word |
## Key bindings for less
| Keyboard shortcut | `less` key binding |
|-------------------|--------------------|
| `n` | forw-line |
| `e` | back-line |
| `k` | repeat-search |
| `ESC`+`k` | repeat-search-all |
| `K` | reverse-search |
| `ESC`+`K` | reverse-search-all |
# Colored man pages plugin
This plugin adds colors to man pages.
To use it, add `colored-man-pages` to the plugins array in your zshrc file:
```zsh
plugins=(... colored-man-pages)
```
You can also try to color other pages by prefixing the respective command with `colored`:
```zsh
colored git help clone
```
...@@ -16,8 +16,8 @@ EOF ...@@ -16,8 +16,8 @@ EOF
fi fi
fi fi
function man() { function colored() {
env \ command env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \ LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \ LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \ LESS_TERMCAP_me=$(printf "\e[0m") \
...@@ -28,5 +28,9 @@ function man() { ...@@ -28,5 +28,9 @@ function man() {
PAGER="${commands[less]:-$PAGER}" \ PAGER="${commands[less]:-$PAGER}" \
_NROFF_U=1 \ _NROFF_U=1 \
PATH="$HOME/bin:$PATH" \ PATH="$HOME/bin:$PATH" \
man "$@" "$@"
}
function man() {
colored man "$@"
} }
...@@ -6,30 +6,43 @@ Colorize will highlight the content based on the filename extension. If it can't ...@@ -6,30 +6,43 @@ Colorize will highlight the content based on the filename extension. If it can't
method for a given extension, it will try to find one by looking at the file contents. If no highlight method method for a given extension, it will try to find one by looking at the file contents. If no highlight method
is found it will just cat the file normally, without syntax highlighting. is found it will just cat the file normally, without syntax highlighting.
To use it, add colorize to the plugins array of your zshrc file: ## Setup
To use it, add colorize to the plugins array of your `~/.zshrc` file:
``` ```
plugins=(... colorize) plugins=(... colorize)
``` ```
## Styles ## Configuration
Pygments offers multiple styles. By default, the `default` style is used, but you can choose another theme by setting the `ZSH_COLORIZE_STYLE` environment variable: ### Requirements
`ZSH_COLORIZE_STYLE="colorful"` This plugin requires that at least one of the following tools is installed:
## Usage * [Chroma](https://github.com/alecthomas/chroma)
* [Pygments](https://pygments.org/download/)
### Colorize tool
* `ccat <file> [files]`: colorize the contents of the file (or files, if more than one are provided). Colorize supports `pygmentize` and `chroma` as syntax highlighter. By default colorize uses `pygmentize` unless it's not installed and `chroma` is. This can be overridden by the `ZSH_COLORIZE_TOOL` environment variable:
If no arguments are passed it will colorize the standard input or stdin.
```
ZSH_COLORIZE_TOOL=chroma
```
* `cless <file> [files]`: colorize the contents of the file (or files, if more than one are provided) and ### Styles
open less. If no arguments are passed it will colorize the standard input or stdin.
Note that `cless` will behave as less when provided more than one file: you have to navigate files with Pygments offers multiple styles. By default, the `default` style is used, but you can choose another theme by setting the `ZSH_COLORIZE_STYLE` environment variable:
the commands `:n` for next and `:p` for previous. The downside is that less options are not supported.
But you can circumvent this by either using the LESS environment variable, or by running `ccat file1 file2|less --opts`. ```
In the latter form, the file contents will be concatenated and presented by less as a single file. ZSH_COLORIZE_STYLE="colorful"
```
## Usage
## Requirements * `ccat <file> [files]`: colorize the contents of the file (or files, if more than one are provided).
If no files are passed it will colorize the standard input.
You have to install Pygments first: [pygments.org](http://pygments.org/download/) * `cless [less-options] <file> [files]`: colorize the contents of the file (or files, if more than one are provided) and open less.
If no files are passed it will colorize the standard input.
The LESSOPEN and LESSCLOSE will be overwritten for this to work, but only in a local scope.
# easier alias to use the plugin # Easier alias to use the plugin
alias ccat='colorize_via_pygmentize' alias ccat="colorize_cat"
alias cless='colorize_via_pygmentize_less' alias cless="colorize_less"
colorize_via_pygmentize() { # '$0:A' gets the absolute path of this file
if ! (( $+commands[pygmentize] )); then ZSH_COLORIZE_PLUGIN_PATH=$0:A
echo "package 'Pygments' is not installed!"
colorize_check_requirements() {
local available_tools=("chroma" "pygmentize")
if [ -z "$ZSH_COLORIZE_TOOL" ]; then
if (( $+commands[pygmentize] )); then
ZSH_COLORIZE_TOOL="pygmentize"
elif (( $+commands[chroma] )); then
ZSH_COLORIZE_TOOL="chroma"
else
echo "Neither 'pygments' nor 'chroma' is installed!" >&2
return 1
fi
fi
if [[ ${available_tools[(Ie)$ZSH_COLORIZE_TOOL]} -eq 0 ]]; then
echo "ZSH_COLORIZE_TOOL '$ZSH_COLORIZE_TOOL' not recognized. Available options are 'pygmentize' and 'chroma'." >&2
return 1
elif (( $+commands["$ZSH_COLORIZE_TOOL"] )); then
echo "Package '$ZSH_COLORIZE_TOOL' is not installed!" >&2
return 1
fi
}
colorize_cat() {
if ! colorize_check_requirements; then
return 1 return 1
fi fi
# If the environment varianle ZSH_COLORIZE_STYLE # If the environment variable ZSH_COLORIZE_STYLE
# is set, use that theme instead. Otherwise, # is set, use that theme instead. Otherwise,
# use the default. # use the default.
if [ -z $ZSH_COLORIZE_STYLE ]; then if [ -z "$ZSH_COLORIZE_STYLE" ]; then
ZSH_COLORIZE_STYLE="default" # Both pygmentize & chroma support 'emacs'
ZSH_COLORIZE_STYLE="emacs"
fi fi
# pygmentize stdin if no arguments passed # Use stdin if no arguments have been passed.
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g
else
chroma --style="$ZSH_COLORIZE_STYLE"
fi
return $? return $?
fi fi
# guess lexer from file extension, or # Guess lexer from file extension, or guess it from file contents if unsuccessful.
# guess it from file contents if unsuccessful
local FNAME lexer local FNAME lexer
for FNAME in "$@" for FNAME in "$@"; do
do if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
lexer=$(pygmentize -N "$FNAME") lexer=$(pygmentize -N "$FNAME")
if [[ $lexer != text ]]; then if [[ $lexer != text ]]; then
pygmentize -O style="$ZSH_COLORIZE_STYLE" -l "$lexer" "$FNAME" pygmentize -O style="$ZSH_COLORIZE_STYLE" -l "$lexer" "$FNAME"
else
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g "$FNAME"
fi
else else
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g "$FNAME" chroma --style="$ZSH_COLORIZE_STYLE" "$FNAME"
fi fi
done done
} }
colorize_via_pygmentize_less() ( # The less option 'F - Forward forever; like "tail -f".' will not work in this implementation
# this function is a subshell so tmp_files can be shared to cleanup function # caused by the lack of the ability to follow the file within pygmentize.
declare -a tmp_files colorize_less() {
if ! colorize_check_requirements; then
return 1
fi
cleanup () { _cless() {
[[ ${#tmp_files} -gt 0 ]] && rm -f "${tmp_files[@]}" # LESS="-R $LESS" enables raw ANSI colors, while maintain already set options.
exit local LESS="-R $LESS"
}
trap 'cleanup' EXIT HUP TERM INT
while (( $# != 0 )); do #TODO: filter out less opts # This variable tells less to pipe every file through the specified command
tmp_file="$(mktemp -t "tmp.colorize.XXXX.$(sed 's/\//./g' <<< "$1")")" # (see the man page of less INPUT PREPROCESSOR).
tmp_files+=("$tmp_file") # 'zsh -ic "colorize_cat %s 2> /dev/null"' would not work for huge files like
colorize_via_pygmentize "$1" > "$tmp_file" # the ~/.zsh_history. For such files the tty of the preprocessor will be supended.
shift 1 # Therefore we must source this file to make colorize_cat available in the
done # preprocessor without the interactive mode.
# `2>/dev/null` will suppress the error for large files 'broken pipe' of the python
# script pygmentize, which will show up if less has not fully "loaded the file"
# (e.g. when not scrolled to the bottom) while already the next file will be displayed.
local LESSOPEN="| zsh -c 'source \"$ZSH_COLORIZE_PLUGIN_PATH\"; \
ZSH_COLORIZE_TOOL=$ZSH_COLORIZE_TOOL ZSH_COLORIZE_STYLE=$ZSH_COLORIZE_STYLE \
colorize_cat %s 2> /dev/null'"
less -f "${tmp_files[@]}" # LESSCLOSE will be set to prevent any errors by executing a user script
) # which assumes that his LESSOPEN has been executed.
local LESSCLOSE=""
LESS="$LESS" LESSOPEN="$LESSOPEN" LESSCLOSE="$LESSCLOSE" less "$@"
}
if [ -t 0 ]; then
_cless "$@"
else
# The input is not associated with a terminal, therefore colorize_cat will
# colorize this input and pass it to less.
# Less has now to decide what to use. If any files have been provided, less
# will ignore the input by default, otherwise the colorized input will be used.
# If files have been supplied and the input has been redirected, this will
# lead to unnecessary overhead, but retains the ability to use the less options
# without checking for them inside this script.
colorize_cat | _cless "$@"
fi
}
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