Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wifi-password.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if [ "" != "$args" ]; then
ssid="$@"
else
# get current ssid
ssid="`$airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'`"
ssid="`$airport -I | sed -n 's/^[[:space:]]*[[:space:]]SSID:[[:space:]]//p'`"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? What's going on here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternate:

... | sed -En 's/^ +SSID: (.*)$/\1/p'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't handle tabs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs where? the airport doesn't print tabs AFAIK

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You never know. Developers do switch between spaces and tabs for alignment all the time. How will you know they won't switch down the road?

if [ "$ssid" = "" ]; then
echo "ERROR: Could not retrieve current SSID. Are you connected?" >&2
exit 1
Expand Down