From a5322715f6d3cd94670445ff1ff5473c45386819 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Tue, 9 Mar 2021 17:04:11 +0100 Subject: [PATCH] solarize: fix substring error when /bin/sh is not bash The substring expansion ${parameter:offset:length} is a bashism and does not work when /bin/sh points to a shell other than bash, e.g. on Ubuntu. This commit replaces this expansion with a call to awk, inspired by the solution at: https://wiki.ubuntu.com/DashAsBinSh --- bin/solarize | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/bin/solarize b/bin/solarize index fc95081..88bebea 100755 --- a/bin/solarize +++ b/bin/solarize @@ -40,8 +40,8 @@ fi # under the heading "Change the color palette". set_iterm2_colors() { # 1: foreground, 2: background, 3: cursor while read -r key rgb; do - printf "%s1337;SetColors=%s=%s%s" "$_OSC" "$key" "${rgb}" "$_ST" - done < 4;c;spec - # c -> index of the ANSI color to change [0..15] - # spec -> RGB value of color as rgb:RR/GG/BB - printf "%s4;%s;rgb:%s/%s/%s%s" "$_OSC" "$c" "${rgb:0:2}" "${rgb:2:2}" "${rgb:4:2}" "$_ST" - done < 4;c;spec + # c -> index of the ANSI color to change [0..15] + # spec -> RGB value of color as rgb:RR/GG/BB + awk -v osc="$_OSC" -v st="$_ST" -v ORS="" \ + '{print osc "4;" $1 ";rgb:" substr($2,1,2) "/" substr($2,3,2) "/" substr($2,5,2) st}' \ + < foreground (10), background (11), or cursor (12) - # Pt -> RGB value of color as rgb:RR/GG/BB - printf "%s%s;rgb:%s/%s/%s%s" "$_OSC" "$Ps" "${rgb:0:2}" "${rgb:2:2}" "${rgb:4:2}" "$_ST" - done < foreground (10), background (11), or cursor (12) + # Pt -> RGB value of color as rgb:RR/GG/BB + awk -v osc="$_OSC" -v st="$_ST" -v ORS="" \ + '{print osc $1 ";rgb:" substr($2,1,2) "/" substr($2,3,2) "/" substr($2,5,2) st}' \ + <