Skip to content

Commit

Permalink
Replace awk with sed for WSL
Browse files Browse the repository at this point in the history
The WSL distribution of Debian uses mawk instead of gawk by default, which
does not support matching into an array as it is currently being done for
extracting the COM port from the device name.

This commit replaces awk by sed, which also simplifies the building of
/dev/ttySx paths.
  • Loading branch information
socram8888 authored and doegox committed Oct 10, 2020
1 parent 7562bc8 commit 8a0bbe2
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions pm3
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ function get_pm3_list_WSL {
# Need to look for this first, the call to Win32_serialport "crashes" then native bt serial port. Don't ask why.
#BT direct SERIAL PORTS (COM)
if $FINDBTRFCOMM; then
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev/null | awk 'match($0,/COM([0-9]+)/,m){print m[1]}'); do

DEV=${DEV/ */}
DEV="/dev/ttyS${DEV#COM}"
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev/null | sed -nr 's#.*\bCOM([0-9]+)\b.*#/dev/ttyS\1#p'); do
# ttyS counterpart takes some more time to appear
if [ -e "$DEV" ]; then
PM3LIST+=("$DEV")
Expand All @@ -176,9 +173,7 @@ function get_pm3_list_WSL {
fi

# Normal SERIAL PORTS (COM)
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_9AC4&PID_4B8F*' | Select DeviceID" 2>/dev/null | awk '/^COM/{print $1}'); do
DEV=${DEV/ */}
DEV="/dev/ttyS${DEV#COM}"
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_9AC4&PID_4B8F*' | Select DeviceID" 2>/dev/null | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p'); do
# ttyS counterpart takes some more time to appear
if [ -e "$DEV" ]; then
PM3LIST+=("$DEV")
Expand All @@ -194,9 +189,7 @@ function get_pm3_list_WSL {

#white BT dongle SERIAL PORTS (COM)
if $FINDBTDONGLE; then
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev/null | awk '/^COM/{print $1}'); do
DEV=${DEV/ */}
DEV="/dev/ttyS${DEV#COM}"
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev/null | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p'); do
# ttyS counterpart takes some more time to appear
if [ -e "$DEV" ]; then
PM3LIST+=("$DEV")
Expand Down

0 comments on commit 8a0bbe2

Please sign in to comment.