Skip to content

Conversation

Theoreticallyhugo
Copy link
Collaborator

network.sh now supports gsm modules via nmcli.

when connected via gsm, the gsm label is displayed in combination with the carrier.
the gsm label can be set to something custom:

set -g @dracula-network-gsm-label ""

tested on:

  • linux (x86) with gsm
  • linux (x86) without gsm
  • MacOS (apple silicon) without gsm

Copy link

coderabbitai bot commented Jul 12, 2025

📝 Walkthrough

Walkthrough

Adds GSM support to the Linux network detection script, introducing a GSM label and carrier detection via nmcli. Documentation updates reflect four network states (offline, ethernet, wifi, gsm), revised default display logic, updated Nerdfont labels/icons, and minor formatting adjustments. No changes to non-Linux paths or public signatures.

Changes

Cohort / File(s) Summary of Changes
Documentation updates
docs/CONFIG.md
Updated network widget states to include GSM; revised default display logic; adjusted wifi label; added GSM label and combined wifi/gsm icons in Nerdfont section; minor formatting cleanup.
Linux network detection (script)
scripts/network.sh
Added gsm_label option and GSM detection via nmcli; when no Wi-Fi SSID is found, detect active GSM connection and output GSM label with carrier; otherwise fallback to ethernet; scope limited to Linux path.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant network.sh
  participant nmcli

  Caller->>network.sh: get_ssid (Linux)
  network.sh->>network.sh: Load labels (wifi/ethernet/gsm)
  alt Check Wi-Fi
    network.sh->>nmcli: Query active Wi-Fi SSID
    nmcli-->>network.sh: SSID or none
    alt SSID found
      network.sh-->>Caller: wifi_label + SSID
    else No SSID
      alt Check GSM
        network.sh->>nmcli: Query active GSM connection
        nmcli-->>network.sh: Carrier or none
        alt GSM active
          network.sh-->>Caller: gsm_label + Carrier
        else No GSM
          network.sh-->>Caller: ethernet_label
        end
      end
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/network-gsm-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Theoreticallyhugo Theoreticallyhugo force-pushed the feat/network-gsm-support branch from ef5a5fc to ad154a4 Compare August 14, 2025 12:53
@Theoreticallyhugo
Copy link
Collaborator Author

@coderabbitai review

Copy link

coderabbitai bot commented Aug 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Theoreticallyhugo
Copy link
Collaborator Author

@coderabbitai review

Copy link

coderabbitai bot commented Aug 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
docs/CONFIG.md (4)

618-618: Capitalize and use “by default”; fix sentence flow.

Improve readability and grammar.

Apply this diff:

-however, per default **this will only display the ethernet/wifi/gsm you're connected to, if it provides internet access!**
+However, by default, **this will only display the ethernet/wifi/gsm you're connected to if it has internet access!**

638-638: Specify a language for the fenced code block (markdownlint MD040).

Use a neutral language hint like “text” for icon lists.

Apply this diff:

-```
+```text

632-634: Ensure label examples line up with runtime defaults (trailing space).

Your examples include a trailing space (good), but the script’s default for gsm_label is "GSM" without a trailing space, which will render like "GSMVodafone". Either:

  • Add a trailing space to the script’s default, or
  • Add a small note here that labels should include a trailing space for proper concatenation.

Would you like me to update scripts/network.sh to default to "GSM "?


641-642: Icon grouping note (optional).

You combined wifi/gsm icons in one list. Consider keeping separate “wifi” and “gsm” subsections to make it obvious which icon is intended for which label, especially for users scanning quickly.

scripts/network.sh (1)

11-11: Add trailing space to gsm_label default to avoid glued output.

Without a trailing space, outputs become “GSMVodafone”. Align with docs (examples include a trailing space).

Apply this diff:

-gsm_label=$(get_tmux_option "@dracula-network-gsm-label" "GSM")
+gsm_label=$(get_tmux_option "@dracula-network-gsm-label" "GSM ")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 91a1e09 and ad154a4.

📒 Files selected for processing (2)
  • docs/CONFIG.md (2 hunks)
  • scripts/network.sh (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
scripts/network.sh (1)
scripts/utils.sh (1)
  • get_tmux_option (3-12)
🪛 LanguageTool
docs/CONFIG.md

[grammar] ~617-~617: There might be a mistake here.
Context: ...ected, wifi connected, or gsm connected. however, per default **this will only di...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
docs/CONFIG.md

638-638: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

Comment on lines +20 to +25
if [ ! -x "$(which nmcli 2> /dev/null)" ];then
nmcli connection show --active | grep gsm
gsm_connected=$?
else
gsm_connected=false
fi
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
      }

Comment on lines 26 to 31
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
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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant