> ## Documentation Index
> Fetch the complete documentation index at: https://nikcli.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Terminal Operations

> Complete reference for terminal and shell command execution

# Terminal Operations

NikCLI provides comprehensive terminal operations for executing shell commands, managing processes, and integrating with development tools. All commands include AI-powered assistance and enhanced output formatting.

## Core Terminal Commands

### `/run [command]`

Execute shell commands with enhanced output and AI assistance.

**Syntax:**

```bash theme={null}
/run <command> [args...]
```

**Features:**

* Real-time output streaming
* Exit code handling
* Error analysis and suggestions
* Command history tracking
* Environment variable support

**Examples:**

```bash theme={null}
# Basic command execution
/run ls -la

# Package management
/run npm install lodash

# Git operations
/run git status

# Build commands
/run npm run build

# System commands
/run ps aux | grep node

# Complex commands with pipes
/run find . -name "*.js" | grep -v node_modules | wc -l
```

**Output Features:**

* Syntax highlighting for command output
* Error highlighting and suggestions
* Performance timing
* Resource usage monitoring
* Exit code interpretation

### `/sh [command]`

Execute shell commands (alias for `/run`).

**Syntax:**

```bash theme={null}
/sh <command> [args...]
```

**Examples:**

```bash theme={null}
# Same functionality as /run
/sh echo "Hello World"
/sh curl -s https://api.github.com/user
/sh docker ps
```

### `/bash [command]`

Execute commands specifically in bash shell.

**Syntax:**

```bash theme={null}
/bash <command> [args...]
```

**Features:**

* Forces bash shell execution
* Bash-specific features support
* Script execution capabilities

**Examples:**

```bash theme={null}
# Bash-specific commands
/bash source ~/.bashrc

# Complex bash scripting
/bash 'for i in {1..5}; do echo "Count: $i"; done'

# Bash arrays and functions
/bash 'declare -a arr=("a" "b" "c"); echo ${arr[@]}'
```

## Development Tool Integration

### `/npm [args]`

Execute npm commands with enhanced package management features.

**Syntax:**

```bash theme={null}
/npm <npm-command> [args...]
```

**Features:**

* Package suggestion and analysis
* Dependency conflict detection
* Security vulnerability scanning
* Performance monitoring
* Cache management

**Examples:**

```bash theme={null}
# Package installation
/npm install react react-dom

# Development dependencies
/npm install --save-dev typescript @types/react

# Global packages
/npm install -g @nicomatt69/nikcli

# Package information
/npm info lodash

# Security audit
/npm audit

# Update packages
/npm update

# Run scripts
/npm run build
/npm run test
/npm run dev

# Package management
/npm list
/npm outdated
/npm prune
```

**Enhanced Features:**

* Automatic package suggestions
* Dependency tree analysis
* Bundle size impact analysis
* License compatibility checking

### `/yarn [args]`

Execute Yarn commands with workspace support.

**Syntax:**

```bash theme={null}
/yarn <yarn-command> [args...]
```

**Features:**

* Workspace management
* Plug'n'Play support
* Advanced caching
* Parallel execution

**Examples:**

```bash theme={null}
# Package installation
/yarn add react react-dom

# Development dependencies
/yarn add --dev typescript

# Workspace commands
/yarn workspace frontend add lodash
/yarn workspaces foreach run build

# Script execution
/yarn build
/yarn test
/yarn dev

# Package management
/yarn info
/yarn upgrade
/yarn dedupe
```

### `/git [args]`

Execute Git commands with enhanced status and visualization.

**Syntax:**

```bash theme={null}
/git <git-command> [args...]
```

**Features:**

* Enhanced status display
* Branch visualization
* Commit analysis
* Conflict resolution assistance
* Performance optimization

**Examples:**

```bash theme={null}
# Status and information
/git status
/git log --oneline -10
/git branch -a

# Working with changes
/git add .
/git commit -m "feat: add new feature"
/git push origin main

# Branch management
/git checkout -b feature/new-feature
/git merge develop
/git rebase main

# Remote operations
/git fetch origin
/git pull --rebase
/git push --set-upstream origin feature-branch

# Advanced operations
/git stash
/git cherry-pick abc123
/git reset --hard HEAD~1
```

**Enhanced Output:**

* Colorized diff output
* Branch tree visualization
* Commit message analysis
* Merge conflict highlighting

### `/docker [args]`

Execute Docker commands with container management features.

**Syntax:**

```bash theme={null}
/docker <docker-command> [args...]
```

**Features:**

