diff --git a/zsh/.local/share/zsh/functions/aws-ec2-instances b/zsh/.local/share/zsh/functions/aws-ec2-instances index 3748cd2..c9bd8a5 100644 --- a/zsh/.local/share/zsh/functions/aws-ec2-instances +++ b/zsh/.local/share/zsh/functions/aws-ec2-instances @@ -1,6 +1,12 @@ aws-ec2-instances() { aws ec2 describe-instances --output json \ - | jq -r '.Reservations[].Instances[] | - [.InstanceId, .State.Name, .PrivateIpAddress, (.PublicIpAddress // "N/A")] | + | jq -r '.Reservations[].Instances[] | + [ + .InstanceId, + .State.Name, + .PrivateIpAddress, + (.PublicIpAddress // "N/A"), + ((.Tags | map("\(.Key)=\(.Value)") | join(", ")) // "N/A") + ] | @tsv' } diff --git a/zsh/.local/share/zsh/functions/aws-get-secret b/zsh/.local/share/zsh/functions/aws-get-secret new file mode 100644 index 0000000..d1c6f14 --- /dev/null +++ b/zsh/.local/share/zsh/functions/aws-get-secret @@ -0,0 +1,25 @@ +aws-get-secret () { + local secret_id="${1}" + + if [[ -z "$secret_id" ]]; then + secret_id=$(aws secretsmanager list-secrets \ + | jq -r '.SecretList | sort_by(.Name) | .[] | [.Name,.LastChangedDate] | @tsv' \ + | awk -F'\t' '{ + full_name = $1; + truncated_name = substr($1,1,30); + split($2, date_parts, "T"); + # Output: full_name (for return), truncated_name (for display), date (for display) + printf "%s\t%-30s\t%s\n", full_name, truncated_name, date_parts[1] + }' \ + | fzf \ + --header="$(printf '%-30s\t%s\n' 'NAME' 'LAST_CHANGED_DATE')" \ + --delimiter='\t' \ + --with-nth=2,3 \ + | awk '{print $1}') \ + + [[ -z "$secret_id" ]] && return 1 + fi + + echo "Retrieving secret: $secret_id" >&2 + aws secretsmanager get-secret-value --secret-id "$secret_id" --query SecretString --output text +} diff --git a/zsh/.local/share/zsh/functions/aws-list-secrets b/zsh/.local/share/zsh/functions/aws-list-secrets new file mode 100644 index 0000000..fd0908e --- /dev/null +++ b/zsh/.local/share/zsh/functions/aws-list-secrets @@ -0,0 +1,3 @@ +aws-list-secrets() { + aws secretsmanager list-secrets | jq -r '.SecretList[] | [.Name,.LastChangedDate,.ARN] | @tsv' +} diff --git a/zsh/.local/share/zsh/functions/aws-ssm-connect b/zsh/.local/share/zsh/functions/aws-ssm-connect index 92cb2d4..8484399 100644 --- a/zsh/.local/share/zsh/functions/aws-ssm-connect +++ b/zsh/.local/share/zsh/functions/aws-ssm-connect @@ -4,8 +4,8 @@ aws-ssm-connect() { --filters "Name=instance-state-name,Values=running" \ --query 'Reservations[].Instances[].[InstanceId,Tags[?Key==`Name`].Value|[0],PrivateIpAddress,InstanceType]' \ --output text \ - | awk '{printf "%-20s %-40s %-15s %s\n", $1, $2, $3, $4}' \ - | fzf --header="Instance ID Name IP Type" \ + | awk '{printf "%-20s %-40s %-15s %s\n", $1, substr($2, 1, 40), $3, $4}' \ + | fzf --header="$(printf '%-20s %-40s %-15s %s' 'Instance ID' 'Name' 'IP' 'Type')" \ | awk '{print $1}') [[ -z "$instance_id" ]] && return 1 diff --git a/zsh/.local/share/zsh/functions/spacelift-login b/zsh/.local/share/zsh/functions/spacelift-login new file mode 100644 index 0000000..fee3207 --- /dev/null +++ b/zsh/.local/share/zsh/functions/spacelift-login @@ -0,0 +1,4 @@ +spacelift-login() { + spacectl profile login && export SPACELIFT_API_TOKEN=$(spacectl profile export-token) + export SPACECTL_SKIP_STACK_PROMPT=true +}