nu_plugin_ws
A plugin for Nushell, a cross-platform shell and scripting language. This plugin adds support for streaming from a websocket.
Installation
Cargo
Get the latest version from crates.io with a local install:
# Downloads and installs the plugin
# Registers the plugin with Nushell
# Activates the plugin
Manual build
Manual builds can also be used:
# Clone the repository
# Enter the repo folder
# Build a release version of the plugin
# Registers the plugin with Nushell
# Activates the plugin
Usage
Basic Connection
Connect to a WebSocket and stream data:
# Connect and listen only
# With timeout
Sending Messages
Send text messages by piping string data:
# Send a text message
|
# Send JSON data
|
# Send with custom headers
|
Send binary data:
# Send binary data (hex format)
|
# Send file contents as binary
|
Advanced Usage
# Multiple custom headers
# With timeout and verbose logging
|
# Handle special characters and Unicode
|
Interactive WebSocket Sessions
For interactive WebSocket communication, you can use Nushell's built-in commands to create interactive workflows:
Method 1: Using a loop with input
Create an interactive session using Nushell's loop and input commands:
# Simple interactive loop
Method 2: Using a custom function
Define a reusable function for interactive sessions:
# Add to your Nushell config
# Use it
Method 3: Reading from a file
For automated testing or scripted interactions:
# Create a messages file
|
# Send each line as a separate message
| |
Method 4: Using a watch file
Create a file-based interactive session:
# In one terminal, watch a file and send its contents
# In another terminal, write messages to the file
|
Method 5: Bi-directional communication with multiple connections
For scenarios requiring separate send and receive channels:
# Terminal 1: Listen for messages
|
# Terminal 2: Send messages
Development
This project uses pre-commit hooks to ensure code quality. See CONTRIBUTING.md for setup instructions.
Quick setup:
# Install pre-commit
# Install the git hooks