* Container status monitoring
* Image analysis
* Resource usage tracking
* Security scanning
* Multi-platform support

**Examples:**

```bash theme={null}
# Container management
/docker ps
/docker ps -a
/docker logs container-name
/docker exec -it container-name bash

# Image operations
/docker images
/docker build -t my-app .
/docker pull node:18-alpine
/docker rmi unused-image

# Network and volume management
/docker network ls
/docker volume ls
/docker-compose up -d
/docker-compose down

# System operations
/docker system df
/docker system prune
/docker stats
```

**Enhanced Features:**

* Container health monitoring
* Resource usage visualization
* Security vulnerability scanning
* Multi-architecture build support

## Process Management

### `/ps`

Show running processes with enhanced information.

**Syntax:**

```bash theme={null}
/ps [options]
```

**Features:**

* Process tree visualization
* Resource usage monitoring
* Port usage detection
* Parent-child relationships

**Examples:**

```bash theme={null}
# Show all processes
/ps

# Show processes with details
/ps -aux

# Show process tree
/ps --tree

# Show specific processes
/ps node
/ps docker
```

**Output Format:**

```
🔄 Running Processes:

┌─────┬──────────────┬─────────┬─────────┬──────────┬─────────────┐
│ PID │ Name         │ CPU %   │ Memory  │ Port     │ Status      │
├─────┼──────────────┼─────────┼─────────┼──────────┼─────────────┤
│ 1234│ node         │ 15.2%   │ 128MB   │ 3000     │ Running     │
│ 5678│ docker       │ 5.1%    │ 64MB    │ -        │ Running     │
│ 9012│ nginx        │ 2.3%    │ 32MB    │ 80,443   │ Running     │
└─────┴──────────────┴─────────┴─────────┴──────────┴─────────────┘
```

### `/kill [pid]`

Terminate processes with safety checks.

**Syntax:**

```bash theme={null}
/kill <pid> [signal]
```

**Parameters:**

* `pid` - Process ID to terminate
* `signal` - Signal to send (default: TERM)

**Safety Features:**

* Process ownership verification
* Critical process protection
* Confirmation for system processes
* Graceful shutdown attempts

**Examples:**

```bash theme={null}
# Terminate process gracefully
/kill 1234

# Force terminate
/kill 1234 KILL

# Terminate by name
/kill node

# Terminate with confirmation
/kill 1234 --confirm
```

## Project Operations

### `/install [package]`

Intelligent package installation with dependency analysis.

**Syntax:**

```bash theme={null}
/install <package-name> [options]
```

**Features:**

* Package manager detection
* Dependency analysis
* Security scanning
* License checking
* Alternative suggestions

**Examples:**

```bash theme={null}
# Install with auto-detection
/install lodash

# Install development dependency
/install --dev typescript

# Install specific version
/install react@18.2.0

# Install from GitHub
/install user/repo

# Install globally
/install --global @nicomatt69/nikcli
```

**Smart Features:**

* Detects package manager (npm, yarn, pnpm)
* Suggests related packages
* Checks for security vulnerabilities
* Analyzes bundle size impact

### `/build`

Execute project build with optimization and analysis.

**Syntax:**

```bash theme={null}
/build [options]
```

**Features:**

* Build script detection
* Performance monitoring
* Bundle analysis
* Error reporting
* Optimization suggestions

**Examples:**

```bash theme={null}
# Standard build
/build

# Production build
/build --production

# Build with analysis
/build --analyze

# Build specific target
/build --target web

# Clean build
/build --clean
```

**Build Analysis:**

* Bundle size reporting
* Dependency analysis
* Performance metrics
* Optimization suggestions
* Error categorization

### `/test [args]`

Execute tests with enhanced reporting and analysis.

**Syntax:**

```bash theme={null}
/test [test-pattern] [options]
```

**Features:**

* Test framework detection
* Coverage reporting
* Performance analysis
* Failure analysis
* Continuous monitoring

**Examples:**

```bash theme={null}
# Run all tests
/test

# Run specific test file
/test user.test.js

# Run tests with coverage
/test --coverage

# Run tests in watch mode
/test --watch

# Run tests matching pattern
/test --grep "authentication"

# Run tests with specific reporter
/test --reporter json
```

**Enhanced Reporting:**

* Visual test results
* Coverage visualization
* Performance benchmarks
* Failure analysis and suggestions
* Historical comparison

### `/lint`

Execute linting with intelligent error analysis.

**Syntax:**

```bash theme={null}
/lint [files] [options]
```

**Features:**

* Multi-linter support
* Auto-fix capabilities
* Rule explanation
* Performance impact analysis
* Custom rule suggestions

**Examples:**

```bash theme={null}
# Lint all files
/lint

# Lint specific files
/lint src/**/*.js

# Lint with auto-fix
/lint --fix

# Lint with specific config
/lint --config .eslintrc.custom.js

# Lint and report performance
/lint --perf
```

**Intelligent Features:**

* Rule explanation and documentation
* Auto-fix suggestions
* Performance impact analysis
* Code quality metrics

## Advanced Terminal Features

### Command History

Enhanced command history with search and analysis:

```bash theme={null}
# Show command history
/history

# Search command history
/history search "npm install"

# Execute from history
/history exec 15

# Clear history
/history clear
```

### Environment Management

Manage environment variables and configuration:

```bash theme={null}
# Show environment
/env

# Set environment variable
/env NODE_ENV production

# Load from file
/env --file .env.production

# Show specific variables
/env NODE_ENV PATH
```

### Command Aliases

Create and manage command aliases:

```bash theme={null}
# Create alias
/alias ll "ls -la"

# List aliases
/alias

# Remove alias
/alias --remove ll
```

### Command Completion

Intelligent command completion and suggestions:

```bash theme={null}
# Enable completion
/completion enable

# Get command suggestions
/suggest npm  # Shows: install, run, test, build...

# Get parameter suggestions
/suggest git  # Shows: status, add, commit, push...
```

## Performance Monitoring

### Resource Usage

Monitor system resources during command execution:

```bash theme={null}
# Enable resource monitoring
/monitor enable

# Commands show resource usage
/run npm run build
# Output includes: CPU: 45%, Memory: 512MB, Time: 2.3s
```

### Benchmarking

Benchmark command performance:

```bash theme={null}
# Benchmark command
/benchmark "npm run build"

# Compare commands
/benchmark "npm run build" "yarn build"

# Historical benchmarks
/benchmark --history
```

## Security Features

### Command Validation

Validate commands for security issues:

```bash theme={null}
# Enable security scanning
/security terminal enable

# Commands are scanned for:
# - Dangerous operations
# - Privilege escalation
# - Network access
# - File system access
```

### Sandboxing

Execute commands in sandboxed environments:

```bash theme={null}
# Enable sandbox mode
/sandbox enable

# Commands run with restricted permissions
/run rm -rf /  # Blocked by sandbox

# Temporary sandbox
/sandbox /run dangerous-command
```

## Integration Examples

### CI/CD Pipeline

```bash theme={null}
# Typical CI/CD workflow
/run git pull origin main
/install
/lint
/test --coverage
/build --production
/run docker build -t my-app .
/run docker push registry/my-app
```

### Development Workflow

```bash theme={null}
# Daily development workflow
/git status
/git pull --rebase
/install  # Install any new dependencies
/test --watch &  # Start tests in background
/run npm run dev  # Start development server
```

### Deployment Workflow

```bash theme={null}
# Production deployment
/git checkout main
/git pull origin main
/install --production
/build --production
/test --production
/docker build -t app:latest .
/docker push registry/app:latest
/run kubectl apply -f k8s/
```

## Troubleshooting

### Common Issues

**Command not found:**

```bash theme={null}
# Check PATH
/env PATH

# Find command location
/run which node

# Install missing command
/install --global missing-command
```

**Permission denied:**

```bash theme={null}
# Check permissions
/run ls -la /path/to/file

# Fix permissions
/run chmod +x script.sh

# Use sudo (with caution)
/run sudo command
```

**Process hanging:**

```bash theme={null}
# Find hanging processes
/ps | grep hanging-process

# Terminate hanging process
/kill process-id

# Force terminate
/kill process-id KILL
```

### Debug Commands

```bash theme={null}
# Show terminal debug info
/debug terminal

# Show command execution logs
/debug commands

# Show environment debug info
/debug env

# Test terminal functionality
/diagnostic terminal
```

## Best Practices

### Command Safety

* Always verify commands before execution
* Use `--dry-run` flags when available
* Backup important data before destructive operations
* Use version control for all changes

### Performance

* Use appropriate command options
* Monitor resource usage
* Optimize build and test commands
* Use caching when available

### Security

* Validate command sources
* Use sandboxing for untrusted commands
* Avoid running commands as root
* Regularly audit command history

### Organization

* Use consistent command patterns
* Document complex command sequences
* Create aliases for frequently used commands
* Maintain clean command history
