mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-12 01:52:31 +01:00
Merge branch 'ohmyzsh:master' into master
This commit is contained in:
commit
6cc5aef3ab
14 changed files with 213 additions and 146 deletions
|
|
@ -62,47 +62,47 @@ function acp() {
|
|||
read -r sess_duration
|
||||
fi
|
||||
mfa_opt=(--serial-number "$mfa_serial" --token-code "$mfa_token" --duration-seconds "${sess_duration:-3600}")
|
||||
fi
|
||||
|
||||
# Now see whether we need to just MFA for the current role, or assume a different one
|
||||
local role_arn="$(aws configure get role_arn --profile $profile)"
|
||||
local sess_name="$(aws configure get role_session_name --profile $profile)"
|
||||
# Now see whether we need to just MFA for the current role, or assume a different one
|
||||
local role_arn="$(aws configure get role_arn --profile $profile)"
|
||||
local sess_name="$(aws configure get role_session_name --profile $profile)"
|
||||
|
||||
if [[ -n "$role_arn" ]]; then
|
||||
# Means we need to assume a specified role
|
||||
aws_command=(aws sts assume-role --role-arn "$role_arn" "${mfa_opt[@]}")
|
||||
if [[ -n "$role_arn" ]]; then
|
||||
# Means we need to assume a specified role
|
||||
aws_command=(aws sts assume-role --role-arn "$role_arn" "${mfa_opt[@]}")
|
||||
|
||||
# Check whether external_id is configured to use while assuming the role
|
||||
local external_id="$(aws configure get external_id --profile $profile)"
|
||||
if [[ -n "$external_id" ]]; then
|
||||
aws_command+=(--external-id "$external_id")
|
||||
fi
|
||||
|
||||
# Get source profile to use to assume role
|
||||
local source_profile="$(aws configure get source_profile --profile $profile)"
|
||||
if [[ -z "$sess_name" ]]; then
|
||||
sess_name="${source_profile:-profile}"
|
||||
fi
|
||||
aws_command+=(--profile="${source_profile:-profile}" --role-session-name "${sess_name}")
|
||||
|
||||
echo "Assuming role $role_arn using profile ${source_profile:-profile}"
|
||||
else
|
||||
# Means we only need to do MFA
|
||||
aws_command=(aws sts get-session-token --profile="$profile" "${mfa_opt[@]}")
|
||||
echo "Obtaining session token for profile $profile"
|
||||
# Check whether external_id is configured to use while assuming the role
|
||||
local external_id="$(aws configure get external_id --profile $profile)"
|
||||
if [[ -n "$external_id" ]]; then
|
||||
aws_command+=(--external-id "$external_id")
|
||||
fi
|
||||
|
||||
# Format output of aws command for easier processing
|
||||
aws_command+=(--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' --output text)
|
||||
|
||||
# Run the aws command to obtain credentials
|
||||
local -a credentials
|
||||
credentials=(${(ps:\t:)"$(${aws_command[@]})"})
|
||||
|
||||
if [[ -n "$credentials" ]]; then
|
||||
aws_access_key_id="${credentials[1]}"
|
||||
aws_secret_access_key="${credentials[2]}"
|
||||
aws_session_token="${credentials[3]}"
|
||||
# Get source profile to use to assume role
|
||||
local source_profile="$(aws configure get source_profile --profile $profile)"
|
||||
if [[ -z "$sess_name" ]]; then
|
||||
sess_name="${source_profile:-profile}"
|
||||
fi
|
||||
aws_command+=(--profile="${source_profile:-profile}" --role-session-name "${sess_name}")
|
||||
|
||||
echo "Assuming role $role_arn using profile ${source_profile:-profile}"
|
||||
else
|
||||
# Means we only need to do MFA
|
||||
aws_command=(aws sts get-session-token --profile="$profile" "${mfa_opt[@]}")
|
||||
echo "Obtaining session token for profile $profile"
|
||||
fi
|
||||
|
||||
# Format output of aws command for easier processing
|
||||
aws_command+=(--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' --output text)
|
||||
|
||||
# Run the aws command to obtain credentials
|
||||
local -a credentials
|
||||
credentials=(${(ps:\t:)"$(${aws_command[@]})"})
|
||||
|
||||
if [[ -n "$credentials" ]]; then
|
||||
aws_access_key_id="${credentials[1]}"
|
||||
aws_secret_access_key="${credentials[2]}"
|
||||
aws_session_token="${credentials[3]}"
|
||||
fi
|
||||
|
||||
# Switch to AWS profile
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ copybuffer () {
|
|||
if which clipcopy &>/dev/null; then
|
||||
printf "%s" "$BUFFER" | clipcopy
|
||||
else
|
||||
echo "clipcopy function not found. Please make sure you have Oh My Zsh installed correctly."
|
||||
zle -M "clipcopy not found. Please make sure you have Oh My Zsh installed correctly."
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,41 +11,51 @@
|
|||
## Functions
|
||||
|
||||
source_env() {
|
||||
if [[ -f $ZSH_DOTENV_FILE ]]; then
|
||||
if [[ "$ZSH_DOTENV_PROMPT" != false ]]; then
|
||||
local confirmation dirpath="${PWD:A}"
|
||||
if [[ ! -f "$ZSH_DOTENV_FILE" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# make sure there is an (dis-)allowed file
|
||||
touch "$ZSH_DOTENV_ALLOWED_LIST"
|
||||
touch "$ZSH_DOTENV_DISALLOWED_LIST"
|
||||
if [[ "$ZSH_DOTENV_PROMPT" != false ]]; then
|
||||
local confirmation dirpath="${PWD:A}"
|
||||
|
||||
# early return if disallowed
|
||||
if grep -q "$dirpath" "$ZSH_DOTENV_DISALLOWED_LIST" &>/dev/null; then
|
||||
return;
|
||||
fi
|
||||
# make sure there is an (dis-)allowed file
|
||||
touch "$ZSH_DOTENV_ALLOWED_LIST"
|
||||
touch "$ZSH_DOTENV_DISALLOWED_LIST"
|
||||
|
||||
# check if current directory's .env file is allowed or ask for confirmation
|
||||
if ! grep -q "$dirpath" "$ZSH_DOTENV_ALLOWED_LIST" &>/dev/null; then
|
||||
# print same-line prompt and output newline character if necessary
|
||||
echo -n "dotenv: found '$ZSH_DOTENV_FILE' file. Source it? ([Y]es/[n]o/[a]lways/n[e]ver) "
|
||||
read -k 1 confirmation; [[ "$confirmation" != $'\n' ]] && echo
|
||||
|
||||
# check input
|
||||
case "$confirmation" in
|
||||
[nN]) return ;;
|
||||
[aA]) echo "$dirpath" >> "$ZSH_DOTENV_ALLOWED_LIST" ;;
|
||||
[eE]) echo "$dirpath" >> "$ZSH_DOTENV_DISALLOWED_LIST"; return ;;
|
||||
*) ;; # interpret anything else as a yes
|
||||
esac
|
||||
fi
|
||||
# early return if disallowed
|
||||
if command grep -q "$dirpath" "$ZSH_DOTENV_DISALLOWED_LIST" &>/dev/null; then
|
||||
return
|
||||
fi
|
||||
|
||||
# test .env syntax
|
||||
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
|
||||
# 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
|
||||
# get cursor column and print new line before prompt if not at line beginning
|
||||
local column
|
||||
echo -ne "\e[6n" > /dev/tty
|
||||
read -t 1 -s -d R column < /dev/tty
|
||||
column="${column##*\[*;}"
|
||||
[[ $column -eq 1 ]] || echo
|
||||
|
||||
setopt localoptions allexport
|
||||
source $ZSH_DOTENV_FILE
|
||||
# print same-line prompt and output newline character if necessary
|
||||
echo -n "dotenv: found '$ZSH_DOTENV_FILE' file. Source it? ([Y]es/[n]o/[a]lways/n[e]ver) "
|
||||
read -k 1 confirmation
|
||||
[[ "$confirmation" = $'\n' ]] || echo
|
||||
|
||||
# check input
|
||||
case "$confirmation" in
|
||||
[nN]) return ;;
|
||||
[aA]) echo "$dirpath" >> "$ZSH_DOTENV_ALLOWED_LIST" ;;
|
||||
[eE]) echo "$dirpath" >> "$ZSH_DOTENV_DISALLOWED_LIST"; return ;;
|
||||
*) ;; # interpret anything else as a yes
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
# test .env syntax
|
||||
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
|
||||
|
||||
setopt localoptions allexport
|
||||
source $ZSH_DOTENV_FILE
|
||||
}
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
|
|
|
|||
2
plugins/fnm/.gitignore
vendored
Normal file
2
plugins/fnm/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
_fnm
|
||||
|
||||
9
plugins/fnm/README.md
Normal file
9
plugins/fnm/README.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# fnm plugin
|
||||
|
||||
This plugin adds autocompletion for [fnm](https://github.com/Schniz/fnm) - a Node.js version manager.
|
||||
|
||||
To use it, add `fnm` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... fnm)
|
||||
```
|
||||
12
plugins/fnm/fnm.plugin.zsh
Normal file
12
plugins/fnm/fnm.plugin.zsh
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# COMPLETION FUNCTION
|
||||
if (( $+commands[fnm] )); then
|
||||
if [[ ! -f $ZSH_CACHE_DIR/fnm_version ]] \
|
||||
|| [[ "$(fnm --version)" != "$(< "$ZSH_CACHE_DIR/fnm_version")" ]] \
|
||||
|| [[ ! -f $ZSH/plugins/fnm/_fnm ]]; then
|
||||
fnm completions --shell=zsh > $ZSH/plugins/fnm/_fnm
|
||||
fnm --version > $ZSH_CACHE_DIR/fnm_version
|
||||
fi
|
||||
autoload -Uz _fnm
|
||||
_comps[fnm]=_fnm
|
||||
fi
|
||||
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
This plugin supports working with GitHub from the command line. It provides a few things:
|
||||
|
||||
* Sets up the `hub` wrapper and completions for the `git` command if you have `hub` installed.
|
||||
* Completion for the `github` Ruby gem.
|
||||
* Sets up the `hub` wrapper and completions for the `git` command if you have [`hub`](https://github.com/github/hub) installed.
|
||||
* Completion for the [`github` Ruby gem](https://github.com/defunkt/github-gem).
|
||||
* Convenience functions for working with repos and URLs.
|
||||
|
||||
### Functions
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ __gnu_utils() {
|
|||
gcmds+=('gfind' 'gxargs' 'glocate')
|
||||
|
||||
# Not part of either coreutils or findutils, installed separately.
|
||||
gcmds+=('gsed' 'gtar' 'gtime' 'gmake')
|
||||
gcmds+=('gsed' 'gtar' 'gtime' 'gmake' 'ggrep')
|
||||
|
||||
for gcmd in "${gcmds[@]}"; do
|
||||
# Do nothing if the command isn't found
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue