#!/bin/bash curr_network=$(nmcli device wifi | rg "^\*" | awk '{print $3}') if [ -z "$curr_network" ]; then echo "Looks like we're not connected to any network" exit 1 fi path_to_net_conns="/etc/NetworkManager/system-connections" fullpath="${path_to_net_conns}/${curr_network}.nmconnection" if [ ! -f "$fullpath" ]; then echo "Could not find this wifi's Network Manager entry" exit 1 fi password=$(sudo cat $fullpath | rg "^psk" | cut -d "=" -f 2) echo Name: \ \ \ $curr_network echo Password: $password