From 5eab722b45e57f52f9b070d5c55bb59ae37fb816 Mon Sep 17 00:00:00 2001 From: Rob Woolley Date: Wed, 15 Oct 2025 15:40:45 -0500 Subject: [PATCH] Simplify removing leading and trailing separators Previously, we checked if the leading or trailing character was a colon and then used a wildcard to remove it. It is simpler to just remove a leading or trailing colon. This has the added benefit of only using shell built-in functions. Co-authored-by: Scott K Logan --- colcon_core/shell/sh.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/colcon_core/shell/sh.py b/colcon_core/shell/sh.py index cfab571f..95553d83 100644 --- a/colcon_core/shell/sh.py +++ b/colcon_core/shell/sh.py @@ -28,10 +28,8 @@ class ShShell(ShellExtensionPoint): FORMAT_STR_USE_ENV_VAR = '${name}' FORMAT_STR_INVOKE_SCRIPT = 'COLCON_CURRENT_PREFIX="{prefix}" ' \ '_colcon_prefix_sh_source_script "{script_path}"' - FORMAT_STR_REMOVE_LEADING_SEPARATOR = 'if [ "$(echo -n ${name} | ' \ - 'head -c 1)" = ":" ]; then export {name}=${{{name}#?}} ; fi' - FORMAT_STR_REMOVE_TRAILING_SEPARATOR = 'if [ "$(echo -n ${name} | ' \ - 'tail -c 1)" = ":" ]; then export {name}=${{{name}%?}} ; fi' + FORMAT_STR_REMOVE_LEADING_SEPARATOR = 'export {name}=${{{name}#:}}' + FORMAT_STR_REMOVE_TRAILING_SEPARATOR = 'export {name}=${{{name}%:}}' def __init__(self): # noqa: D107 super().__init__()