mirror of https://github.com/akelge/zsh
Update starship and awsprofile
This commit is contained in:
parent
c50a178bb7
commit
0173294d2a
|
@ -14,13 +14,13 @@ blocks:
|
|||
style: plain
|
||||
foreground: yellow
|
||||
properties:
|
||||
postfix: ""
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
template: '{{if .SSHSession}}|{{ .HostName }}| {{end}}'
|
||||
|
||||
- type: text
|
||||
style: plain
|
||||
foreground: green
|
||||
foreground: lightBlue
|
||||
properties:
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
|
@ -30,16 +30,18 @@ blocks:
|
|||
style: plain
|
||||
foreground: yellow
|
||||
properties:
|
||||
postfix: ""
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
root_icon: "\u26A1"
|
||||
# root_icon: "# "
|
||||
|
||||
- type: path
|
||||
style: plain
|
||||
enable_hyperlink: false
|
||||
foreground: lightBlue
|
||||
properties:
|
||||
prefix: ""
|
||||
# style: agnoster_short
|
||||
# max_depth: 2
|
||||
style: full
|
||||
|
||||
- type: git
|
||||
|
@ -74,7 +76,8 @@ blocks:
|
|||
foreground: yellow
|
||||
properties:
|
||||
postfix: ""
|
||||
prefix: " "
|
||||
# prefix: " "
|
||||
prefix: " "
|
||||
# prefix: " "
|
||||
template: '{{if .Profile}}{{.Profile}}{{end}}'
|
||||
|
||||
|
|
|
@ -29,18 +29,18 @@ add_newline = false
|
|||
|
||||
[aws]
|
||||
# format = '[$symbol($profile )(\($region\) )(\[$duration\])]($style)'
|
||||
format = '[$symbol($profile)(/($region)) ]($style)'
|
||||
format = '[ $symbol($profile)(/($region)) ]($style)'
|
||||
# symbol = '☁️ '
|
||||
symbol = ' '
|
||||
# symbol = ' '
|
||||
style = 'bright-yellow'
|
||||
style = 'inverted bright-yellow'
|
||||
disabled = false
|
||||
expiration_symbol = 'X'
|
||||
|
||||
[aws.region_aliases]
|
||||
eu-west-1 = "ire"
|
||||
eu-central-1 = "fra"
|
||||
us-east-2 = "ohio"
|
||||
eu-west-1 = "ire1"
|
||||
eu-central-1 = "fra1"
|
||||
us-east-2 = "ohio1"
|
||||
|
||||
[azure]
|
||||
format = 'on [$symbol($subscription)]($style) '
|
||||
|
@ -154,7 +154,7 @@ detect_folders = []
|
|||
|
||||
[directory]
|
||||
truncation_length = 5
|
||||
truncate_to_repo = false
|
||||
truncate_to_repo = true
|
||||
repo_root_style = "underline italic bold blue"
|
||||
fish_style_pwd_dir_length = 0
|
||||
use_logical_path = true
|
||||
|
@ -165,7 +165,7 @@ disabled = false
|
|||
# read_only = '🔒'
|
||||
read_only = " \u2718"
|
||||
read_only_style = 'bright-red bold'
|
||||
truncation_symbol = ''
|
||||
truncation_symbol = '.../'
|
||||
home_symbol = '~'
|
||||
|
||||
[directory.substitutions]
|
||||
|
@ -420,8 +420,8 @@ detect_folders = []
|
|||
|
||||
[kubernetes]
|
||||
symbol = '☸ '
|
||||
format = '[$symbol$context/$namespace]($style) '
|
||||
style = 'bright-blue'
|
||||
format = '[ $symbol$context/$namespace]($style) '
|
||||
style = 'inverted bold bright-blue'
|
||||
disabled = false
|
||||
|
||||
[kubernetes.context_aliases]
|
||||
|
@ -746,8 +746,8 @@ detect_files = ['Package.swift']
|
|||
detect_folders = []
|
||||
|
||||
[terraform]
|
||||
format = 'via [$symbol$workspace]($style) '
|
||||
version_format = 'v${raw}'
|
||||
format = '[$symbol$version]($style)'
|
||||
version_format = '${raw}'
|
||||
symbol = '💠 '
|
||||
style = 'bold 105'
|
||||
disabled = false
|
||||
|
@ -819,7 +819,7 @@ detect_folders = []
|
|||
[custom.vpn]
|
||||
description = "vpn status"
|
||||
command = "echo \uF023"
|
||||
when = "ifconfig utun2 > /dev/null 2>&1"
|
||||
when = "ifconfig utun3 > /dev/null 2>&1"
|
||||
# format = "[$symbol($output)]($style)" # Remove extra blank after output
|
||||
style = "green"
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ setopt NO_HIST_BEEP
|
|||
setopt LIST_TYPES
|
||||
setopt LONG_LIST_JOBS
|
||||
|
||||
setopt no_CLOBBER
|
||||
#setopt no_CLOBBER
|
||||
|
||||
setopt no_BEEP
|
||||
setopt no_HUP
|
||||
|
|
|
@ -9,7 +9,8 @@ fi
|
|||
whence thefuck > /dev/null && eval $(thefuck --alias)
|
||||
|
||||
# z
|
||||
[ -f $LIBRARY/plugins/zsh-z/zsh-z.plugin.zsh ] && source $LIBRARY/plugins/zsh-z/zsh-z.plugin.zsh
|
||||
# [ -f $LIBRARY/plugins/zsh-z/zsh-z.plugin.zsh ] && source $LIBRARY/plugins/zsh-z/zsh-z.plugin.zsh
|
||||
whence zoxide > /dev/null && eval eval "$(zoxide init zsh)"
|
||||
|
||||
# kubectl/krew
|
||||
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
#compdef _stern stern
|
||||
|
||||
# zsh completion for stern -*- shell-script -*-
|
||||
|
||||
__stern_debug()
|
||||
{
|
||||
local file="$BASH_COMP_DEBUG_FILE"
|
||||
if [[ -n ${file} ]]; then
|
||||
echo "$*" >> "${file}"
|
||||
fi
|
||||
}
|
||||
|
||||
_stern()
|
||||
{
|
||||
local shellCompDirectiveError=1
|
||||
local shellCompDirectiveNoSpace=2
|
||||
local shellCompDirectiveNoFileComp=4
|
||||
local shellCompDirectiveFilterFileExt=8
|
||||
local shellCompDirectiveFilterDirs=16
|
||||
|
||||
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace
|
||||
local -a completions
|
||||
|
||||
__stern_debug "\n========= starting completion logic =========="
|
||||
__stern_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}"
|
||||
|
||||
# The user could have moved the cursor backwards on the command-line.
|
||||
# We need to trigger completion from the $CURRENT location, so we need
|
||||
# to truncate the command-line ($words) up to the $CURRENT location.
|
||||
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
||||
words=("${=words[1,CURRENT]}")
|
||||
__stern_debug "Truncated words[*]: ${words[*]},"
|
||||
|
||||
lastParam=${words[-1]}
|
||||
lastChar=${lastParam[-1]}
|
||||
__stern_debug "lastParam: ${lastParam}, lastChar: ${lastChar}"
|
||||
|
||||
# For zsh, when completing a flag with an = (e.g., stern -n=<TAB>)
|
||||
# completions must be prefixed with the flag
|
||||
setopt local_options BASH_REMATCH
|
||||
if [[ "${lastParam}" =~ '-.*=' ]]; then
|
||||
# We are dealing with a flag with an =
|
||||
flagPrefix="-P ${BASH_REMATCH}"
|
||||
fi
|
||||
|
||||
# Prepare the command to obtain completions
|
||||
requestComp="${words[1]} __complete ${words[2,-1]}"
|
||||
if [ "${lastChar}" = "" ]; then
|
||||
# If the last parameter is complete (there is a space following it)
|
||||
# We add an extra empty parameter so we can indicate this to the go completion code.
|
||||
__stern_debug "Adding extra empty parameter"
|
||||
requestComp="${requestComp} \"\""
|
||||
fi
|
||||
|
||||
__stern_debug "About to call: eval ${requestComp}"
|
||||
|
||||
# Use eval to handle any environment variables and such
|
||||
out=$(eval ${requestComp} 2>/dev/null)
|
||||
__stern_debug "completion output: ${out}"
|
||||
|
||||
# Extract the directive integer following a : from the last line
|
||||
local lastLine
|
||||
while IFS='\n' read -r line; do
|
||||
lastLine=${line}
|
||||
done < <(printf "%s\n" "${out[@]}")
|
||||
__stern_debug "last line: ${lastLine}"
|
||||
|
||||
if [ "${lastLine[1]}" = : ]; then
|
||||
directive=${lastLine[2,-1]}
|
||||
# Remove the directive including the : and the newline
|
||||
local suffix
|
||||
(( suffix=${#lastLine}+2))
|
||||
out=${out[1,-$suffix]}
|
||||
else
|
||||
# There is no directive specified. Leave $out as is.
|
||||
__stern_debug "No directive found. Setting do default"
|
||||
directive=0
|
||||
fi
|
||||
|
||||
__stern_debug "directive: ${directive}"
|
||||
__stern_debug "completions: ${out}"
|
||||
__stern_debug "flagPrefix: ${flagPrefix}"
|
||||
|
||||
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
||||
__stern_debug "Completion received error. Ignoring completions."
|
||||
return
|
||||
fi
|
||||
|
||||
while IFS='\n' read -r comp; do
|
||||
if [ -n "$comp" ]; then
|
||||
# If requested, completions are returned with a description.
|
||||
# The description is preceded by a TAB character.
|
||||
# For zsh's _describe, we need to use a : instead of a TAB.
|
||||
# We first need to escape any : as part of the completion itself.
|
||||
comp=${comp//:/\\:}
|
||||
|
||||
local tab=$(printf '\t')
|
||||
comp=${comp//$tab/:}
|
||||
|
||||
__stern_debug "Adding completion: ${comp}"
|
||||
completions+=${comp}
|
||||
lastComp=$comp
|
||||
fi
|
||||
done < <(printf "%s\n" "${out[@]}")
|
||||
|
||||
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
||||
__stern_debug "Activating nospace."
|
||||
noSpace="-S ''"
|
||||
fi
|
||||
|
||||
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
||||
# File extension filtering
|
||||
local filteringCmd
|
||||
filteringCmd='_files'
|
||||
for filter in ${completions[@]}; do
|
||||
if [ ${filter[1]} != '*' ]; then
|
||||
# zsh requires a glob pattern to do file filtering
|
||||
filter="\*.$filter"
|
||||
fi
|
||||
filteringCmd+=" -g $filter"
|
||||
done
|
||||
filteringCmd+=" ${flagPrefix}"
|
||||
|
||||
__stern_debug "File filtering command: $filteringCmd"
|
||||
_arguments '*:filename:'"$filteringCmd"
|
||||
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
||||
# File completion for directories only
|
||||
local subDir
|
||||
subdir="${completions[1]}"
|
||||
if [ -n "$subdir" ]; then
|
||||
__stern_debug "Listing directories in $subdir"
|
||||
pushd "${subdir}" >/dev/null 2>&1
|
||||
else
|
||||
__stern_debug "Listing directories in ."
|
||||
fi
|
||||
|
||||
local result
|
||||
_arguments '*:dirname:_files -/'" ${flagPrefix}"
|
||||
result=$?
|
||||
if [ -n "$subdir" ]; then
|
||||
popd >/dev/null 2>&1
|
||||
fi
|
||||
return $result
|
||||
else
|
||||
__stern_debug "Calling _describe"
|
||||
if eval _describe "completions" completions $flagPrefix $noSpace; then
|
||||
__stern_debug "_describe found some completions"
|
||||
|
||||
# Return the success of having called _describe
|
||||
return 0
|
||||
else
|
||||
__stern_debug "_describe did not find completions."
|
||||
__stern_debug "Checking if we should do file completion."
|
||||
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
||||
__stern_debug "deactivating file completion"
|
||||
|
||||
# We must return an error code here to let zsh know that there were no
|
||||
# completions found by _describe; this is what will trigger other
|
||||
# matching algorithms to attempt to find completions.
|
||||
# For example zsh can match letters in the middle of words.
|
||||
return 1
|
||||
else
|
||||
# Perform file completion
|
||||
__stern_debug "Activating file completion"
|
||||
|
||||
# We must return the result of this command, so it must be the
|
||||
# last command, or else we must store its result to return it.
|
||||
_arguments '*:filename:_files'" ${flagPrefix}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# don't run the completion function when being source-ed or eval-ed
|
||||
if [ "$funcstack[1]" = "_stern" ]; then
|
||||
_stern
|
||||
fi
|
||||
compdef _stern stern
|
|
@ -1,4 +1,7 @@
|
|||
profile=$1
|
||||
shift
|
||||
region=${1:-""}
|
||||
|
||||
|
||||
if [ ! -f ~/.aws/config ]; then
|
||||
echo "no aws config file found, bailing out..."
|
||||
|
@ -18,9 +21,12 @@ if [ $profile ]; then # We got a profile pattern, look for a match
|
|||
fi
|
||||
|
||||
if [ $match ]; then # Single match, setting profile
|
||||
print -P "$FX[bold]activating profile $FG[075]$match$FX[reset]"
|
||||
export AWS_CLI_AUTO_PROMPT=on
|
||||
export AWS_DEFAULT_PROFILE=$match
|
||||
export AWS_DEFAULT_REGION=$(aws configure get region)
|
||||
export AWS_PROFILE=$match
|
||||
export AWS_REGION=${region:-$AWS_DEFAULT_REGION}
|
||||
print -P "$FX[bold]activating profile $FG[075]$match$FX[reset] $FX[bold] on region $FG[075]$AWS_REGION$FX[reset]"
|
||||
return
|
||||
else
|
||||
print -P "$FX[bold]$FG[009]no match for $profile$FX[reset]"
|
||||
|
@ -28,7 +34,7 @@ if [ $profile ]; then # We got a profile pattern, look for a match
|
|||
fi
|
||||
|
||||
elif [ $AWS_PROFILE ]; then # no profile passed, clean up current one, logout
|
||||
unset AWS_DEFAULT_PROFILE AWS_PROFILE
|
||||
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_DEFAULT_REGION AWS_REGION
|
||||
print -P "$FX[bold]profile cleared$FX[reset]."
|
||||
return
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue