diff --git a/bash/.bash_functions b/bash/.bash_functions index 975be4a..c0cec68 100644 --- a/bash/.bash_functions +++ b/bash/.bash_functions @@ -100,3 +100,42 @@ backup() { urlencode() { echo -n "$1" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g' } + +# ---- Config ---- +# Preferred networks (higher = more preferred) +declare -A WIFI_PRIORITY=( + ["HomeWiFi"]=100 + ["WorkWiFi"]=90 + ["PhoneHotspot"]=80 +) + +# ---- Helpers ---- +_wifi_scan() { + nmcli -t -f IN-USE,SSID,SIGNAL,SECURITY dev wifi list \ + | sed '/^::/d' | sort -t: -k3 -nr +} + +# ---- List ---- +wifi_list() { + nmcli -f IN-USE,SSID,SIGNAL,SECURITY dev wifi list +} + +# ---- FZF Connect ---- +wifi_show() { + command -v fzf >/dev/null || { echo "fzf not installed"; return 1; } + + local choice ssid + choice=$(_wifi_scan | fzf --delimiter=: --with-nth=2,3,4 --prompt="Select Wi-Fi: ") + + [ -z "$choice" ] && return 1 + ssid=$(echo "$choice" | cut -d: -f2) + + read -s -p "Password (leave empty if open): " password + echo + + if [ -z "$password" ]; then + nmcli dev wifi connect "$ssid" + else + nmcli dev wifi connect "$ssid" password "$password" + fi +} diff --git a/bash/.bash_variables b/bash/.bash_variables new file mode 100644 index 0000000..7aec4f1 --- /dev/null +++ b/bash/.bash_variables @@ -0,0 +1,2 @@ +export EDITOR=vim +export VISUAL=vim