npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

shiny-command-line

v1.0.1

Published

🌟 Pretty command line formatter with intelligent multiline display, operator detection, flag formatting, and syntax highlighting

Downloads

10

Readme

🌟 Shiny Command Line

Pretty command line formatter with multiline display, operator detection, flag formatting, and syntax highlighting.

npm version License: MIT

πŸ“‹ Features

  • Command Parsing: Uses shell-quote for command parsing
  • Pretty Formatting: Formats long commands with proper line breaks
  • Operator Detection: Recognizes &&, ||, ;, | and formats accordingly
  • Line Breaking: Breaks lines at appropriate points
  • Option Grouping: Keeps long options with their values together
  • Flag Formatting: Option to put each flag on a new line for better readability
  • Syntax Highlighting: Colorizes commands, operators, flags, and arguments by default
  • Configurable: Customizable line width, indentation, and formatting options
  • TypeScript: Full TypeScript support with type definitions
  • Minimal Dependencies: Only depends on shell-quote and chalk

πŸ“¦ Installation

npm install shiny-command-line

πŸš€ Quick Start

import { prettifyCommand, shouldPrettifyCommand, getCommandPreview } from 'shiny-command-line';

// Basic usage
const command = 'npm run build && npm run test --coverage --verbose && npm run deploy --env=production';
const prettified = prettifyCommand(command);

console.log(prettified);
// Output:
// npm run build &&
//   npm run test \\
//     --coverage \\
//     --verbose &&
//   npm run deploy \\
//     --env=production

// With advanced formatting
const dockerCmd = 'docker run -d --name myapp -p 3000:3000 -e NODE_ENV=production myapp:latest';
const advanced = prettifyCommand(dockerCmd, { 
  flagsOnNewLine: true
});

console.log(advanced);
// Output (with colors by default):
// docker run \
//   -d \
//   --name myapp \
//   -p 3000:3000 \
//   -e NODE_ENV=production \
//   myapp:latest

πŸ“š API Reference

prettifyCommand(command, options?)

Formats a command string with multiline display.

Parameters:

  • command (string): The command to prettify
  • options (object, optional):
    • maxWidth (number): Maximum line width (default: 80)
    • indent (string): Indentation string (default: ' ')
    • flagsOnNewLine (boolean): Put each flag on a new line (default: false)
    • disableColors (boolean): Disable syntax highlighting (default: false)

Returns: Prettified command string

import { prettifyCommand } from 'shiny-command-line';

// Basic formatting
const result = prettifyCommand(
  'docker build -t myapp . && docker run -p 3000:3000 myapp'
);

// Advanced formatting with flags on new lines
const advanced = prettifyCommand(
  'docker run -d --name myapp -p 3000:3000 -e NODE_ENV=production myapp:latest',
  { 
    maxWidth: 60, 
    indent: '    ',
    flagsOnNewLine: true
  }
);

// To disable colors
const disableColors = prettifyCommand(dockerCmd, { disableColors: true });

shouldPrettifyCommand(command, threshold?)

Determines if a command should be prettified based on complexity.

Parameters:

  • command (string): The command to analyze
  • threshold (number): Length threshold (default: 80)

Returns: Boolean indicating if prettification is recommended

import { shouldPrettifyCommand } from 'shiny-command-line';

console.log(shouldPrettifyCommand('ls -la')); // false
console.log(shouldPrettifyCommand('npm run build && npm run test')); // true
console.log(shouldPrettifyCommand('command --option1 --option2 --option3 --option4')); // true

getCommandPreview(command, options?)

Gets both original and prettified versions of a command.

Parameters:

  • command (string): The command to preview
  • options (object, optional):
    • showPretty (boolean): Include prettified version (default: false)
    • maxWidth (number): Maximum line width (default: 80)
    • indent (string): Indentation string (default: ' ')
    • flagsOnNewLine (boolean): Put each flag on a new line (default: false)
    • disableColors (boolean): Disable syntax highlighting (default: false)

Returns: Object with original, pretty, and shouldPrettify properties

import { getCommandPreview } from 'shiny-command-line';

const preview = getCommandPreview(
  'npm run build && npm run test',
  { showPretty: true, flagsOnNewLine: true }
);

console.log(preview.original);     // Original command
console.log(preview.pretty);       // Prettified version (if shouldPrettify is true)
console.log(preview.shouldPrettify); // true

prettifyCommands(commands, options?)

Formats multiple commands in batch.

Parameters:

  • commands (string[]): Array of commands to prettify
  • options (object, optional): Same as prettifyCommand

Returns: Array of prettified command strings

import { prettifyCommands } from 'shiny-command-line';

const commands = [
  'npm run build && npm run test',
  'docker build -t app . && docker run app'
];

const prettified = prettifyCommands(commands, { 
  flagsOnNewLine: true
});

🎯 Examples

Flag Formatting

