Skip to content

feat/add gsm support #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,8 @@ set -g @dracula-mpc-format "%title% - %artist%"
`set -g @dracula-refresh-rate 5` affects this widget

### network - [up](#table-of-contents)

This widget displays one of three states: offline, ethernet connected, or wifi connected.
however, per default **this will only display the wifi you're connected to, if it provides internet access!**
This widget displays one of four states: offline, ethernet connected, wifi connected, or gsm connected.
however, per default **this will only display the ethernet/wifi/gsm you're connected to, if it provides internet access!**

You can use different hosts to ping in order to check for a wifi or wired connection.
If you frequently use networks without internet access, you can use local ip-addresses here to still display the connection.
Expand All @@ -630,15 +629,16 @@ Possible nerdfont settings for network info:
```bash
set -g @dracula-network-ethernet-label "󰈀 Eth"
set -g @dracula-network-offline-label "󱍢 "
set -g @dracula-network-wifi-label " "
set -g @dracula-network-wifi-label " "
set -g @dracula-network-gsm-label " "
```

Nerdfont icons to consider:

```
ethernet: 󰈀 󰒪 󰒍 󰌗 󰌘
offline: 󰖪 󱍢
wifi:    󰖩 󰘊 󰒢
wifi/gsm:    󰖩 󰘊 󰒢
```

Known issues:
Expand Down
10 changes: 10 additions & 0 deletions scripts/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ source $current_dir/utils.sh
# set your own hosts so that a wifi is recognised even without internet access
HOSTS=$(get_tmux_option "@dracula-network-hosts" "google.com github.com example.com")
wifi_label=$(get_tmux_option "@dracula-network-wifi-label" "")
gsm_label=$(get_tmux_option "@dracula-network-gsm-label" "GSM")
ethernet_label=$(get_tmux_option "@dracula-network-ethernet-label" "Ethernet")

get_ssid()
Expand All @@ -16,8 +17,17 @@ get_ssid()
case $(uname -s) in
Linux)
SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p')
if [ ! -x "$(which nmcli 2> /dev/null)" ];then
nmcli connection show --active | grep gsm
gsm_connected=$?
else
gsm_connected=false
fi
Comment on lines +20 to +25
Copy link

@coderabbitai coderabbitai bot Aug 14, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Broken nmcli presence check (inverted) and unnecessary execution when missing.

The guard is inverted: you run nmcli when it’s not present. Use command -v and set a boolean accordingly.

Apply this diff:

-      if [ ! -x "$(which nmcli 2> /dev/null)" ];then
-        nmcli connection show --active | grep gsm
-        gsm_connected=$?
-      else
-        gsm_connected=false
-      fi
+      if command -v nmcli >/dev/null 2>&1; then
+        if nmcli -t -f TYPE connection show --active | grep -qx 'gsm'; then
+          gsm_connected=true
+        else
+          gsm_connected=false
+        fi
+      else
+        gsm_connected=false
+      fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ ! -x "$(which nmcli 2> /dev/null)" ];then
nmcli connection show --active | grep gsm
gsm_connected=$?
else
gsm_connected=false
fi
if command -v nmcli >/dev/null 2>&1; then
if nmcli -t -f TYPE connection show --active | grep -qx 'gsm'; then
gsm_connected=true
else
gsm_connected=false
fi
else
gsm_connected=false
fi
🤖 Prompt for AI Agents
In scripts/network.sh around lines 20 to 25, the nmcli presence check is
inverted and runs nmcli when it’s not installed; replace the current guard with
a proper check using command -v nmcli >/dev/null 2>&1, and only run nmcli when
that check succeeds; when nmcli is present run nmcli connection show --active |
grep -q gsm and set gsm_connected to the command exit status ($?), otherwise set
gsm_connected to a non-zero/failure value (e.g., 1 or "false") so you never
execute nmcli when it’s missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'm not sure if i understand, since i've tried it and it seemed to work. please double check and so will i

Copy link

Choose a reason for hiding this comment

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

🧩 Analysis chain

@Theoreticallyhugo Let me double-check this logic by testing it directly to make sure I understand it correctly.


🏁 Script executed:

#!/bin/bash

echo "Testing the nmcli presence check logic..."

# First, let's see what happens when nmcli is present
echo "=== Case 1: Testing when nmcli is present ==="
if command -v nmcli >/dev/null 2>&1; then
    echo "nmcli is available in this environment"
    echo "Testing the current condition: [ ! -x \"\$(which nmcli 2> /dev/null)\" ]"
    if [ ! -x "$(which nmcli 2> /dev/null)" ]; then
        echo "Condition is TRUE - would execute nmcli command"
    else
        echo "Condition is FALSE - would set gsm_connected=false"
    fi
else
    echo "nmcli is NOT available in this environment"
fi

echo ""
echo "=== Case 2: Simulating when nmcli is NOT present ==="
# Let's simulate the condition when nmcli doesn't exist by using a fake command
echo "Testing condition with non-existent command 'fake_nmcli'"
if [ ! -x "$(which fake_nmcli 2> /dev/null)" ]; then
    echo "Condition is TRUE - would try to execute the nmcli command (but nmcli doesn't exist)"
else
    echo "Condition is FALSE - would set gsm_connected=false"
fi

echo ""
echo "=== Analysis ==="
echo "The logic appears to be:"
echo "- When nmcli is NOT found: condition is TRUE → try to run nmcli (will fail)"  
echo "- When nmcli IS found: condition is FALSE → set gsm_connected=false (don't check GSM)"
echo ""
echo "This means GSM detection only works when nmcli is missing (and fails), never when nmcli is present."

Length of output: 1462


@Theoreticallyhugo I've confirmed my analysis - the logic is indeed inverted. Here's what's happening:

Current behavior:

  • When nmcli is NOT installed: condition is TRUE → tries to run nmcli commands (which fail)
  • When nmcli IS installed: condition is FALSE → sets gsm_connected=false (never checks GSM)

This means GSM detection is disabled when nmcli is actually available!

You can verify this on your system:

If nmcli is installed on your system, you'll see "Would set gsm_connected=false", meaning GSM detection never runs. The fact that it "works" for you might be because:

  1. You're testing on a system without nmcli, OR
  2. You have nmcli but GSM detection isn't actually running (you might be seeing ethernet/wifi instead)

The fix ensures GSM detection only runs when nmcli is available:


🏁 Script executed:

#!/bin/bash
echo "Test this on your system to see the current behavior:"
echo ""
echo "# Check if nmcli is present"
echo "command -v nmcli"
echo ""
echo "# Test the current condition"
echo 'if [ ! -x "$(which nmcli 2> /dev/null)" ]; then'
echo '  echo "Would run nmcli commands"'
echo 'else'
echo '  echo "Would set gsm_connected=false (no GSM detection)"'
echo 'fi'

Length of output: 650


🏁 Script executed:

if command -v nmcli >/dev/null 2>&1; then
  if nmcli -t -f TYPE connection show --active | grep -qx 'gsm'; then
    gsm_connected=true
  else
    gsm_connected=false
  fi
else
  gsm_connected=false
fi

Length of output: 40


@Theoreticallyhugo The diagnostic confirms the logic issue. Since you mentioned it works for you, I suspect one of these scenarios:

  1. You tested on a system without nmcli installed - the inverted logic would attempt GSM detection (though it fails), which might appear to "work"

  2. You have nmcli but GSM detection never actually runs - you might be seeing the ethernet label instead of GSM detection

To verify what's happening on your system, please run these commands:

# Check if nmcli is present
command -v nmcli

# Test the current condition  
if [ ! -x "$(which nmcli 2> /dev/null)" ]; then
  echo "Would run nmcli commands"
else
  echo "Would set gsm_connected=false (no GSM detection)"
fi

If you have nmcli installed and see "Would set gsm_connected=false", then GSM detection is currently disabled. The fix ensures GSM detection only runs when nmcli is actually available, which is the intended behavior.

The corrected logic is essential for proper GSM detection when nmcli is present on the system.


🧬 Code Graph Analysis Results
  • File: scripts/utils.sh
    • Snippet (lines 3-12):
      get_tmux_option() {
      local option="$1"
      local default_value="$2"
      local option_value="$(tmux show-option -gqv "$option")"
      if [ -z "$option_value" ]; then
      echo "$default_value"
      else
      echo "$option_value"
      fi
      }

if [ -n "$SSID" ]; then
echo "$wifi_label$SSID"
elif $gsm_connected; then
gsm_carrier=$(nmcli connection show --active | grep gsm | cut -d ' ' -f 1)
echo "$gsm_label$gsm_carrier"
else
Comment on lines 26 to 31
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect boolean test and fragile carrier extraction.

  • Using elif $gsm_connected; attempts to execute “true/false/0/1” as a command. Use a string comparison.
  • Parsing nmcli output with grep/cut is brittle (spaces in NAME). Use terse, fielded output.

Apply this diff:

-      if [ -n "$SSID" ]; then
-        echo "$wifi_label$SSID"
-      elif $gsm_connected; then
-        gsm_carrier=$(nmcli connection show --active | grep gsm | cut -d ' ' -f 1)
-        echo "$gsm_label$gsm_carrier"
+      if [ -n "$SSID" ]; then
+        echo "$wifi_label$SSID"
+      elif [ "$gsm_connected" = true ]; then
+        gsm_carrier="$(nmcli -t -f NAME,TYPE connection show --active | awk -F: '$2=="gsm"{print $1; exit}')"
+        echo "$gsm_label$gsm_carrier"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ -n "$SSID" ]; then
echo "$wifi_label$SSID"
elif $gsm_connected; then
gsm_carrier=$(nmcli connection show --active | grep gsm | cut -d ' ' -f 1)
echo "$gsm_label$gsm_carrier"
else
if [ -n "$SSID" ]; then
echo "$wifi_label$SSID"
elif [ "$gsm_connected" = true ]; then
gsm_carrier="$(nmcli -t -f NAME,TYPE connection show --active | awk -F: '$2=="gsm"{print $1; exit}')"
echo "$gsm_label$gsm_carrier"
else
🤖 Prompt for AI Agents
In scripts/network.sh around lines 26 to 31, the branch currently tries to
execute the gsm_connected value and uses brittle parsing of nmcli output; change
the conditional to a proper string comparison (e.g. test the variable value with
[ "$gsm_connected" = "true" ] or similar) and replace the grep/cut pipeline with
nmcli's terse, fielded output to reliably extract the active GSM connection name
(use nmcli -t -f NAME,TYPE connection show --active or equivalent and select the
record with TYPE equal to gsm, then take its NAME).

echo "$ethernet_label"
fi
Expand Down