Merge branch 'ohmyzsh:master' into master

This commit is contained in:
Ghasem Shirdel 2022-01-23 09:58:25 +03:30 committed by GitHub
commit caf9c3bd6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 339 additions and 153 deletions

View file

@ -16,10 +16,10 @@ plugins=(... aws)
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.
* `acp [<profile>]`: 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 obtained. It
requires the roles to be configured as per the
* `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
obtained. It requires the roles to be configured as per the
[official guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html).
Run `acp` without arguments to clear the profile.

View file

@ -45,6 +45,7 @@ function acp() {
fi
local profile="$1"
local mfa_token="$2"
# Get fallback credentials for if the aws command fails or no command is run
local aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)"
@ -58,9 +59,10 @@ function acp() {
if [[ -n "$mfa_serial" ]]; then
local -a mfa_opt
local mfa_token
echo -n "Please enter your MFA token for $mfa_serial: "
read -r mfa_token
if [[ -z "$mfa_token" ]]; then
echo -n "Please enter your MFA token for $mfa_serial: "
read -r mfa_token
fi
if [[ -z "$sess_duration" ]]; then
echo -n "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role): "
read -r sess_duration

View file

@ -23,12 +23,12 @@ source_env() {
touch "$ZSH_DOTENV_DISALLOWED_LIST"
# early return if disallowed
if command grep -q "$dirpath" "$ZSH_DOTENV_DISALLOWED_LIST" &>/dev/null; then
if command grep -Fx -q "$dirpath" "$ZSH_DOTENV_DISALLOWED_LIST" &>/dev/null; then
return
fi
# check if current directory's .env file is allowed or ask for confirmation
if ! command grep -q "$dirpath" "$ZSH_DOTENV_ALLOWED_LIST" &>/dev/null; then
if ! command grep -Fx -q "$dirpath" "$ZSH_DOTENV_ALLOWED_LIST" &>/dev/null; then
# get cursor column and print new line before prompt if not at line beginning
local column
echo -ne "\e[6n" > /dev/tty

9
plugins/fig/README.md Normal file
View file

@ -0,0 +1,9 @@
# Fig plugin
This plugin sets up completion for [Fig](https://fig.io/).
To use it, add `fig` to the plugins array in your zshrc file:
```zsh
plugins=(... fig)
```

View file

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

View file

@ -24,9 +24,7 @@ compdef _git _git_log_prettily=git-log
# Warn if the current branch is a WIP
function work_in_progress() {
if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
echo "WIP!!"
fi
command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
}
# Check if main exists and use instead of master

View file

@ -11,12 +11,12 @@ command rm -f "${ZSH_CACHE_DIR}/helm_completion"
command mkdir -p "$ZSH_CACHE_DIR/completions"
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `helm`. Otherwise, compinit will have already done that.
# If the completion file does not exist, generate it and then source it
# Otherwise, source it and regenerate in the background
if [[ ! -f "$ZSH_CACHE_DIR/completions/_helm" ]]; then
typeset -g -A _comps
autoload -Uz _helm
_comps[helm]=_helm
helm completion zsh >| "$ZSH_CACHE_DIR/completions/_helm"
source "$ZSH_CACHE_DIR/completions/_helm"
else
source "$ZSH_CACHE_DIR/completions/_helm"
helm completion zsh >| "$ZSH_CACHE_DIR/completions/_helm" &|
fi
helm completion zsh >| "$ZSH_CACHE_DIR/completions/_helm" &|

View file

@ -8,15 +8,15 @@ if (( $+commands[kubectl] )); then
command mkdir -p "$ZSH_CACHE_DIR/completions"
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `kubectl`. Otherwise, compinit will have already done that.
# If the completion file does not exist, generate it and then source it
# Otherwise, source it and regenerate in the background
if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
typeset -g -A _comps
autoload -Uz _kubectl
_comps[kubectl]=_kubectl
kubectl completion zsh >| "$ZSH_CACHE_DIR/completions/_kubectl"
source "$ZSH_CACHE_DIR/completions/_kubectl"
else
source "$ZSH_CACHE_DIR/completions/_kubectl"
kubectl completion zsh >| "$ZSH_CACHE_DIR/completions/_kubectl" &|
fi
kubectl completion zsh >! "$ZSH_CACHE_DIR/completions/_kubectl" &|
fi
# This command is used a LOT both below and in daily life

View file

@ -117,7 +117,7 @@ function listMavenCompletions {
done
# List modules
modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|'))
modules=($(print -l **/pom.xml(-.N:h) | grep -v '/target/classes/META-INF/'))
reply=(
# common lifecycle

9
plugins/poetry/README.md Normal file
View file

@ -0,0 +1,9 @@
# Poetry Plugin
This plugin automatically installs [Poetry](https://python-poetry.org/)'s completions for you, and keeps them up to date as your Poetry version changes.
To use it, add `poetry` to the plugins array in your zshrc file:
```zsh
plugins=(... poetry)
```

View file

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

View file

@ -27,5 +27,5 @@ fi
rustup completions zsh >| "$ZSH_CACHE_DIR/completions/_rustup" &|
cat >| "$ZSH_CACHE_DIR/completions/_cargo" <<'EOF'
#compdef cargo
source $(rustc +${${(z)$(rustup default)}[1]} --print sysroot)/share/zsh/site-functions/_cargo
source "$(rustc +${${(z)$(rustup default)}[1]} --print sysroot)"/share/zsh/site-functions/_cargo
EOF

View file

@ -24,6 +24,20 @@ By pressing the <kbd>esc</kbd> key twice, you will have the same command with `s
$ sudo apt-get install build-essential
```
The same happens for editing files with your default editor (defined in `$SUDO_EDITOR`, `$VISUAL` or `$EDITOR`, in that order):
If the editor defined were `vim`:
```console
$ vim /etc/hosts
```
By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo -e` instead of the editor, that would open that editor with root privileges:
```console
$ sudo -e /etc/hosts
```
### Previous executed commands
Say you want to delete a system file and denied:
@ -44,6 +58,8 @@ Password:
$
```
The same happens for file editing, as told before.
## Key binding
By default, the `sudo` plugin uses <kbd>Esc</kbd><kbd>Esc</kbd> as the trigger.

View file

@ -2,7 +2,7 @@
# Description
# -----------
#
# sudo or sudoedit will be inserted before the command
# sudo or sudo -e (replacement for sudoedit) will be inserted before the command
#
# ------------------------------------------------------------------------------
# Authors
@ -11,14 +11,19 @@
# * Dongweiming <ciici123@gmail.com>
# * Subhaditya Nath <github.com/subnut>
# * Marc Cornellà <github.com/mcornella>
# * Carlo Sala <carlosalag@protonmail.com>
#
# ------------------------------------------------------------------------------
__sudo-replace-buffer() {
local old=$1 new=$2 space=${2:+ }
if [[ ${#LBUFFER} -le ${#old} ]]; then
RBUFFER="${space}${BUFFER#$old }"
LBUFFER="${new}"
# if the cursor is positioned in the $old part of the text, make
# the substitution and leave the cursor after the $new text
if [[ $CURSOR -le ${#old} ]]; then
BUFFER="${new}${space}${BUFFER#$old }"
CURSOR=${#new}
# otherwise just replace $old with $new in the text before the cursor
else
LBUFFER="${new}${space}${LBUFFER#$old }"
fi
@ -35,14 +40,21 @@ sudo-command-line() {
LBUFFER="${LBUFFER:1}"
fi
# If $EDITOR is not set, just toggle the sudo prefix on and off
if [[ -z "$EDITOR" ]]; then
case "$BUFFER" in
sudoedit\ *) __sudo-replace-buffer "sudoedit" "" ;;
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
*) LBUFFER="sudo $LBUFFER" ;;
esac
else
{
# If $SUDO_EDITOR or $VISUAL are defined, then use that as $EDITOR
# Else use the default $EDITOR
local EDITOR=${SUDO_EDITOR:-${VISUAL:-$EDITOR}}
# If $EDITOR is not set, just toggle the sudo prefix on and off
if [[ -z "$EDITOR" ]]; then
case "$BUFFER" in
sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "" ;;
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
*) LBUFFER="sudo $LBUFFER" ;;
esac
return
fi
# Check if the typed command is really an alias to $EDITOR
# Get the first part of the typed command
@ -67,24 +79,25 @@ sudo-command-line() {
if [[ "$realcmd" = (\$EDITOR|$editorcmd|${editorcmd:c}) \
|| "${realcmd:c}" = ($editorcmd|${editorcmd:c}) ]] \
|| builtin which -a "$realcmd" | command grep -Fx -q "$editorcmd"; then
editorcmd="$cmd" # replace $editorcmd with the typed command so it matches below
__sudo-replace-buffer "$cmd" "sudo -e"
return
fi
# Check for editor commands in the typed command and replace accordingly
case "$BUFFER" in
$editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudoedit" ;;
\$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudoedit" ;;
sudoedit\ *) __sudo-replace-buffer "sudoedit" "$EDITOR" ;;
$editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudo -e" ;;
\$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudo -e" ;;
sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "$EDITOR" ;;
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
*) LBUFFER="sudo $LBUFFER" ;;
esac
fi
} always {
# Preserve beginning space
LBUFFER="${WHITESPACE}${LBUFFER}"
# Preserve beginning space
LBUFFER="${WHITESPACE}${LBUFFER}"
# Redisplay edit buffer (compatibility with zsh-syntax-highlighting)
zle redisplay
# Redisplay edit buffer (compatibility with zsh-syntax-highlighting)
zle redisplay
}
}
zle -N sudo-command-line

View file

@ -55,7 +55,7 @@ svn_get_branch_name() {
}
svn_get_rev_nr() {
sed -n 's/Revision:\ //p' "${1:-$(LANG= svn info 2>/dev/null)}"
sed -n 's/Revision:\ //p' <<<"${1:-$(LANG= svn info 2>/dev/null)}"
}
svn_dirty() {
@ -67,10 +67,10 @@ svn_dirty_choose() {
root=$(sed -n 's/^Working Copy Root Path: //p' <<< "${1:-$(LANG= svn info 2>/dev/null)}")
if LANG= svn status "$root" 2>/dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
# Grep exits with 0 when "One or more lines were selected", return "dirty".
echo $1
echo $2
else
# Otherwise, no lines were found, or an error occurred. Return clean.
echo $2
echo $3
fi
}

View file

@ -15,20 +15,21 @@ The plugin also supports the following:
## Aliases
| Alias | Command | Description |
| ------ | -----------------------|---------------------------------------------------------- |
| `ta` | tmux attach -t | Attach new tmux session to already running named session |
| `tad` | tmux attach -d -t | Detach named tmux session |
| `ts` | tmux new-session -s | Create a new named tmux session |
| `tl` | tmux list-sessions | Displays a list of running tmux sessions |
| `tksv` | tmux kill-server | Terminate all running tmux sessions |
| `tkss` | tmux kill-session -t | Terminate named running tmux session |
| `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session |
| Alias | Command | Description |
| ---------- | ---------------------- | -------------------------------------------------------- |
| `ta` | tmux attach -t | Attach new tmux session to already running named session |
| `tad` | tmux attach -d -t | Detach named tmux session |
| `ts` | tmux new-session -s | Create a new named tmux session |
| `tl` | tmux list-sessions | Displays a list of running tmux sessions |
| `tksv` | tmux kill-server | Terminate all running tmux sessions |
| `tkss` | tmux kill-session -t | Terminate named running tmux session |
| `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session |
| `tmuxconf` | `$EDITOR ~/.tmux.conf` | Open .tmux.conf file with an editor |
## Configuration Variables
| Variable | Description |
|-------------------------------------|-------------------------------------------------------------------------------|
| ----------------------------------- | ----------------------------------------------------------------------------- |
| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) |
| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) |
| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) |

View file

@ -11,6 +11,7 @@ alias ts='tmux new-session -s'
alias tl='tmux list-sessions'
alias tksv='tmux kill-server'
alias tkss='tmux kill-session -t'
alias tmuxconf='$EDITOR ~/.tmux.conf'
# CONFIGURATION VARIABLES
# Automatically start tmux

View file

@ -30,10 +30,10 @@ plugins=(... vi-mode)
```
- `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode.
See [Mode indicator](#mode-indicator) for details.
See [Mode indicators](#mode-indicators) for details.
- `INSERT_MODE_INDICATOR`: controls the string displayed when the shell is in insert mode.
See [Mode indicator](#mode-indicator) for details.
See [Mode indicators](#mode-indicators) for details.
## Mode indicators

View file

@ -116,7 +116,7 @@ _yarn_commands_scripts() {
fi
if [[ -n $packageJson ]]; then
scripts=($(cat "$packageJson" | perl -0777 -MJSON::PP -n -E '%r=decode_json($_); say for sort keys %{$r->{scripts}}'))
scripts=($(cat "$packageJson" | perl -0777 -MJSON::PP -n -E '$r=decode_json($_); do{($k=$_)=~s/:/\\:/g;say $k}for sort keys %{$r->{scripts}}'))
fi
_describe 'command or script' _commands -- _global_commands -- scripts -- binaries
@ -144,7 +144,7 @@ _yarn_scripts() {
fi
if [[ -n $packageJson ]]; then
scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; printf "$_:$r{$_}\n" for sort keys %r')}")
scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}")
fi
commands=('env' $scripts $binaries)