Skip to content

Commit

Permalink
awx compdef
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Sep 2, 2019
1 parent 836f0f4 commit 1060d35
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions .zshrc
Expand Up @@ -41,24 +41,31 @@ zstyle ':vcs_info:*' formats '%{'${fg[red]}'%}(%s %b) %{'$reset_color'%}'
zstyle ':vcs_info:*' disable-patterns "$HOME/"
zstyle ':vcs_info:*' disable-patterns "/Users/Songmu/temporary/"

function awx() {
awx-profiles() {
local conf=${AWS_CONFIG_FILE:-~/.aws/config}
grep "^\[.*\]" $conf | tr -d "[]" | sed -e "s/^profile //"
}

awx-complete() {
_values "awx-complete" $(awx-profiles)
}

awx() {
local aws_profile="$1"
if [ -z "$aws_profile" ]; then
local conf=${AWS_CONFIG_FILE:-~/.aws/config}
aws_profile=$(grep "^\[.*\]" $conf | tr -d "[]" | sed -e "s/^profile //" | peco)
aws_profile=$(awx-profiles | peco)
fi
if [ -z "${aws_profile}" ]; then return 1; fi
export AWS_DEFAULT_PROFILE=$aws_profile
}
compdef awx-complete awx

setopt prompt_subst
my_precmd () {
LANG=en_US.UTF-8 vcs_info
local aws_profile=${AWS_DEFAULT_PROFILE:-default}

if [ -z "${SSH_CONNECTION}" ]; then
PROMPT="
%{${fg[yellow]}%}%~%{${reset_color}%} ${vcs_info_msg_0_}(aws $aws_profile)
%{${fg[yellow]}%}%~%{${reset_color}%} ${vcs_info_msg_0_}(aws ${AWS_CONFIG_FILE:-default})
[%*]$ "
else
PROMPT="
Expand Down

0 comments on commit 1060d35

Please sign in to comment.