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'
alias arci='arc commit'
alias ard='arc diff'
alias ardc='arc diff --create'
alias ardnu='arc diff --nounit'
alias ardnupc='arc diff --nounit --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
autojump_paths=(
$HOME/.autojump/etc/profile.d/autojump.zsh # manual installation
......
......@@ -10,7 +10,8 @@ function asp() {
return
fi
local available_profiles=($(aws_profiles))
local -a available_profiles
available_profiles=($(aws_profiles))
if [[ -z "${available_profiles[(r)$1]}" ]]; then
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
......
......@@ -7,23 +7,25 @@
# Email: neuralsandwich@gmail.com #
# 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() {
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
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 battery_is_charging() {
ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes'
}
function plugged_in() {
[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ]
function battery_pct() {
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() {
if plugged_in ; then
if battery_is_charging; then
echo "External Power"
else
battery_pct
......@@ -32,9 +34,9 @@ if [[ "$OSTYPE" = darwin* ]] ; then
function battery_time_remaining() {
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
if [ $timeremaining -gt 720 ] ; then
if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then
timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
if [ $timeremaining -gt 720 ]; then
echo "::"
else
echo "~$((timeremaining / 60)):$((timeremaining % 60))"
......@@ -45,39 +47,36 @@ if [[ "$OSTYPE" = darwin* ]] ; then
}
function battery_pct_prompt () {
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
b=$(battery_pct_remaining)
if [ $b -gt 50 ] ; then
local battery_pct color
if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then
battery_pct=$(battery_pct_remaining)
if [[ $battery_pct -gt 50 ]]; then
color='green'
elif [ $b -gt 20 ] ; then
elif [[ $battery_pct -gt 20 ]]; then
color='yellow'
else
color='red'
fi
echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
echo "%{$fg[$color]%}[${battery_pct}%%]%{$reset_color%}"
else
echo "∞"
fi
}
function battery_is_charging() {
[[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]]
}
elif [[ "$OSTYPE" = linux* ]] ; then
elif [[ "$OSTYPE" = freebsd* ]]; then
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() {
if (( $+commands[acpi] )) ; then
echo "$(acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')"
if (( $+commands[sysctl] )); then
sysctl -n hw.acpi.battery.life
fi
}
function battery_pct_remaining() {
if [ ! $(battery_is_charging) ] ; then
if ! battery_is_charging; then
battery_pct
else
echo "External Power"
......@@ -85,76 +84,128 @@ elif [[ "$OSTYPE" = linux* ]] ; then
}
function battery_time_remaining() {
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
echo $(acpi 2>/dev/null | cut -f3 -d ',')
local remaining_time
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
}
function battery_pct_prompt() {
b=$(battery_pct_remaining)
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
if [ $b -gt 50 ] ; then
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 [ $b -gt 20 ] ; then
elif [[ $battery_pct -gt 20 ]]; then
color='yellow'
else
color='red'
fi
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
else
echo "∞"
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
fi
}
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
}
else
# Empty functions so we don't cause errors in prompts
function battery_pct_remaining() {
if ! battery_is_charging; then
battery_pct
else
echo "External Power"
fi
}
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() {
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
function battery_level_gauge() {
local gauge_slots=${BATTERY_GAUGE_SLOTS:-10};
local green_threshold=${BATTERY_GREEN_THRESHOLD:-6};
local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-4};
local color_green=${BATTERY_COLOR_GREEN:-%F{green}};
local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}};
local color_red=${BATTERY_COLOR_RED:-%F{red}};
local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}};
local battery_prefix=${BATTERY_GAUGE_PREFIX:-'['};
local battery_suffix=${BATTERY_GAUGE_SUFFIX:-']'};
local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'▶'};
local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-'▷'};
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow};
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'};
local battery_remaining_percentage=$(battery_pct);
local gauge_slots=${BATTERY_GAUGE_SLOTS:-10}
local green_threshold=${BATTERY_GREEN_THRESHOLD:-$(( gauge_slots * 0.6 ))}
local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-$(( gauge_slots * 0.4 ))}
local color_green=${BATTERY_COLOR_GREEN:-%F{green}}
local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}}
local color_red=${BATTERY_COLOR_RED:-%F{red}}
local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}}
local battery_prefix=${BATTERY_GAUGE_PREFIX:-'['}
local battery_suffix=${BATTERY_GAUGE_SUFFIX:-']'}
local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'▶'}
local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-'▷'}
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'}
local battery_remaining_percentage=$(battery_pct)
local filled empty gauge_color
if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then
local filled=$(((( $battery_remaining_percentage + $gauge_slots - 1) / $gauge_slots)));
local empty=$(($gauge_slots - $filled));
filled=$(( ($battery_remaining_percentage * $gauge_slots) / 100 ))
empty=$(( $gauge_slots - $filled ))
if [[ $filled -gt $green_threshold ]]; then local gauge_color=$color_green;
elif [[ $filled -gt $yellow_threshold ]]; then local gauge_color=$color_yellow;
else local gauge_color=$color_red;
if [[ $filled -gt $green_threshold ]]; then
gauge_color=$color_green
elif [[ $filled -gt $yellow_threshold ]]; then
gauge_color=$color_yellow
else
gauge_color=$color_red
fi
else
local filled=$gauge_slots;
local empty=0;
filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'};
filled=$gauge_slots
empty=0
filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'}
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 ${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}
# Suffix
printf ${color_reset//\%/\%\%}${battery_suffix//\%/\%\%}${color_reset//\%/\%\%}
}
......@@ -15,7 +15,7 @@
- calls `bundle exec <gem executable>` otherwise
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
......@@ -42,7 +42,7 @@ This will exclude the `foreman` and `spin` gems (i.e. their executable) from bei
## 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`
`foreman`
......
......@@ -27,6 +27,7 @@ bundled_commands=(
rainbows
rake
rspec
rubocop
shotgun
sidekiq
spec
......@@ -81,7 +82,7 @@ _bundler-installed() {
_within-bundled-project() {
local check_dir="$PWD"
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)"
done
false
......@@ -94,7 +95,7 @@ _binstubbed() {
_run-with-bundler() {
if _bundler-installed && _within-bundled-project; then
if _binstubbed $1; then
./bin/$@
./bin/${^^@}
else
bundle exec $@
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 @@
autoload -U regexp-replace
zstyle -T ':completion:*:*:cargo:*' tag-order && \
zstyle ':completion:*:*:cargo:*' tag-order 'common-commands'
_cargo() {
local context state state_descr line
typeset -A opt_args
# leading items in parentheses are an exclusion list for the arguments following that arg
# See: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions
# - => exclude all other options
# 1 => exclude positional arg 1
# * => exclude all other args
# +blah => exclude +blah
_arguments \
'(- 1 *)'{-h,--help}'[show help message]' \
local curcontext="$curcontext" ret=1
local -a command_scope_spec common parallel features msgfmt triple target registry
local -a state line state_descr # These are set by _arguments
typeset -A opt_args
common=(
'(-q --quiet)*'{-v,--verbose}'[use verbose output]'
'(-q --quiet -v --verbose)'{-q,--quiet}'[no output printed to stdout]'
'-Z+[pass unstable (nightly-only) flags to cargo]: :_cargo_unstable_flags'
'--frozen[require that Cargo.lock and cache are up-to-date]'
'--locked[require that Cargo.lock is up-to-date]'
'--color=[specify colorization option]:coloring:(auto always never)'
'(- 1 *)'{-h,--help}'[show help message]'
)
# leading items in parentheses are an exclusion list for the arguments following that arg
# See: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions
# - => exclude all other options
# 1 => exclude positional arg 1
# * => exclude all other args
# +blah => exclude +blah
_arguments -s -S -C $common \
'(- 1 *)--list[list installed commands]' \
'(- 1 *)--explain=[provide a detailed explanation of an error message]:error code' \
'(- 1 *)'{-V,--version}'[show version information]' \
{-v,--verbose}'[use verbose output]' \
--color'[colorization option]' \
'(+beta +nightly)+stable[use the stable toolchain]' \
'(+stable +nightly)+beta[use the beta toolchain]' \
'(+stable +beta)+nightly[use the nightly toolchain]' \
'1: :->command' \
'1: :_cargo_cmds' \
'*:: :->args'
case $state in
command)
_alternative 'common-commands:common:_cargo_cmds' 'all-commands:all:_cargo_all_cmds'
;;
# 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.
command_scope_spec=(
'(--bin --example --test --lib)--bench=[specify benchmark name]: :_cargo_benchmark_names'
'(--bench --bin --test --lib)--example=[specify example name]:example name'
'(--bench --example --test --lib)--bin=[specify binary name]:binary name'
'(--bench --bin --example --test)--lib=[specify library name]:library name'
'(--bench --bin --example --lib)--test=[specify test name]:test name'
)
parallel=(
'(-j --jobs)'{-j+,--jobs=}'[specify number of parallel jobs]:jobs [# of CPUs]'
)
features=(
'(--all-features)--features=[specify features to activate]:feature'
'(--features)--all-features[activate all available features]'
"--no-default-features[don't build the default features]"
)
msgfmt='--message-format=[specify error format]:error format [human]:(human json short)'
triple='--target=[specify target triple]:target triple'
target='--target-dir=[specify directory for all generated artifacts]:directory:_directories'
manifest='--manifest-path=[specify path to manifest]:path:_directories'
registry='--registry=[specify registry to use]:registry'
case $state in
args)
case $words[1] in
curcontext="${curcontext%:*}-${words[1]}:"
case ${words[1]} in
bench)
_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]' \
_arguments -s -A "^--" $common $parallel $features $msgfmt $triple $target $manifest \
"${command_scope_spec[@]}" \
'--manifest-path=[path to manifest]: :_files -/' \
'--no-default-features[do not build the default features]' \
'--no-run[compile but do not run]' \
'(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--color=:colorization option:(auto always never)' \
'--all-targets[benchmark all targets]' \
"--no-run[compile but don't run]" \
'(-p --package)'{-p+,--package=}'[specify package to run benchmarks for]:package:_cargo_package_names' \
'--exclude=[exclude packages from the benchmark]:spec' \
'--no-fail-fast[run all benchmarks regardless of failure]' \
'1: :_guard "^-*" "bench name"' \
'*:args:_default'
;;
build)
_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]' \
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
"${command_scope_spec[@]}" \
'--manifest-path=[path to manifest]: :_files -/' \
'--no-default-features[do not build the default features]' \
'(-p,--package)'{-p=,--package=}'[package to build]:packages:_get_package_names' \
'--release=[build in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--color=:colorization option:(auto always never)' \
'(-p --package)'{-p+,--package=}'[specify package to build]:package:_cargo_package_names' \
'--release[build in release mode]' \
'--build-plan[output the build plan in JSON]' \
;;
check)
_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]' \
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
"${command_scope_spec[@]}" \
'--manifest-path=[path to manifest]: :_files -/' \
'--no-default-features[do not check the default features]' \
'(-p,--package)'{-p=,--package=}'[package to check]:packages:_get_package_names' \
'--release=[check in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--color=:colorization option:(auto always never)' \
'(-p --package)'{-p+,--package=}'[specify package to check]:package:_cargo_package_names' \
'--release[check in release mode]' \
;;
clean)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
'(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release[whether or not to clean release artifacts]' \
'--target=[target triple(default:all)]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common $triple $target $manifest \
'(-p --package)'{-p+,--package=}'[specify package to clean]:package:_cargo_package_names' \
'--release[clean release artifacts]' \
'--doc[clean just the documentation directory]'
;;
doc)
_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 -/' \
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--no-deps[do not build docs for dependencies]' \
'--no-default-features[do not build the default features]' \
'--document-private-items[include non-public items in the documentation]' \
'--open[open docs in browser after the build]' \
'(-p, --package)'{-p,--package}'=[package to document]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-p --package)'{-p+,--package=}'[specify package to document]:package:_cargo_package_names' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[build for the target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
;;
fetch)
_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)' \
_arguments -s -S $common $triple $manifest
;;
fix)
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
"${command_scope_spec[@]}" \
'--broken-code[fix code even if it already has compiler errors]' \
'--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]' \
'--allow-dirty[fix code even if the working directory is dirty]' \
'--allow-staged[fix code even if the working directory has staged changes]'
;;
generate-lockfile)
_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)' \
_arguments -s -S $common $manifest
;;
git-checkout)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--reference=[REF]' \
'--url=[URL]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common \
'--reference=:reference' \
'--url=:url:_urls'
;;
help)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'*: :_cargo_cmds' \
_cargo_cmds
;;
init)
_arguments \
'--bin[use binary template]' \
'--vcs:initialize a new repo with a given VCS:(git hg none)' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--name=[set the resulting package name]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common $registry \
'--lib[use library template]' \
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018)' \
'--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'
;;
install)
_arguments \
'--bin=[only install the specified binary]' \
'--branch=[branch to use when installing from git]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common $parallel $features $triple $registry \
'(-f --force)'{-f,--force}'[force overwriting of existing crates or binaries]' \
'--bin=[only install the specified binary]:binary' \
'--branch=[branch to use when installing from git]:branch' \
'--debug[build in debug mode instead of release mode]' \
'--example[install the specified example instead of binaries]' \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'--git=[URL from which to install the crate]' \
'(-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]' \
'--path=[local filesystem path to crate to install]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--rev=[specific commit to use when installing from git]' \
'--root=[directory to install packages into]: :_files -/' \
'--tag=[tag to use when installing from git]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--vers=[version to install from crates.io]' \
'--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' \
'--rev=[specific commit to use when installing from git]:commit' \
'--root=[directory to install packages into]: :_directories' \
'--tag=[tag to use when installing from git]:tag' \
'--vers=[version to install from crates.io]:version' \
'--list[list all installed packages and their versions]' \
'*: :_guard "^-*" "crate"'
;;
locate-project)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
_arguments -s -S $common $manifest
;;
login)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--host=[Host to set the token for]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common $registry \
'*: :_guard "^-*" "token"'
;;
metadata)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
_arguments -s -S $common $features $manifest \
"--no-deps[output information only about the root package and don't fetch dependencies]" \
'--no-default-features[do not include the default feature]' \
'--manifest-path=[path to manifest]: :_files -/' \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'--format-version=[format version(default: 1)]' \
'--color=:colorization option:(auto always never)' \
'--format-version=[specify format version]:version [1]:(1)'
;;
new)
_arguments \
'--bin[use binary template]' \
_arguments -s -S $common $registry \
'--lib[use library template]' \
'--vcs:initialize a new repo with a given VCS:(git hg none)' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--name=[set the resulting package name]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
'--name=[set the resulting package name]'
;;
owner)
_arguments \
'(-a, --add)'{-a,--add}'[add owner LOGIN]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--index[registry index]' \
'(-l, --list)'{-l,--list}'[list owners of a crate]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-r, --remove)'{-r,--remove}'[remove owner LOGIN]' \
'--token[API token to use when authenticating]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common $registry \
'(-a --add)'{-a,--add}'[specify name of a user or team to invite as an owner]:name' \
'--index=[specify registry index]:index' \
'(-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' \
'*: :_guard "^-*" "crate"'
;;
package)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-l, --list)'{-l,--list}'[print files included in a package without making one]' \
'--manifest-path=[path to manifest]: :_files -/' \
_arguments -s -S $common $parallel $features $triple $target $manifest \
'(-l --list)'{-l,--list}'[print files included in a package without making one]' \
'--no-metadata[ignore warnings about a lack of human-usable metadata]' \
'--no-verify[do not build to verify contents]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
'--allow-dirty[allow dirty working directories to be packaged]' \
"--no-verify[don't build to verify contents]"
;;
pkgid)
_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)' \
_arguments -s -S $common $manifest \
'(-p --package)'{-p+,--package=}'[specify package to get ID specifier for]:package:_cargo_package_names' \
'*: :_guard "^-*" "spec"'
;;
publish)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--host=[Host to set the token for]' \
'--manifest-path=[path to manifest]: :_files -/' \
'--no-verify[Do not verify tarball until before publish]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--token[token to use when uploading]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common $parallel $features $triple $target $manifest $registry \
'--index=[specify registry index]:index' \
'--allow-dirty[allow dirty working directories to be packaged]' \
"--no-verify[don't verify the contents by building them]" \
'--token=[specify token to use when uploading]:token' \
'--dry-run[perform all checks without uploading]'
;;
read-manifest)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common $manifest
;;
run)
_arguments \
'--example=[name of the bin target]' \
'--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 -/' \
'--bin=[name of the bin target]' \
'--no-default-features[do not build the default features]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release=[build in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
'*: :_normal' \
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--example=[name of the bin target]:name' \
'--bin=[name of the bin target]:name' \
'(-p --package)'{-p+,--package=}'[specify package with the target to run]:package:_cargo_package_names' \
'--release[build in release mode]' \
'*: :_default'
;;
rustc)
_arguments \
'--color=:colorization option:(auto always never)' \
'--features=[features to compile for the package]' \
'--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 the manifest to fetch dependencies for]: :_files -/' \
'--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]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-p --package)'{-p+,--package=}'[specify package to build]:package:_cargo_package_names' \
'--profile=[specify profile to build the selected target for]:profile' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[target triple which compiles will be for]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
"${command_scope_spec[@]}" \
'*: : _dispatch rustc rustc -default-'
;;
rustdoc)
_arguments \
'--color=:colorization option:(auto always never)' \
'--features=[space-separated list of features to also build]' \
'--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 the manifest to document]: :_files -/' \
'--no-default-features[do not build the `default` feature]' \
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--document-private-items[include non-public items in the documentation]' \
'--open[open the docs in a browser after the operation]' \
'(-p, --package)'{-p,--package}'=[package to document]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-p --package)'{-p+,--package=}'[specify package to document]:package:_cargo_package_names' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[build for the target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
"${command_scope_spec[@]}" \
'*: : _dispatch rustdoc rustdoc -default-'
;;
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]' \
_arguments -s -S $common $registry \
'--index=[specify registry index]:index' \
'--limit=[limit the number of results]:results [10]' \
'*: :_guard "^-*" "query"'
;;
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]' \
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--test=[test name]: :_cargo_test_names' \
'--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]' \
'(-p --package)'{-p+,--package=}'[package to run tests for]:package:_cargo_package_names' \
'--all[test all packages in the workspace]' \
'--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' \
'1: :_cargo_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]'
'*: :_default'
;;
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]' \
_arguments -s -S $common \
'(-p --package)'{-p+,--package=}'[specify package to uninstall]:package:_cargo_package_names' \
'--bin=[only uninstall the specified binary]:name' \
'--root=[directory to uninstall packages from]: :_files -/' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'*:crate:_cargo_installed_crates -F line'
;;
update)
_arguments \
_arguments -s -S $common $manifest \
'--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)' \
"--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'
;;
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)' \
_arguments -s -S $common $manifest
;;
version)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
_arguments -s -S $common
;;
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]' \
_arguments -s -S $common $registry \
'--vers=[specify yank version]:version' \
'--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]' \
'--index=[specify registry index to yank from]:registry index' \
'--token=[specify API token to use when authenticating]:token' \
'*: :_guard "^-*" "crate"'
;;
*)
# allow plugins to define their own functions
if ! _call_function ret _cargo-${words[1]}; then
# fallback on default completion for unknown commands
_default && ret=0
fi
(( ! ret ))
;;
esac
;;
esac
esac
}
_cargo_unstable_flags() {
local flags
flags=( help ${${${(M)${(f)"$(_call_program flags cargo -Z help)"}:#*--*}/ #-- #/:}##*-Z } )
_describe -t flags 'unstable flag' flags
}
_cargo_cmds(){
local -a commands;commands=(
'bench:execute all benchmarks of a local package'
'build:compile the current package'
'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_installed_crates() {
local expl
_description crates expl 'crate'
compadd "$@" "$expl[@]" - ${${${(f)"$(cargo install --list)"}:# *}%% *}
}
_cargo_all_cmds(){
local -a commands;commands=($(cargo --list))
_describe -t all-commands 'all commands' commands
_cargo_cmds() {
local -a 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
#gets package names from the manifest file
_get_package_names()
{
}
#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
_cargo_package_names() {
_message -e packages package
}
# Extracts the values of "name" from the array given in $1 and shows them as
# command line options for completion
_get_names_from_array()
{
local -a filelist;
local manifest=$(_locate_manifest)
_cargo_names_from_array() {
# strip json from the path
local manifest=${${${"$(cargo locate-project)"}%\"\}}##*\"}
if [[ -z $manifest ]]; then
return 0
fi
......@@ -494,51 +372,36 @@ _get_names_from_array()
local in_block=false
local block_name=$1
names=()
while read line
do
while read -r line; do
if [[ $last_line == "[[$block_name]]" ]]; then
in_block=true
else
if [[ $last_line =~ '.*\[\[.*' ]]; then
if [[ $last_line =~ '\s*\[\[.*' ]]; then
in_block=false
fi
fi
if [[ $in_block == true ]]; then
if [[ $line =~ '.*name.*=' ]]; then
regexp-replace line '^.*name *= *|"' ""
names+=$line
if [[ $line =~ '\s*name\s*=' ]]; then
regexp-replace line '^\s*name\s*=\s*|"' ''
names+=( "$line" )
fi
fi
last_line=$line
done < $manifest
_describe $block_name names
done < "$manifest"
_describe "$block_name" names
}
#Gets the test names from the manifest file
_test_names()
{
_get_names_from_array "test"
_cargo_test_names() {
_cargo_names_from_array "test"
}
#Gets the bench names from the manifest file
_benchmark_names()
{
_get_names_from_array "bench"
_cargo_benchmark_names() {
_cargo_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
......@@ -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
$ 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
fi
fi
function man() {
env \
function colored() {
command env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
......@@ -28,5 +28,9 @@ function man() {
PAGER="${commands[less]:-$PAGER}" \
_NROFF_U=1 \
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
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.
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)
```
## 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/)
* `ccat <file> [files]`: colorize the contents of the file (or files, if more than one are provided).
If no arguments are passed it will colorize the standard input or stdin.
### Colorize tool
* `cless <file> [files]`: colorize the contents of the file (or files, if more than one are provided) and
open less. If no arguments are passed it will colorize the standard input or stdin.
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:
Note that `cless` will behave as less when provided more than one file: you have to navigate files with
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_TOOL=chroma
```
## Requirements
### Styles
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:
```
ZSH_COLORIZE_STYLE="colorful"
```
## Usage
* `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
alias ccat='colorize_via_pygmentize'
alias cless='colorize_via_pygmentize_less'
# Easier alias to use the plugin
alias ccat="colorize_cat"
alias cless="colorize_less"
colorize_via_pygmentize() {
if ! (( $+commands[pygmentize] )); then
echo "package 'Pygments' is not installed!"
# '$0:A' gets the absolute path of this file
ZSH_COLORIZE_PLUGIN_PATH=$0:A
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
}
# If the environment varianle ZSH_COLORIZE_STYLE
colorize_cat() {
if ! colorize_check_requirements; then
return 1
fi
# If the environment variable ZSH_COLORIZE_STYLE
# is set, use that theme instead. Otherwise,
# use the default.
if [ -z $ZSH_COLORIZE_STYLE ]; then
ZSH_COLORIZE_STYLE="default"
if [ -z "$ZSH_COLORIZE_STYLE" ]; then
# Both pygmentize & chroma support 'emacs'
ZSH_COLORIZE_STYLE="emacs"
fi
# pygmentize stdin if no arguments passed
# Use stdin if no arguments have been passed.
if [ $# -eq 0 ]; then
if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g
else
chroma --style="$ZSH_COLORIZE_STYLE"
fi
return $?
fi
# guess lexer from file extension, or
# guess it from file contents if unsuccessful
# Guess lexer from file extension, or guess it from file contents if unsuccessful.
local FNAME lexer
for FNAME in "$@"
do
for FNAME in "$@"; do
if [[ "$ZSH_COLORIZE_TOOL" == "pygmentize" ]]; then
lexer=$(pygmentize -N "$FNAME")
if [[ $lexer != text ]]; then
pygmentize -O style="$ZSH_COLORIZE_STYLE" -l "$lexer" "$FNAME"
else
pygmentize -O style="$ZSH_COLORIZE_STYLE" -g "$FNAME"
fi
else
chroma --style="$ZSH_COLORIZE_STYLE" "$FNAME"
fi
done
}
colorize_via_pygmentize_less() (
# this function is a subshell so tmp_files can be shared to cleanup function
declare -a tmp_files
# The less option 'F - Forward forever; like "tail -f".' will not work in this implementation
# caused by the lack of the ability to follow the file within pygmentize.
colorize_less() {
if ! colorize_check_requirements; then
return 1
fi
cleanup () {
[[ ${#tmp_files} -gt 0 ]] && rm -f "${tmp_files[@]}"
exit
}
trap 'cleanup' EXIT HUP TERM INT
_cless() {
# LESS="-R $LESS" enables raw ANSI colors, while maintain already set options.
local LESS="-R $LESS"
while (( $# != 0 )); do #TODO: filter out less opts
tmp_file="$(mktemp -t "tmp.colorize.XXXX.$(sed 's/\//./g' <<< "$1")")"
tmp_files+=("$tmp_file")
colorize_via_pygmentize "$1" > "$tmp_file"
shift 1
done
# This variable tells less to pipe every file through the specified command
# (see the man page of less INPUT PREPROCESSOR).
# 'zsh -ic "colorize_cat %s 2> /dev/null"' would not work for huge files like
# the ~/.zsh_history. For such files the tty of the preprocessor will be supended.
# Therefore we must source this file to make colorize_cat available in the
# 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