From ac09ad6b712df483b022280af953d86738dffd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Endre=20Midtg=C3=A5rd=20Meckelborg?= Date: Tue, 29 Oct 2024 11:00:41 +0100 Subject: [PATCH] Fix bug on missing line feed on last line (#283) If you have a shell config without line feed at the end of the file, the appended line would follow the last line. Fix this by adding an empty line before adding actual content. --- pkg/aws/admin-session.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/aws/admin-session.go b/pkg/aws/admin-session.go index e2b00b0..9b89ce9 100644 --- a/pkg/aws/admin-session.go +++ b/pkg/aws/admin-session.go @@ -208,6 +208,7 @@ func startWorkingShell(awsProfile string) error { func startZshWorkingShell(awsProfile string) error { setup := "mkdir -p /tmp/zsh-sso-admin-session;" + "find $HOME -type f -maxdepth 1 -name \".zsh*\" | xargs -I {} cp {} /tmp/zsh-sso-admin-session;" + + "echo >> /tmp/zsh-sso-admin-session/.zshrc;" + "echo 'export AWS_PROFILE=" + awsProfile + "' >> /tmp/zsh-sso-admin-session/.zshrc;" + "echo 'export PROMPT=\"%F{red}SSO-Admin-Session%f (${AWS_PROFILE}) %~ $ \"' >> /tmp/zsh-sso-admin-session/.zshrc" cmd := exec.Command(os.Getenv("SHELL"), "-c", setup) @@ -230,6 +231,7 @@ func startZshWorkingShell(awsProfile string) error { func startBashWorkingShell(awsProfile string) error { setup := "mkdir -p /tmp/bash-sso-admin-session;" + "find $HOME -type f -maxdepth 1 -name \".bashrc\" | xargs -I {} cp {} /tmp/bash-sso-admin-session;" + + "echo >> /tmp/bash-sso-admin-session/.bashrc;" + "echo 'export AWS_PROFILE=" + awsProfile + "' >> /tmp/bash-sso-admin-session/.bashrc;" + "echo 'export PS1=\"\\e[31m\\]SSO-Admin-Session\\e[0m\\] (${AWS_PROFILE}) \\w $ \"' >> /tmp/bash-sso-admin-session/.bashrc" cmd := exec.Command(os.Getenv("SHELL"), "-c", setup)