Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.

Commit fc89da2

Browse files
committed
prompt: remove blank lines and code comments before printing
1 parent ce94102 commit fc89da2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Changed
1414
* Convert conditionals to bash-native to simplify maintenance and readability
1515
* Add internal logic to allow more complex prefix/suffix whitespace logic
16+
* Remove blank lines and code comments when printing bash/zsh script
1617

1718
### Added
1819
* Allow users to disable prompt modification with `MAWS_PROMPT_DISABLE=1`.

mozilla_aws_cli/role_picker.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import platform
66
import requests
77
import tempfile
8+
import re
89

910
from .cache import read_group_role_map, write_group_role_map
1011

1112

1213
logger = logging.getLogger(__name__)
1314

14-
PROMPT_BASH_CODE = r'''
15+
# we post-process this variable in a specific manner; please take note:
16+
# 1) blank lines are removed
17+
# 2) lines that are only a # comment are removed
18+
prompt_bash_code_original = r'''
1519
function maws_profile {
1620
if [[ -n $MAWS_PROMPT ]]; then
1721
# either a whitespace character or blank, depending on what
@@ -70,6 +74,14 @@
7074
fi
7175
'''
7276

77+
# remove blank lines and code comments from the bash script.
78+
# this permits maintainable code but minimizes what's emitted
79+
# if the user doesn't use source/eval/<() when calling maws.
80+
PROMPT_BASH_CODE=""
81+
for line in prompt_bash_code_original.split("\n"):
82+
# skip blank lines and comments
83+
if not re.match('^ *(#|$)', line):
84+
PROMPT_BASH_CODE += line + "\n"
7385

7486
def output_set_env_vars(var_map, message=None):
7587
if platform.system() == "Windows":

0 commit comments

Comments
 (0)