Skip to content
Open
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
39 changes: 39 additions & 0 deletions examples/sample-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Sample shell script for testing $fy tool
# This demonstrates various shell features

set -e

# Variables
PROJECT_DIR="/tmp/test-project"
LOG_FILE="build.log"

# Create project directory
mkdir -p "$PROJECT_DIR"
cd "$PROJECT_DIR"

# Initialize project
echo "Initializing project..."
touch package.json
echo '{"name": "test-project", "version": "1.0.0"}' > package.json

# Build process
echo "Starting build process" | tee "$LOG_FILE"
ls -la >> "$LOG_FILE"

# Conditional execution
if [ -f "package.json" ]; then
echo "Package.json found"
else
echo "Package.json missing" && exit 1
fi

# Pipeline operations
cat package.json | grep "name" | cut -d '"' -f 4

# Cleanup
cd ..
rm -rf "$PROJECT_DIR"

echo "Build complete!"
32 changes: 32 additions & 0 deletions examples/test-fy-debug.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bun

/**
* Debug the $fy tool to see what it receives
*/

import { register, $ } from '../src/$.mjs';

// Register a debug version
register('$fy-debug', async ({ args, stdin, options }) => {
console.log('DEBUG - args:', args);
console.log('DEBUG - stdin:', stdin);
console.log('DEBUG - stdin type:', typeof stdin);
console.log('DEBUG - stdin length:', stdin ? stdin.length : 'null/undefined');
console.log('DEBUG - options:', options);

return {
stdout: 'Debug info printed to stderr\n',
code: 0
};
});

console.log('=== Testing $fy Debug ===\n');

// Test with file
console.log('Testing with file:');
const result = await $`$fy-debug examples/sample-script.sh`;
console.log('Result:', result.stdout);

console.log('\nTesting with stdin:');
const result2 = await $({ stdin: 'ls -la' })`$fy-debug`;
console.log('Result2:', result2.stdout);
50 changes: 50 additions & 0 deletions examples/test-fy-tool.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bun

/**
* Test script for the $fy tool
*/

import { $ } from '../src/$.mjs';

console.log('=== Testing $fy Tool ===\n');

// Test 1: Help message
console.log('1. Testing help message:');
try {
const help = await $`$fy`;
console.log(help.stderr);
} catch (error) {
console.log('Help result:', error.code);
}

console.log('\n2. Testing simple command conversion from stdin:');
// Test 2: Simple command from stdin
try {
const result = await $({ stdin: 'ls -la' })`$fy`;
console.log('Converted command:');
console.log(result.stdout);
} catch (error) {
console.log('Error:', error.message);
}

console.log('\n3. Testing pipeline command from stdin:');
// Test 3: Pipeline command from stdin
try {
const result = await $({ stdin: 'ls -la | grep test' })`$fy`;
console.log('Converted pipeline:');
console.log(result.stdout);
} catch (error) {
console.log('Error:', error.message);
}

console.log('\n4. Testing shell operators from stdin:');
// Test 4: Shell operators
try {
const result = await $({ stdin: 'cd /tmp && pwd && ls' })`$fy`;
console.log('Converted sequence:');
console.log(result.stdout);
} catch (error) {
console.log('Error:', error.message);
}

console.log('=== $fy Tool Test Complete ===');
2 changes: 2 additions & 0 deletions src/$.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4521,6 +4521,7 @@ import dirnameCommand from './commands/$.dirname.mjs';
import yesCommand from './commands/$.yes.mjs';
import seqCommand from './commands/$.seq.mjs';
import testCommand from './commands/$.test.mjs';
import { $fy } from './commands/$.$fy.mjs';

// Built-in commands that match Bun.$ functionality
function registerBuiltins() {
Expand All @@ -4547,6 +4548,7 @@ function registerBuiltins() {
register('yes', yesCommand);
register('seq', seqCommand);
register('test', testCommand);
register('$fy', $fy);
}


Expand Down
Loading
Loading