const dockerCmd = 'docker run -d --name myapp --restart=unless-stopped -p 3000:3000 -p 4000:4000 -e NODE_ENV=production -e DATABASE_URL=postgres://user:pass@localhost:5432/db -v /host/logs:/app/logs myapp:latest';

// Standard formatting
console.log(prettifyCommand(dockerCmd));
// Output:
// docker run \\
//   -d \\
//   --name myapp \\
//   --restart=unless-stopped \\
//   -p 3000:3000 \\
//   -p 4000:4000 \\
//   -e NODE_ENV=production \\
//   -e DATABASE_URL=postgres://user:pass@localhost:5432/db \\
//   -v /host/logs:/app/logs \\
//   myapp:latest

// With flags on new lines (better for complex commands)
console.log(prettifyCommand(dockerCmd, { flagsOnNewLine: true }));
// Output:
// docker run \\
//   -d \\
//   --name myapp \\
//   --restart=unless-stopped \\
//   -p 3000:3000 \\
//   -p 4000:4000 \\
//   -e NODE_ENV=production \\
//   -e DATABASE_URL=postgres://user:pass@localhost:5432/db \\
//   -v /host/logs:/app/logs \\
//   myapp:latest

Syntax Highlighting

const complexCmd = 'npm run build && docker build -t myapp:latest . && curl -X POST https://api.example.com/deploy --data-binary @package.json';

// With colors (default behavior)
console.log(prettifyCommand(complexCmd));
// Commands appear in cyan, operators in yellow, flags in green, etc.

// Without colors
console.log(prettifyCommand(complexCmd, { disableColors: true }));

Color Scheme:

  • Commands: Cyan bold (npm, docker, curl)
  • Operators: Yellow bold (&&, ||, ;, |)
  • Flags: Green (--flag, -f)
  • File paths: Blue (./src/index.js, /host/path)
  • Key=value pairs: Magenta (NODE_ENV=production)
  • URLs: Blue underlined (https://api.example.com)
  • Arguments: White (regular arguments)

Complex Docker Command

const dockerCmd = 'docker run -d --name myapp -p 3000:3000 -p 4000:4000 -e NODE_ENV=production -e DATABASE_URL=postgres://user:pass@localhost:5432/db -v /host/path:/container/path myapp:latest';

console.log(prettifyCommand(dockerCmd, { flagsOnNewLine: true }));
// Output (with colors by default):
// docker run \
//   -d \
//   --name myapp \
//   -p 3000:3000 \
//   -p 4000:4000 \
//   -e NODE_ENV=production \
//   -e DATABASE_URL=postgres://user:pass@localhost:5432/db \
//   -v /host/path:/container/path \
//   myapp:latest

CI/CD Pipeline

const ciCmd = 'npm ci && npm run lint && npm run test -- --coverage && npm run build && npm run deploy -- --env=production --verbose';

console.log(prettifyCommand(ciCmd));
// Output:
// npm ci &&
//   npm run lint &&
//   npm run test \\
//     -- \\
//     --coverage &&
//   npm run build &&
//   npm run deploy \\
//     -- \\
//     --env=production \\
//     --verbose

Git Operations

const gitCmd = 'git add . && git commit -m "feat: add new feature with tests and documentation" && git push origin feature/new-feature';

console.log(prettifyCommand(gitCmd, { disableColors: true }));
// Output:
// git add . &&
//   git commit \\
//     -m "feat: add new feature with tests and documentation" &&
//   git push \\
//     origin \\
//     feature/new-feature

πŸ”§ Configuration

Custom Formatting Options

import { prettifyCommand } from 'shiny-command-line';

// Custom line width and indentation
const options = {
  maxWidth: 120,
  indent: '    ', // 4 spaces instead of 2
  flagsOnNewLine: true,
  disableColors: true
};

const prettified = prettifyCommand(longCommand, options);

Integration with Your CLI Tool

import { getCommandPreview } from 'shiny-command-line';

function executeCommand(cmd: string, showPreview: boolean = false) {
  if (showPreview) {
    const preview = getCommandPreview(cmd, { 
      showPretty: true,
      flagsOnNewLine: true,
      disableColors: true
    });
    
    if (preview.shouldPrettify && preview.pretty) {
      console.log('Command preview:');
      console.log('─'.repeat(50));
      console.log(preview.pretty);
      console.log('─'.repeat(50));
    }
  }
  
  // Execute the command...
}

Use Cases

Perfect for:

  • Docker commands with many flags and options
  • CLI tools with complex argument structures
  • CI/CD scripts with chained commands
  • Documentation that shows command examples
  • Developer tools that need to display commands clearly
  • Script runners that preview commands before execution

πŸ§ͺ Demo

Run the interactive demo to see all features in action:

git clone https://github.com/steven-pribilinskiy/shiny-command-line.git
cd shiny-command-line
npm install
npm run build
npm run demo

The demo showcases:

  • Basic command analysis
  • Flag formatting comparison
  • Syntax highlighting examples
  • Batch processing capabilities