(view source code of clipboardprepend.cs as plain text)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace RobvanderWoude
{
internal class ClipboardPrepend
{
static readonly string progver = "1.00";
[STAThread]
static int Main( string[] args )
{
if ( args.Length > 1 || ( args.Length == 1 && Console.IsInputRedirected ) || args.Contains( "/?" ) )
{
return ShowHelp( );
}
string text;
if ( args.Length == 1 )
{
text = args[0];
}
else if ( Console.IsInputRedirected )
{
text = Console.In.ReadToEnd( );
}
else
{
return ShowHelp( );
}
if ( Clipboard.ContainsText( ) )
{
string cliptext = Clipboard.GetText( );
Clipboard.SetText( text + cliptext );
}
else
{
Clipboard.SetText( text );
}
return 0;
}
public static int ShowHelp( params string[] errmsg )
{
#region Error Message
if ( errmsg.Length > 0 )
{
List<string> errargs = new List<string>( errmsg );
errargs.RemoveAt( 0 );
Console.Error.WriteLine( );
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.Write( "ERROR:\t" );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( errmsg[0], errargs.ToArray( ) );
Console.ResetColor( );
}
#endregion Error Message
#region Help Text
/*
ClipboardPrepend.exe, Version 1.00
Send text to clipboard, prepending it to existing text in clipboard
Usage: CLIPBOARDAPPEND.EXE text
or: somecommand | CLIPBOARDAPPEND.EXE
Where: text text to be prepended to clipboard
somecommand command whose output will be prepended to clipboard
Notes: If the clipboard contains data other than text, it is overwritten.
Return code (\"ErrorLevel\") -1 in case of (command line) errors,
otherwise 0.
Written by Rob van der Woude
https://www.robvanderwoude.com
*/
#endregion Help Text
#region Display Help Text
Console.Error.WriteLine( );
Console.Error.WriteLine( "ClipboardPrepend.exe, Version {0}", progver );
Console.Error.WriteLine( "Send text to clipboard, prepending it to existing text in clipboard" );
Console.Error.WriteLine( );
Console.Error.Write( "Usage: " );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( "CLIPBOARDPREPEND.EXE text" );
Console.ResetColor( );
Console.Error.WriteLine( );
Console.Error.Write( "or: " );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( "somecommand | CLIPBOARDPREPEND.EXE" );
Console.ResetColor( );
Console.Error.WriteLine( );
Console.Error.Write( "Where: " );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.Write( "text" );
Console.ResetColor( );
Console.Error.WriteLine( " text to be prepended to clipboard" );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.Write( " somecommand" );
Console.ResetColor( );
Console.Error.WriteLine( " command whose output will be prepended to clipboard" );
Console.Error.WriteLine( );
Console.Error.WriteLine( "Notes: If the clipboard contains data other than text, it is overwritten." );
Console.Error.WriteLine( " Return code (\"ErrorLevel\") -1 in case of (command line) errors," );
Console.Error.WriteLine( " otherwise 0." );
Console.Error.WriteLine( );
Console.Error.WriteLine( "Written by Rob van der Woude" );
Console.Error.WriteLine( "https://www.robvanderwoude.com" );
#endregion Display Help Text
return -1;
}
}
}
page last modified: 2024-04-16; loaded in 0.0060 seconds