Skip to content

Commit

Permalink
xplat
Browse files Browse the repository at this point in the history
  • Loading branch information
ajryan committed Jun 7, 2018
1 parent d1b7cd9 commit 3f0e6a8
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 17 deletions.
6 changes: 5 additions & 1 deletion Clipboard.cs
Expand Up @@ -5,17 +5,21 @@ namespace WinHaste
// https://stackoverflow.com/questions/44205260/net-core-copy-to-clipboard
public static class Clipboard
{
public static void Copy(string text)
public static bool Copy(string text)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
$"echo {text} | clip".Bat();
return true;
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
$"echo \"{text}\" | pbcopy".Bash();
return true;
}

return false;
}
}
}
26 changes: 13 additions & 13 deletions Parameters.cs
Expand Up @@ -37,23 +37,13 @@ public Parameters(string[] args)

public ParseResult Parse()
{
if (_args.Length == 0)
{
return ParseResult.Success;
}

if (_args.Length > 2)
return ParseResult.BadArgs;

bool pathProvided = false;

if (_args.Length > 1)
if (_args.Length == 0)
{
Url = ParseUrl(_args[0]);
FilePath = _args[1];
pathProvided = true;
Url = DEFAULT_URL;
}
else
else if (_args.Length == 1)
{
Url = ParseUrl(_args[0]);

Expand All @@ -64,6 +54,16 @@ public ParseResult Parse()
pathProvided = true;
}
}
else if (_args.Length == 2)
{
Url = ParseUrl(_args[0]);
FilePath = _args[1];
pathProvided = true;
}
else
{
return ParseResult.BadArgs;
}

return Url == null ? ParseResult.BadUrl
: !File.Exists(FilePath) && pathProvided
Expand Down
6 changes: 4 additions & 2 deletions Program.cs
Expand Up @@ -41,8 +41,10 @@ static async Task Main(string[] args)
}

string hasteUrl = String.Concat(parameters.Url, "/", match.Groups["key"]);
Clipboard.Copy(hasteUrl);
Console.WriteLine($"Haste URL: {hasteUrl} (copied to clipboard){Environment.NewLine}", hasteUrl);

string copyMessage = Clipboard.Copy(hasteUrl) ? " (copied to clipboard)" : string.Empty;

Console.WriteLine($"Haste URL: {hasteUrl}{copyMessage}{Environment.NewLine}", hasteUrl);
}
}

Expand Down
16 changes: 16 additions & 0 deletions Properties/PublishProfiles/linux.pubxml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp2.1\linux\publish\</PublishDir>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions Properties/PublishProfiles/osx.pubxml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp2.1\osx\publish\</PublishDir>
<RuntimeIdentifier>osx.10.12-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions Properties/PublishProfiles/win.pubxml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp2.1\win\publish\</PublishDir>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion WinHaste.csproj
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>latest</LangVersion>
<RuntimeIdentifiers>win7-x64;osx.10.12-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions publish-all.cmd
@@ -0,0 +1,3 @@
dotnet publish -c Release -r linux-x64 --self-contained
dotnet publish -c Release -r win7-x64 --self-contained
dotnet publish -c Release -r osx.10.12-x64 --self-contained

0 comments on commit 3f0e6a8

Please sign in to comment.