diff --git a/emacs/.emacs.d/config/init-aws.el b/emacs/.emacs.d/config/init-aws.el index a3f5b71..2bbac74 100644 --- a/emacs/.emacs.d/config/init-aws.el +++ b/emacs/.emacs.d/config/init-aws.el @@ -13,12 +13,14 @@ (add-hook 'vterm-mode-hook #'aws-local-profile) (add-hook 'term-mode-hook #'aws-local-profile) -(add-to-list 'aws-profiles "personal") -(add-to-list 'aws-profiles "lola-cde") -(add-to-list 'aws-profiles "lola-gbt") +(defun aws-list-profiles () + (when (not (executable-find "aws")) + (user-error "Unable to find executable \"aws\"!")) + (let ((profile-string (shell-command-to-string "aws configure list-profiles"))) + (s-split "\n" profile-string))) (defun aws-switch-profile (profile) - (interactive (list (completing-read "Profile: " aws-profiles))) + (interactive (list (completing-read "Profile: " (aws-list-profiles)))) (setenv "AWS_PROFILE" profile) (when (eq major-mode 'vterm-mode) (vterm-send-C-e) @@ -26,6 +28,10 @@ (vterm-send-string (format "export AWS_PROFILE=%s\n" profile))) (setq aws-current-profile profile)) +(defun aws-sso-login () + (interactive) + (async-shell-command "AWS_PROFILE=default aws sso login")) + (add-hook 'emacs-startup-hook (lambda () (aws-switch-profile "default")))