Merge branch 'master' of github.com:fklassen/ohmyzsh

* 'master' of github.com:fklassen/ohmyzsh: (38 commits)
  fix(aws): restore accidentally deleted variable
  feat(upgrade): add verbosity settings
  fix(uninstall): abort uninstall if unable to change shell (#10357)
  feat(juju): add functions to get current controller and model (#11572)
  fix(aws): do not print region if it's not defined
  feat(aws): set region when AWS_REGION is not set
  feat(gnu-utils): add `gindent` (#11569)
  fix(lib): set equivalent LS_COLORS and LSCOLORS variables
  feat(rails): add `rta` alias (#11553)
  docs(vi-mode): document how to add vi-mode info on the prompt (#11548)
  Fixing link to PA website in README
  feat(vi-mode): add settings for vi-mode cursor styles (#10860)
  fix(init): set completion colors on theme load, not with `precmd`
  feat(aws): add AWS_REGION to aws_prompt_info (#10062)
  fix(aliases): group properly aliases (#11546)
  fix(argocd): typo in filename
  feat(argocd): add completion plugin
  refactor(theme-and-appearance): reorganize and clean up logic (#11529)
  fix(lib): use `$BROWSER` in `open_command` if set (#11532)
  docs(brew): remove duplication (#11535)
  ...

 Conflicts:
	oh-my-zsh.sh
This commit is contained in:
Fred Klassen 2023-03-28 13:47:10 -07:00
commit 21c511d24e
No known key found for this signature in database
GPG key ID: E9E2149793BDE17E
47 changed files with 1103 additions and 155 deletions

View file

@ -19,7 +19,7 @@ Requirements: Python needs to be installed.
- `acs -h/--help`: print help mesage
- `acs <keyword>`: filter aliases by `<keyword>` and highlight
- `acs <keyword(s)>`: filter and highlight aliases by `<keyword>`
- `acs -g <group>/--group <group>`: show only aliases for group `<group>`. Multiple uses of the flag show all groups

View file

@ -15,6 +15,7 @@ def parse(line):
def cheatsheet(lines):
exps = [ parse(line) for line in lines ]
exps.sort(key=lambda exp:exp[2])
cheatsheet = {'_default': []}
for key, group in itertools.groupby(exps, lambda exp:exp[2]):
group_list = [ item for item in group ]
@ -56,8 +57,8 @@ def pretty_print(cheatsheet, wfilter, group_list=None, groups_only=False):
pretty_print_group(key, [ alias for alias in aliases if alias[0].find(wfilter)>-1 or alias[1].find(wfilter)>-1], wfilter)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Pretty print aliases.")
parser.add_argument('filter', nargs="*", help="search aliases matching string")
parser = argparse.ArgumentParser(description="Pretty print aliases.", prog="acs")
parser.add_argument('filter', nargs="*", metavar="<keyword>", help="search aliases matching keywords")
parser.add_argument('-g', '--group', dest="group_list", action='append', help="only print aliases in given groups")
parser.add_argument('--groups', dest='groups_only', action='store_true', help="only print alias groups")
args = parser.parse_args()

20
plugins/argocd/README.md Normal file
View file

@ -0,0 +1,20 @@
# Argo CD plugin
This plugin adds completion for the [Argo CD](https://argoproj.github.io/cd/) CLI.
To use it, add `argocd` to the plugins array in your zshrc file:
```zsh
plugins=(... argocd)
```
This plugin does not add any aliases.
## Cache
This plugin caches the completion script and is automatically updated asynchronously when the plugin is
loaded, which is usually when you start up a new terminal emulator.
The cache is stored at:
- `$ZSH_CACHE/completions/_argocd` completions script

View file

@ -0,0 +1,14 @@
# Autocompletion for argocd.
if (( ! $+commands[argocd] )); then
return
fi
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `argocd`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_argocd" ]]; then
typeset -g -A _comps
autoload -Uz _argocd
_comps[argocd]=_argocd
fi
argocd completion zsh >| "$ZSH_CACHE_DIR/completions/_argocd" &|

View file

@ -1,7 +1,7 @@
# aws
This plugin provides completion support for [awscli](https://docs.aws.amazon.com/cli/latest/reference/index.html)
and a few utilities to manage AWS profiles and display them in the prompt.
and a few utilities to manage AWS profiles/regions and display them in the prompt.
To use it, add `aws` to the plugins array in your zshrc file.
@ -12,10 +12,13 @@ plugins=(... aws)
## Plugin commands
* `asp [<profile>]`: sets `$AWS_PROFILE` and `$AWS_DEFAULT_PROFILE` (legacy) to `<profile>`.
It also sets `$AWS_EB_PROFILE` to `<profile>` for the Elastic Beanstalk CLI.
It also sets `$AWS_EB_PROFILE` to `<profile>` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`.
Run `asp` without arguments to clear the profile.
* `asp [<profile>] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection.
* `asr [<region>]`: sets `$AWS_REGION` and `$AWS_DEFAULT_REGION` (legacy) to `<region>`.
Run `asr` without arguments to clear the profile.
* `acp [<profile>] [<mfa_token>]`: in addition to `asp` functionality, it actually changes
the profile by assuming the role specified in the `<profile>` configuration. It supports
MFA and sets `$AWS_ACCESS_KEY_ID`, `$AWS_SECRET_ACCESS_KEY` and `$AWS_SESSION_TOKEN`, if
@ -25,25 +28,34 @@ plugins=(... aws)
* `agp`: gets the current value of `$AWS_PROFILE`.
* `agr`: gets the current value of `$AWS_REGION`.
* `aws_change_access_key`: changes the AWS access key of a profile.
* `aws_profiles`: lists the available profiles in the `$AWS_CONFIG_FILE` (default: `~/.aws/config`).
Used to provide completion for the `asp` function.
* `aws_regions`: lists the available regions.
Used to provide completion for the `asr` function.
## Plugin options
* Set `SHOW_AWS_PROMPT=false` in your zshrc file if you want to prevent the plugin from modifying your RPROMPT.
Some themes might overwrite the value of RPROMPT instead of appending to it, so they'll need to be fixed to
see the AWS profile prompt.
see the AWS profile/region prompt.
## Theme
The plugin creates an `aws_prompt_info` function that you can use in your theme, which displays
the current `$AWS_PROFILE`. It uses two variables to control how that is shown:
the current `$AWS_PROFILE` and `$AWS_REGION`. It uses four variables to control how that is shown:
* ZSH_THEME_AWS_PREFIX: sets the prefix of the AWS_PROFILE. Defaults to `<aws:`.
* ZSH_THEME_AWS_PROFILE_PREFIX: sets the prefix of the AWS_PROFILE. Defaults to `<aws:`.
* ZSH_THEME_AWS_SUFFIX: sets the suffix of the AWS_PROFILE. Defaults to `>`.
* ZSH_THEME_AWS_PROFILE_SUFFIX: sets the suffix of the AWS_PROFILE. Defaults to `>`.
* ZSH_THEME_AWS_REGION_PREFIX: sets the prefix of the AWS_REGION. Defaults to `<region:`.
* ZSH_THEME_AWS_REGION_SUFFIX: sets the suffix of the AWS_REGION. Defaults to `>`.
## Configuration

View file

@ -2,10 +2,14 @@ function agp() {
echo $AWS_PROFILE
}
function agr() {
echo $AWS_REGION
}
# AWS profile selection
function asp() {
if [[ -z "$1" ]]; then
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE AWS_PROFILE_REGION
echo AWS profile cleared.
return
fi
@ -22,11 +26,32 @@ function asp() {
export AWS_PROFILE=$1
export AWS_EB_PROFILE=$1
export AWS_PROFILE_REGION=$(aws configure get region)
if [[ "$2" == "login" ]]; then
aws sso login
fi
}
# AWS region selection
function asr() {
if [[ -z "$1" ]]; then
unset AWS_DEFAULT_REGION AWS_REGION
echo AWS region cleared.
return
fi
local -a available_regions
available_regions=($(aws_regions))
if [[ -z "${available_regions[(r)$1]}" ]]; then
echo "${fg[red]}Available regions: \n$(aws_regions)"
return 1
fi
export AWS_REGION=$1
export AWS_DEFAULT_REGION=$1
}
# AWS profile switch
function acp() {
if [[ -z "$1" ]]; then
@ -145,12 +170,25 @@ function aws_change_access_key() {
AWS_PAGER="" aws iam list-access-keys
}
function aws_regions() {
if [[ $AWS_DEFAULT_PROFILE || $AWS_PROFILE ]];then
aws ec2 describe-regions |grep RegionName | awk -F ':' '{gsub(/"/, "", $2);gsub(/,/, "", $2);gsub(/ /, "", $2); print $2}'
else
echo "You must specify a AWS profile."
fi
}
function aws_profiles() {
aws --no-cli-pager configure list-profiles 2> /dev/null && return
[[ -r "${AWS_CONFIG_FILE:-$HOME/.aws/config}" ]] || return 1
grep --color=never -Eo '\[.*\]' "${AWS_CONFIG_FILE:-$HOME/.aws/config}" | sed -E 's/^[[:space:]]*\[(profile)?[[:space:]]*([^[:space:]]+)\][[:space:]]*$/\2/g'
}
function _aws_regions() {
reply=($(aws_regions))
}
compctl -K _aws_regions asr
function _aws_profiles() {
reply=($(aws_profiles))
}
@ -158,15 +196,22 @@ compctl -K _aws_profiles asp acp aws_change_access_key
# AWS prompt
function aws_prompt_info() {
[[ -n "$AWS_PROFILE" ]] || return
echo "${ZSH_THEME_AWS_PREFIX=<aws:}${AWS_PROFILE:gs/%/%%}${ZSH_THEME_AWS_SUFFIX=>}"
local _aws_to_show
local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}"
if [[ -n $AWS_PROFILE ]];then
_aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=<aws:}${AWS_PROFILE}${ZSH_THEME_AWS_PROFILE_SUFFIX:=>}"
fi
if [[ -n $AWS_REGION ]]; then
[[ -n $AWS_PROFILE ]] && _aws_to_show+=" "
_aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX:=<region:}${region}${ZSH_THEME_AWS_REGION_SUFFIX:=>}"
fi
echo "$_aws_to_show"
}
if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then
RPROMPT='$(aws_prompt_info)'"$RPROMPT"
fi
# Load awscli completions
# AWS CLI v2 comes with its own autocompletion. Check if that is there, otherwise fall back
@ -211,3 +256,4 @@ else
[[ -r $_aws_zsh_completer_path ]] && source $_aws_zsh_completer_path
unset _aws_zsh_completer_path _brew_prefix
fi

View file

@ -32,12 +32,14 @@ function _az-homebrew-installed() {
(( $+commands[brew] )) || return 1
# speculatively check default brew prefix
if [ -h /usr/local/opt/az ]; then
_brew_prefix=/usr/local/opt/az
if [[ -d /usr/local ]]; then
_brew_prefix=/usr/local
elif [[ -d /opt/homebrew ]]; then
_brew_prefix=/opt/homebrew
else
# ok, it is not in the default prefix
# this call to brew is expensive (about 400 ms), so at least let's make it only once
_brew_prefix=$(brew --prefix azure-cli)
_brew_prefix=$(brew --prefix)
fi
}
@ -49,12 +51,12 @@ _az_zsh_completer_path="$commands[az_zsh_completer.sh]"
if [[ -z $_az_zsh_completer_path ]]; then
# Homebrew
if _az-homebrew-installed; then
_az_zsh_completer_path=$_brew_prefix/libexec/bin/az.completion.sh
_az_zsh_completer_path=$_brew_prefix/etc/bash_completion.d/az
# Linux
else
_az_zsh_completer_path=/etc/bash_completion.d/azure-cli
fi
fi
[[ -r $_az_zsh_completer_path ]] && source $_az_zsh_completer_path
[[ -r $_az_zsh_completer_path ]] && autoload -U +X bashcompinit && bashcompinit && source $_az_zsh_completer_path
unset _az_zsh_completer_path _brew_prefix

View file

@ -21,7 +21,6 @@ defined for convenience.
| -------- | --------------------------------------- | ------------------------------------------------------------------- |
| `bcubc` | `brew upgrade --cask && brew cleanup` | Update outdated casks, then run cleanup. |
| `bcubo` | `brew update && brew outdated --cask` | Update Homebrew data, then list outdated casks. |
| `bcubc` | `brew upgrade --cask && brew cleanup` | Update outdated casks, then run cleanup. |
| `brewp` | `brew pin` | Pin a specified formula so that it's not upgraded. |
| `brews` | `brew list -1` | List installed formulae or the installed files for a given formula. |
| `brewsp` | `brew list --pinned` | List pinned formulae, or show the version of a given formula. |

View file

@ -1,10 +1,10 @@
# extract plugin
This plugin defines a function called `extract` that extracts the archive file
you pass it, and it supports a wide variety of archive filetypes.
This plugin defines a function called `extract` that extracts the archive file you pass it, and it supports a
wide variety of archive filetypes.
This way you don't have to know what specific command extracts a file, you just
do `extract <filename>` and the function takes care of the rest.
This way you don't have to know what specific command extracts a file, you just do `extract <filename>` and
the function takes care of the rest.
To use it, add `extract` to the plugins array in your zshrc file:
@ -15,7 +15,7 @@ plugins=(... extract)
## Supported file extensions
| Extension | Description |
|:------------------|:-------------------------------------|
| :---------------- | :----------------------------------- |
| `7z` | 7zip file |
| `Z` | Z archive (LZW) |
| `apk` | Android app file |
@ -32,6 +32,7 @@ plugins=(... extract)
| `lrz` | LRZ archive |
| `lz4` | LZ4 archive |
| `lzma` | LZMA archive |
| `obscpio` | cpio archive used on OBS |
| `rar` | WinRAR archive |
| `rpm` | RPM package |
| `sublime-package` | Sublime Text package |
@ -57,5 +58,5 @@ plugins=(... extract)
| `zst` | Zstandard file (zstd) |
| `zpaq` | Zpaq file |
See [list of archive formats](https://en.wikipedia.org/wiki/List_of_archive_formats) for
more information regarding archive formats.
See [list of archive formats](https://en.wikipedia.org/wiki/List_of_archive_formats) for more information
regarding archive formats.

View file

@ -3,5 +3,5 @@
_arguments \
'(-r --remove)'{-r,--remove}'[Remove archive.]' \
"*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|cab|cpio|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst|zpaq)(-.)'" \
"*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|cab|cpio|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|obscpio|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst|zpaq)(-.)'" \
&& return 0

View file

@ -72,7 +72,7 @@ EOF
builtin cd -q ..; command rm *.tar.* debian-binary ;;
(*.zst) unzstd "$file" ;;
(*.cab) cabextract -d "$extract_dir" "$file" ;;
(*.cpio) cpio -idmvF "$file" ;;
(*.cpio|*.obscpio) cpio -idmvF "$file" ;;
(*.zpaq) zpaq x "$file" ;;
(*)
echo "extract: '$file' cannot be extracted" >&2

View file

@ -19,7 +19,7 @@ __gnu_utils() {
'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate'
'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand'
'gexpr' 'gfactor' 'gfalse' 'gfmt' 'gfold' 'ggroups' 'ghead' 'ghostid'
'gid' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum'
'gid' 'gindent' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum'
'gmkdir' 'gmkfifo' 'gmknod' 'gmktemp' 'gmv' 'gnice' 'gnl' 'gnohup' 'gnproc'
'god' 'gpaste' 'gpathchk' 'gpinky' 'gpr' 'gprintenv' 'gprintf' 'gptx' 'gpwd'
'greadlink' 'grm' 'grmdir' 'gruncon' 'gseq' 'gsha1sum' 'gsha224sum'
@ -61,3 +61,14 @@ __gnu_utils_preexec() {
autoload -Uz add-zsh-hook
add-zsh-hook preexec __gnu_utils_preexec
# lib/theme-and-appearance.zsh sets the alias for ls not knowing that
# we'll be using GNU ls. We'll reset this to use GNU ls --color.
# See https://github.com/ohmyzsh/ohmyzsh/issues/11503
#
# The ls alias might look like:
# - ls='ls -G'
# - ls='gls --color=tty'
if [[ -x "${commands[gls]}" && "${aliases[ls]}" = (*-G*|gls*) ]]; then
alias ls='ls --color=tty'
fi

View file

@ -2,11 +2,20 @@
This plugin adds a few functions that are useful when using [iTerm2](https://www.iterm2.com/).
To use it, add _iterm2_ to the plugins array of your zshrc file:
```
plugins=(... iterm2)
```
Optionally, the plugin also applies the [Shell Integration Script for iTerm2](https://iterm2.com/documentation-shell-integration.html).
You can enable the integration with zstyle. It's important to add this line
before the line sourcing oh-my-zsh:
```
zstyle :omz:plugins:iterm2 shell-integration yes
```
## Plugin commands
* `_iterm2_command <iterm2-command>`
@ -24,6 +33,9 @@ plugins=(... iterm2)
* `iterm2_tab_color_reset`
resets the color of iTerm2's current tab back to default.
For shell integration features see the [official documentation](https://iterm2.com/documentation-shell-integration.html).
## Contributors
- [Aviv Rosenberg](https://github.com/avivrosenberg)

View file

@ -7,6 +7,17 @@
# This plugin is only relevant if the terminal is iTerm2 on OSX.
if [[ "$OSTYPE" == darwin* ]] && [[ -n "$ITERM_SESSION_ID" ]] ; then
# maybe make it the default in the future and allow opting out?
if zstyle -t ':omz:plugins:iterm2' shell-integration; then
# Handle $0 according to the standard:
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"
# See official docs: https://iterm2.com/documentation-shell-integration.html
source "${0:A:h}/iterm2_shell_integration.zsh"
fi
###
# Executes an arbitrary iTerm2 command via an escape code sequence.
# See https://iterm2.com/documentation-escape-codes.html for all supported commands.

View file

@ -0,0 +1,178 @@
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
if [[ -o interactive ]]; then
if [ "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "tmux-256color" -a "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "screen" -a "${ITERM_SHELL_INTEGRATION_INSTALLED-}" = "" -a "$TERM" != linux -a "$TERM" != dumb ]; then
ITERM_SHELL_INTEGRATION_INSTALLED=Yes
ITERM2_SHOULD_DECORATE_PROMPT="1"
# Indicates start of command output. Runs just before command executes.
iterm2_before_cmd_executes() {
if [ "$TERM_PROGRAM" = "iTerm.app" ]; then
printf "\033]133;C;\r\007"
else
printf "\033]133;C;\007"
fi
}
iterm2_set_user_var() {
printf "\033]1337;SetUserVar=%s=%s\007" "$1" $(printf "%s" "$2" | base64 | tr -d '\n')
}
# Users can write their own version of this method. It should call
# iterm2_set_user_var but not produce any other output.
# e.g., iterm2_set_user_var currentDirectory $PWD
# Accessible in iTerm2 (in a badge now, elsewhere in the future) as
# \(user.currentDirectory).
whence -v iterm2_print_user_vars > /dev/null 2>&1
if [ $? -ne 0 ]; then
iterm2_print_user_vars() {
true
}
fi
iterm2_print_state_data() {
local _iterm2_hostname="${iterm2_hostname-}"
if [ -z "${iterm2_hostname:-}" ]; then
_iterm2_hostname=$(hostname -f 2>/dev/null)
fi
printf "\033]1337;RemoteHost=%s@%s\007" "$USER" "${_iterm2_hostname-}"
printf "\033]1337;CurrentDir=%s\007" "$PWD"
iterm2_print_user_vars
}
# Report return code of command; runs after command finishes but before prompt
iterm2_after_cmd_executes() {
printf "\033]133;D;%s\007" "$STATUS"
iterm2_print_state_data
}
# Mark start of prompt
iterm2_prompt_mark() {
printf "\033]133;A\007"
}
# Mark end of prompt
iterm2_prompt_end() {
printf "\033]133;B\007"
}
# There are three possible paths in life.
#
# 1) A command is entered at the prompt and you press return.
# The following steps happen:
# * iterm2_preexec is invoked
# * PS1 is set to ITERM2_PRECMD_PS1
# * ITERM2_SHOULD_DECORATE_PROMPT is set to 1
# * The command executes (possibly reading or modifying PS1)
# * iterm2_precmd is invoked
# * ITERM2_PRECMD_PS1 is set to PS1 (as modified by command execution)
# * PS1 gets our escape sequences added to it
# * zsh displays your prompt
# * You start entering a command
#
# 2) You press ^C while entering a command at the prompt.
# The following steps happen:
# * (iterm2_preexec is NOT invoked)
# * iterm2_precmd is invoked
# * iterm2_before_cmd_executes is called since we detected that iterm2_preexec was not run
# * (ITERM2_PRECMD_PS1 and PS1 are not messed with, since PS1 already has our escape
# sequences and ITERM2_PRECMD_PS1 already has PS1's original value)
# * zsh displays your prompt
# * You start entering a command
#
# 3) A new shell is born.
# * PS1 has some initial value, either zsh's default or a value set before this script is sourced.
# * iterm2_precmd is invoked
# * ITERM2_SHOULD_DECORATE_PROMPT is initialized to 1
# * ITERM2_PRECMD_PS1 is set to the initial value of PS1
# * PS1 gets our escape sequences added to it
# * Your prompt is shown and you may begin entering a command.
#
# Invariants:
# * ITERM2_SHOULD_DECORATE_PROMPT is 1 during and just after command execution, and "" while the prompt is
# shown and until you enter a command and press return.
# * PS1 does not have our escape sequences during command execution
# * After the command executes but before a new one begins, PS1 has escape sequences and
# ITERM2_PRECMD_PS1 has PS1's original value.
iterm2_decorate_prompt() {
# This should be a raw PS1 without iTerm2's stuff. It could be changed during command
# execution.
ITERM2_PRECMD_PS1="$PS1"
ITERM2_SHOULD_DECORATE_PROMPT=""
# Add our escape sequences just before the prompt is shown.
# Use ITERM2_SQUELCH_MARK for people who can't mdoify PS1 directly, like powerlevel9k users.
# This is gross but I had a heck of a time writing a correct if statetment for zsh 5.0.2.
local PREFIX=""
if [[ $PS1 == *"$(iterm2_prompt_mark)"* ]]; then
PREFIX=""
elif [[ "${ITERM2_SQUELCH_MARK-}" != "" ]]; then
PREFIX=""
else
PREFIX="%{$(iterm2_prompt_mark)%}"
fi
PS1="$PREFIX$PS1%{$(iterm2_prompt_end)%}"
ITERM2_DECORATED_PS1="$PS1"
}
iterm2_precmd() {
local STATUS="$?"
if [ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]; then
# You pressed ^C while entering a command (iterm2_preexec did not run)
iterm2_before_cmd_executes
if [ "$PS1" != "${ITERM2_DECORATED_PS1-}" ]; then
# PS1 changed, perhaps in another precmd. See issue 9938.
ITERM2_SHOULD_DECORATE_PROMPT="1"
fi
fi
iterm2_after_cmd_executes "$STATUS"
if [ -n "$ITERM2_SHOULD_DECORATE_PROMPT" ]; then
iterm2_decorate_prompt
fi
}
# This is not run if you press ^C while entering a command.
iterm2_preexec() {
# Set PS1 back to its raw value prior to executing the command.
PS1="$ITERM2_PRECMD_PS1"
ITERM2_SHOULD_DECORATE_PROMPT="1"
iterm2_before_cmd_executes
}
# If hostname -f is slow on your system set iterm2_hostname prior to
# sourcing this script. We know it is fast on macOS so we don't cache
# it. That lets us handle the hostname changing like when you attach
# to a VPN.
if [ -z "${iterm2_hostname-}" ]; then
if [ "$(uname)" != "Darwin" ]; then
iterm2_hostname=`hostname -f 2>/dev/null`
# Some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option.
if [ $? -ne 0 ]; then
iterm2_hostname=`hostname`
fi
fi
fi
[[ -z ${precmd_functions-} ]] && precmd_functions=()
precmd_functions=($precmd_functions iterm2_precmd)
[[ -z ${preexec_functions-} ]] && preexec_functions=()
preexec_functions=($preexec_functions iterm2_preexec)
iterm2_print_state_data
printf "\033]1337;ShellIntegrationVersion=14;shell=zsh\007"
fi
fi

4
plugins/iterm2/update Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
curl -s -L https://iterm2.com/shell_integration/zsh \
-o iterm2_shell_integration.zsh

View file

@ -126,5 +126,7 @@ Naming convention:
- `jaddr <app_name> [unit_num]`: display app or unit IP address.
- `jreld <relation_name> <app_name> <unit_num>`: display app and unit relation data.
- `jclean`: destroy all controllers
- `jcontroller`: display the controller your are connected to.
- `jmodel`: display the model your are connected to.
- `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval
(default: 5s); you may pass additional arguments to `watch`.

View file

@ -163,10 +163,40 @@ jreld() {
juju run "relation-get -r $relid - $2" --unit $2/$3
}
# Return Juju current controller
jcontroller() {
local controller="$(awk '/current-controller/ {print $2}' ~/.local/share/juju/controllers.yaml)"
if [[ -z "$controller" ]]; then
return 1
fi
echo $controller
return 0
}
# Return Juju current model
jmodel() {
local yqbin="$(whereis yq | awk '{print $2}')"
if [[ -z "$yqbin" ]]; then
echo "--"
return 1
fi
local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)"
if [[ -z "$model" ]]; then
echo "--"
return 1
fi
echo $model
return 0
}
# Watch juju status, with optional interval (default: 5 sec)
wjst() {
local interval="${1:-5}"
shift $(( $# > 0 ))
watch -n "$interval" --color juju status --relations --color "$@"
}

View file

@ -25,7 +25,7 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
| `pxd` | Return the current Xcode project directory |
| `cdx` | `cd` to the current Xcode project directory |
| `quick-look` | Quick-Look a specified file |
| `man-preview` | Open a specified man page in Preview app |
| `man-preview` | Open man pages in Preview app |
| `showfiles` | Show hidden files in Finder |
| `hidefiles` | Hide the hidden files in Finder |
| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on |

View file

@ -224,9 +224,10 @@ function quick-look() {
}
function man-preview() {
local location
# Don't let Preview.app steal focus if the man page doesn't exist
location=$(man -w "$@") && mandoc -Tpdf $location | open -f -a Preview
local page
for page in "${(@f)"$(man -w $@)"}"; do
command mandoc -Tpdf $page | open -f -a Preview
done
}
compdef _man man-preview

View file

@ -3,10 +3,5 @@
# If marked is passed a file, open it in Marked
#
function marked() {
if [ "$1" ]
then
open -a "marked 2.app" "$1"
else
open -a "marked 2.app"
fi
open -a "marked 2.app" "$1"
}

View file

@ -0,0 +1,17 @@
## marktext
Plugin for MarkText, a previewer for Markdown files on Mac OS X
### Requirements
* [MarkText](https://github.com/marktext/marktext)
### Usage
* If `marktext` is called without an argument, open MarkText
* If `marktext` is passed a file, open it in MarkText
### Credits
* just copied from plugins/marked2, all credits to marked2 plugin author

View file

@ -0,0 +1,7 @@
#
# If marktext is called without an argument, open MarkText
# If marktext is passed a file, open it in MarkText
#
function marktext() {
open -a "MarkText.app" "$1"
}

20
plugins/nodenv/README.md Normal file
View file

@ -0,0 +1,20 @@
# nodenv plugin
The primary job of this plugin is to provide `nodenv_prompt_info` which can be added to your theme to include Node
version information into your prompt.
To use it, add `nodenv` to the plugins array in your zshrc file:
```zsh
plugins=(... nodenv)
```
## Functions
* `nodenv_prompt_info`: displays the Node version in use by nodenv; or the global Node
version, if nodenv wasn't found. You can use this function in your prompt by adding
`$(nodenv_prompt_info)` to PROMPT or RPROMPT:
```zsh
RPROMPT='$(nodenv_prompt_info)'
```

View file

@ -0,0 +1,43 @@
# This plugin loads nodenv into the current shell and provides prompt info via
# the 'nodenv_prompt_info' function.
FOUND_NODENV=${+commands[nodenv]}
if [[ $FOUND_NODENV -ne 1 ]]; then
nodenvdirs=(
"$HOME/.nodenv"
"/usr/local/nodenv"
"/opt/nodenv"
"/usr/local/opt/nodenv"
)
for dir in $nodenvdirs; do
if [[ -d "${dir}/bin" ]]; then
export PATH="$PATH:${dir}/bin"
FOUND_NODENV=1
break
fi
done
if [[ $FOUND_NODENV -ne 1 ]]; then
if (( $+commands[brew] )) && dir=$(brew --prefix nodenv 2>/dev/null); then
if [[ -d "${dir}/bin" ]]; then
export PATH="$PATH:${dir}/bin"
FOUND_NODENV=1
fi
fi
fi
fi
if [[ $FOUND_NODENV -eq 1 ]]; then
eval "$(nodenv init --no-rehash - zsh)"
function nodenv_prompt_info() {
nodenv version-name 2>/dev/null
}
else
# fallback to system node
function nodenv_prompt_info() {
echo "system: $(node -v 2>&1 | cut -c 2-)"
}
fi
unset FOUND_NODENV nodenvdirs dir

View file

@ -47,6 +47,7 @@ plugins=(... rails)
| `rsp` | `rails server --port` | Launch a web server and specify the listening port |
| `rsts` | `rails stats` | Print code statistics |
| `rt` | `rails test` | Run Rails tests |
| `rta` | `rails test:all` | Runs all Rails tests, including system tests |
| `ru` | `rails runner` | Run Ruby code in the context of Rails |
### Foreman

View file

@ -75,6 +75,7 @@ alias rsd='rails server --debugger'
alias rsp='rails server --port'
alias rsts='rails stats'
alias rt='rails test'
alias rta='rails test:all'
alias ru='rails runner'
# Foreman aliases

View file

@ -24,6 +24,7 @@ plugins=(... rvm)
| `rb27` | `rvm use ruby-2.7` |
| `rb30` | `rvm use ruby-3.0` |
| `rb31` | `rvm use ruby-3.1` |
| `rb32` | `rvm use ruby-3.2` |
| `rvm-update` | `rvm get head` |
| `gems` | `gem list` |
| `rvms` | `rvm gemset` |

View file

@ -27,6 +27,7 @@ rubies=(
27 'ruby-2.7'
30 'ruby-3.0'
31 'ruby-3.1'
32 'ruby-3.2'
)
for v in ${(k)rubies}; do

View file

@ -19,6 +19,7 @@ plugins=(... terraform)
| ----- | -------------------- |
| `tf` | `terraform` |
| `tfa` | `terraform apply` |
| `tfc` | `terraform console` |
| `tfd` | `terraform destroy` |
| `tff` | `terraform fmt` |
| `tfi` | `terraform init` |

View file

@ -0,0 +1,411 @@
#compdef terraform
local -a _terraform_cmds opt_args
_terraform_cmds=(
'apply:Builds or changes infrastructure'
'console:Interactive console for Terraform interpolations'
'destroy:Destroy Terraform-managed infrastructure'
'fmt:Rewrites config files to canonical format'
'force-unlock:Manually unlock the terraform state'
'get:Download and install modules for the configuration'
'graph:Create a visual graph of Terraform resources'
'import:Import existing infrastructure into Terraform'
'init:Initialize a Terraform working directory'
'login:Obtain and save credentials for a remote host'
'logout:Remove locally-stored credentials for a remote host'
'output:Read an output from a state file'
'plan:Generate and show an execution plan'
'providers:Prints a tree of the providers used in the configuration'
'refresh:Update local state file against real resources'
'show:Inspect Terraform state or plan'
'state:Advanced state management'
'taint:Manually mark a resource for recreation'
'untaint:Manually unmark a resource as tainted'
'validate:Validates the Terraform files'
'version:Prints the Terraform version'
'workspace:Workspace management'
'0.12upgrade:Rewrites pre-0.12 module source code for v0.12'
'0.13upgrade:Rewrites pre-0.13 module source code for v0.13'
)
__012upgrade() {
_arguments \
'-yes[Skip the initial introduction messages and interactive confirmation. This can be used to run this command in batch from a script.]' \
'-force[ Override the heuristic that attempts to detect if a configuration is already written for v0.12 or later. Some of the transformations made by this command are not idempotent, so re-running against the same module may change the meanings expressions in the module.]'
}
__013upgrade() {
_arguments \
'-yes[Skip the initial introduction messages and interactive confirmation. This can be used to run this command in batch from a script.]'
}
__apply() {
_arguments \
'-auto-approve[Skip interactive approval of plan before applying.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-no-color[If specified, output will be colorless.]' \
'-parallelism=[(10) Limit the number of parallel resource operations.]' \
'-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
'*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
'*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
}
__console() {
_arguments \
'-state=[(terraform.tfstate) Path to read state.]' \
'*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
}
__destroy() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-auto-approve[Skip interactive approval before destroying.]' \
'-force[Deprecated: same as auto-approve.]' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will contain no color.]' \
'-parallelism=[(10) Limit the number of concurrent operations.]' \
'-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
'*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
'*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
}
__fmt() {
_arguments \
'-list=[(true) List files whose formatting differs (always false if using STDIN)]' \
'-write=[(true) Write result to source file instead of STDOUT (always false if using STDIN or -check)]' \
'-diff=[(false) Display diffs of formatting changes]' \
'-check=[(false) Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.]' \
'-recursive=[(false) Also process files in subdirectories. By default, only the given directory (or current directory) is processed.]'
}
__force_unlock() {
_arguments \
"-force[Don't ask for input for unlock confirmation.]"
}
__get() {
_arguments \
'-update=[(false) If true, modules already downloaded will be checked for updates and updated if necessary.]' \
'-no-color[Disable text coloring in the output.]'
}
__graph() {
_arguments \
'-draw-cycles[Highlight any cycles in the graph with colored edges. This helps when diagnosing cycle errors.]' \
'-type=[(plan) Type of graph to output. Can be: plan, plan-destroy, apply, validate, input, refresh.]'
}
__import() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-config=[(path) Path to a directory of Terraform configuration files to use to configure the provider. Defaults to pwd. If no config files are present, they must be provided via the input prompts or env vars.]' \
'-allow-missing-config[Allow import when no resource configuration block exists.]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will contain no color.]' \
'-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
'-state-out=[(PATH) Path to the destination state file to write to. If this is not specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -g "*.tfstate"' \
'*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times. This is only useful with the "-config" flag.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
}
__init() {
_arguments \
'-backend=[(true) Configure the backend for this configuration.]' \
'-backend-config=[This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a 'key=value' format. This is merged with what is in the configuration file. This can be specified multiple times. The backend type must be in the configuration itself.]' \
'-force-copy[Suppress prompts about copying state data. This is equivalent to providing a "yes" to all confirmation prompts.]' \
'-from-module=[(SOURCE) Copy the contents of the given module into the target directory before initialization.]' \
'-get=[(true) Download any modules for this configuration.]' \
'-get-plugins=[(true) Download any missing plugins for this configuration.]' \
'-input=[(true) Ask for input if necessary. If false, will error if input was required.]' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will contain no color.]' \
'-plugin-dir[Directory containing plugin binaries. This overrides all default search paths for plugins, and prevents the automatic installation of plugins. This flag can be used multiple times.]:plugin_dir:_files -/' \
'-reconfigure[Reconfigure the backend, ignoring any saved configuration.]' \
'-upgrade=[(false) If installing modules (-get) or plugins (-get-plugins), ignore previously-downloaded objects and install the latest version allowed within configured constraints.]' \
'-verify-plugins=[(true) Verify the authenticity and integrity of automatically downloaded plugins.]'
}
__login() {
_arguments \
}
__logout() {
_arguments \
}
__output() {
_arguments \
'-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
'-no-color[If specified, output will contain no color.]' \
'-json[If specified, machine readable output will be printed in JSON format]'
}
__plan() {
_arguments \
'-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
'-destroy[If set, a plan will be generated to destroy all resources managed by the given configuration and state.]' \
'-detailed-exitcode[() Return detailed exit codes when the command exits. This will change the meaning of exit codes to: 0 - Succeeded, diff is empty (no changes); 1 - Errored, 2 - Succeeded; there is a diff]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[() If specified, output will contain no color.]' \
'-out=[(path) Write a plan file to the given path. This can be used as input to the "apply" command.]' \
'-parallelism=[(10) Limit the number of concurrent operations.]' \
'-refresh=[(true) Update state prior to checking for differences.]' \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -g "*.tfstate"' \
'*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
'*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
}
__providers() {
local -a __providers_cmds
__providers_cmds=(
'mirror:Mirrors the provider plugins needed for the current configuration'
'schema:Prints the schemas of the providers used in the configuration'
)
_describe -t providers "providers commands" __providers_cmds
}
__providers_mirror() {
_arguments \
'-platform=[(os_arch) Choose which target platform to build a mirror for.]' \
"*:target_dir:_files -/"
}
__providers_schema() {
_arguments \
'-json[]' \
'::'
}
__refresh() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]::backupfile:_files -g "*.backup"' \
'-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will not contain any color.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
'*-target=[(resource) A Resource Address to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
'*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
}
__show() {
_arguments \
'-json[If specified, output the Terraform plan or state in a machine-readable form.]' \
'-no-color[If specified, output will not contain any color.]'
}
__state() {
local -a __state_cmds
__state_cmds=(
'list:List resources in the state'
'mv:Move an item in the state'
'pull:Pull current state and output to stdout'
'push:Update remote state from a local state file'
'replace-provider:Replace provider for resources in the Terraform state'
'rm:Remove instances from the state'
'show:Show a resource in the state'
)
_describe -t state "state commands" __state_cmds
}
__state_list() {
_arguments \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default, Terraform will consult the state of the currently-selected workspace.]' \
'-id=[(id) Filters the results to include only instances whose resource types have an attribute named id whose value equals the given id string.]' \
"*:address:__statelist"
}
__state_mv() {
_arguments \
"-dry-run[If set, prints out what would've been moved but doesn't actually move anything.]" \
'-backup=[(PATH) Path where Terraform should write the backup for the original state. This can"t be disabled. If not set, Terraform will write it to the same path as the statefile with a ".backup" extension.]:backupfile:_files -g "*.backup"' \
'-backup-out=[(PATH) Path where Terraform should write the backup for the destination state. This can"t be disabled. If not set, Terraform will write it to the same path as the destination state file with a backup extension. This only needs to be specified if -state-out is set to a different path than -state.]:backupfile:_files -g "*.backup"' \
"-lock=[(true) Lock the state files when locking is supported.]:lock:(true false)" \
"-lock-timeout=[(0s) Duration to retry a state lock.]" \
'-state=[(path) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to the destination state file to write to. If this isn"t specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -g "*.tfstate"' \
"::" \
":source:__statelist" \
":destination: "
}
__state_push() {
_arguments \
"-force[Write the state even if lineages don't match or the remote serial is higher.]" \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
"-lock-timeout=[(0s) Duration to retry a state lock.]" \
"::" \
":destination:_files"
}
__state_replace_provider() {
_arguments \
'-auto-approve[Skip interactive approval.]' \
'-backup=[(PATH) Path where Terraform should write the backup for the state file. This can"t be disabled. If not set, Terraform will write it to the same path as the state file with a ".backup" extension.]:backupfile:_files -g "*.backup"' \
"-lock=[(true) Lock the state files when locking is supported.]:lock:(true false)" \
"-lock-timeout=[(0s) Duration to retry a state lock.]" \
'-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
":from_provider_fqn:" \
":to_provider_fqn:"
}
__state_rm() {
_arguments \
"-dry-run[If set, prints out what would've been removed but doesn't actually remove anything.]" \
'-backup=[(PATH) Path where Terraform should write the backup for the original state.]::backupfile:_files -g "*.backup"' \
"-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)" \
"-lock-timeout=[(0s) Duration to retry a state lock.]" \
'-state=[(PATH) Path to the state file to update. Defaults to the current workspace state.]:statefile:_files -g "*.tfstate"' \
"*:address:__statelist"
}
__state_show() {
_arguments \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -g "*.tfstate"' \
"*:address:__statelist"
}
__statelist() {
compadd $(terraform state list $opt_args[-state])
}
__taint() {
_arguments \
'-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-module=[(path) The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules).]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"' \
"*:address:__statelist"
}
__untaint() {
_arguments \
'-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
'-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-module=[(path) The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules).]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"'
}
__validate() {
_arguments \
'-no-color[If specified, output will not contain any color.]' \
'-json[Produce output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems.]' \
':dir:_files -/'
}
__version() {
_arguments \
'-json[Output the version information as a JSON object.]'
}
__workspace() {
local -a __workspace_cmds
__workspace_cmds=(
'delete:Delete a workspace'
'list:List Workspaces'
'new:Create a new workspace'
'select:Select a workspace'
'show:Show the name of the current workspace'
)
_describe -t workspace "workspace commands" __workspace_cmds
}
_arguments '*:: :->command'
if (( CURRENT == 1 )); then
_describe -t commands "terraform command" _terraform_cmds
return
fi
local -a _command_args
case "$words[1]" in
0.12upgrade)
__012upgrade ;;
0.13upgrade)
__013upgrade ;;
apply)
__apply ;;
console)
__console;;
destroy)
__destroy ;;
fmt)
__fmt;;
force-unlock)
__force_unlock;;
get)
__get ;;
graph)
__graph ;;
import)
__import;;
init)
__init ;;
login)
__login ;;
logout)
__logout ;;
output)
__output ;;
plan)
__plan ;;
providers)
test $CURRENT -lt 3 && __providers
[[ $words[2] = "mirror" ]] && __providers_mirror
[[ $words[2] = "schema" ]] && __providers_schema
;;
refresh)
__refresh ;;
show)
__show ;;
state)
test $CURRENT -lt 3 && __state
[[ $words[2] = "list" ]] && __state_list
[[ $words[2] = "mv" ]] && __state_mv
[[ $words[2] = "push" ]] && __state_push
[[ $words[2] = "replace-provider" ]] && __state_replace_provider
[[ $words[2] = "rm" ]] && __state_rm
[[ $words[2] = "show" ]] && __state_show
;;
taint)
__taint ;;
untaint)
__untaint ;;
validate)
__validate ;;
version)
__version ;;
workspace)
test $CURRENT -lt 3 && __workspace ;;
esac

View file

@ -10,14 +10,10 @@ function tf_prompt_info() {
alias tf='terraform'
alias tfa='terraform apply'
alias tfc='terraform console'
alias tfd='terraform destroy'
alias tff='terraform fmt'
alias tfi='terraform init'
alias tfo='terraform output'
alias tfp='terraform plan'
alias tfv='terraform validate'
if (( $+commands[terraform] )); then
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C terraform terraform
fi

View file

@ -29,6 +29,8 @@ plugins=(... vi-mode)
VI_MODE_SET_CURSOR=true
```
See [Cursor Styles](#cursor-styles) for controlling how the cursor looks in different modes
- `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode.
See [Mode indicators](#mode-indicators) for details.
@ -49,8 +51,42 @@ MODE_INDICATOR="%F{white}+%f"
INSERT_MODE_INDICATOR="%F{yellow}+%f"
```
You can also use the `vi_mode_prompt_info` function in your prompt, which will display
this mode indicator.
### Adding mode indicators to your prompt
`Vi-mode` by default will add mode indicators to `RPROMPT` **unless** that is defined by
a preceding plugin.
If `PROMPT` or `RPROMPT` is not defined to your liking, you can add mode info manually. The `vi_mode_prompt_info` function is available to insert mode indicator information.
Here are some examples:
```bash
source $ZSH/oh-my-zsh.sh
PROMPT="$PROMPT\$(vi_mode_prompt_info)"
RPROMPT="\$(vi_mode_prompt_info)$RPROMPT"
```
Note the `\$` here, which importantly prevents interpolation at the time of defining, but allows it to be executed for each prompt update event.
## Cursor Styles
You can control the cursor style used in each active vim mode by changing the values of the following variables.
```zsh
# defaults
VI_MODE_CURSOR_NORMAL=2
VI_MODE_CURSOR_VISUAL=6
VI_MODE_CURSOR_INSERT=6
VI_MODE_CURSOR_OPPEND=0
```
- 0, 1 - Blinking block
- 2 - Solid block
- 3 - Blinking underline
- 4 - Solid underline
- 5 - Blinking line
- 6 - Solid line
## Key bindings

View file

@ -14,6 +14,15 @@ typeset -g VI_MODE_RESET_PROMPT_ON_MODE_CHANGE
# Unset or set to any other value to do the opposite.
typeset -g VI_MODE_SET_CURSOR
# Control how the cursor appears in the various vim modes. This only applies
# if $VI_MODE_SET_CURSOR=true.
#
# See https://vt100.net/docs/vt510-rm/DECSCUSR for cursor styles
typeset -g VI_MODE_CURSOR_NORMAL=2
typeset -g VI_MODE_CURSOR_VISUAL=6
typeset -g VI_MODE_CURSOR_INSERT=6
typeset -g VI_MODE_CURSOR_OPPEND=0
typeset -g VI_KEYMAP=main
function _vi-mode-set-cursor-shape-for-keymap() {
@ -22,13 +31,13 @@ function _vi-mode-set-cursor-shape-for-keymap() {
# https://vt100.net/docs/vt510-rm/DECSCUSR
local _shape=0
case "${1:-${VI_KEYMAP:-main}}" in
main) _shape=6 ;; # vi insert: line
viins) _shape=6 ;; # vi insert: line
isearch) _shape=6 ;; # inc search: line
command) _shape=6 ;; # read a command name
vicmd) _shape=2 ;; # vi cmd: block
visual) _shape=2 ;; # vi visual mode: block
viopp) _shape=0 ;; # vi operation pending: blinking block
main) _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line
viins) _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line
isearch) _shape=$VI_MODE_CURSOR_INSERT ;; # inc search: line
command) _shape=$VI_MODE_CURSOR_INSERT ;; # read a command name
vicmd) _shape=$VI_MODE_CURSOR_NORMAL ;; # vi cmd: block
visual) _shape=$VI_MODE_CURSOR_VISUAL ;; # vi visual mode: block
viopp) _shape=$VI_MODE_CURSOR_OPPEND ;; # vi operation pending: blinking block
*) _shape=0 ;;
esac
printf $'\e[%d q' "${_shape}"