Copy command line output to the clipboard on macOS, Windows, and Linux

You’ve just figured out the exact piece of information you need from a command line call. Now, how do you get it out of your terminal and take it somewhere else, like an email, chat, or document? Fortunately, there are already programs out there to make this easy. You can send the output from any command to one of these applications, and the output will be available in your clipboard. From there, you can paste it anywhere you please. In the case of Windows and macOS, there are programs to do this that come with the OS. On Linux, you can install a tool to have the same functionality. Windows Whether you are in Command Prompt or PowerShell (old-school or Core), you can use the Windows clip application to get output to the clipboard. Should it matter to you, clip will append an extra line break to whatever you feed it. command {some command} | clip For example, to dump your file listing to the clipboard, you would run dir | clip or Get-ChildItem . | clip, with dir working in both cmd and all flavors of PowerShell and the later only working in PowerShell. Windows (non-Core) PowerShell also offers… Continue reading

Determine SHA hash of file on Windows, Linux, and macOS

While it doesn’t guarantee a download hasn’t been compromised, sometimes you feel better knowing the file you downloaded matches the expected SHA hash. Full disclosure here: while I haven’t been paid or provided anything for this blog post, I am only creating this post for me. If it helps you, great! I just keep looking this up every time I need it. Instead of wading through a bunch of Stack Overflow answers to find the exact magic command I need, I’m hoping I’ll start finding my own blog post in my search results. SHA-256 hash commands Here’s what I use most days. There are bound to be other ways to do this, and on more operating systems or command line shells. As well, there may be ways that are better suited for certain tasks like scripting or other automation steps. For the occasional one-off hash needs, though, they get the job done. macOS bash shasum –algorithm 256 ~/Downloads/some-file.zip Windows (cmd.exe) bash CertUtil -hashfile ~/Downloads/some-file.zip SHA256 Windows (PowerShell) Confirmed in v6.1.3 [Core], but it probably works in several earlier versions. powershell Get-FileHash -Path ~/Downloads/some-file.zip -Algorithm SHA256 Linux I’ve only confirmed this on a few flavors of Ubuntu and Debian/Raspbian. bash sha256sum… Continue reading

Workaround: Xamarin.Android long paths on Windows

Quick answer (TL;DR) Create a symbolic link from your deeply-nested folder to a shorter path using one of the following commands in an Administrator prompt. Command Prompt mklink /D {desired-path-location} {actual-path-location} PowerShell [Core] New-Item -ItemType SymbolicLink -Path {desired-path-location} -Value {actual-path-location} After you create the symbolic link, drag the desired solution into Visual Studio rather than navigating through the link in the Open dialog, which will override to the original path. Background If you like to keep all your code in a user directory on Windows, there’s a very good chance you’ve cloned a repo or started a new Xamarin.Android project that ran into issues on the first build. Most likely you have run into a path length issue. Sometimes a project is just so nested, even putting the repo in a low-level folder will still have trouble. If you read the error messages, sometimes they explicitly say there is a path length issue. Sometimes, though, it will be something unusual like this JavaTypeInfo error. I don’t know enough of the Android build process to explain the issue here, but it’s definitely looking for a file at a path location that is 269 characters long. Failed to create JavaTypeInfo for class:… Continue reading

Play Japanese Famicom games with your US Nintendo Switch Online account

If you’re looking for more retro gaming than the NES games that come free with your Nintendo Switch Online subscription, you might be interested in playing some Japanese Famicom games. Turns out you can do this without any additional cost. I’m not suggesting you load an emulator on your Switch, though that seems like an option these days. It’s not totally straightforward, but it’s not too challenging either. And it definitely won’t leave your Switch in a state where you’re afraid to let it update. One warning, though. The ads on your Switch home screen now have the ability to show up in either English or Japanese. Why would you want the Famicom app? You might just want it because you can. (It’s me!) If you were a Nintendo Switch Online subscriber in Japan, the free retro gaming app is what you would get by default with your subscription is the Famicom app. (And you’d be looking for the reverse instructions to play NES games.) It has all the appropriate cover art images, some of which are just awesome. So, maybe the cover art could sell you on it. There were also several games that were slightly different when released… Continue reading

Fallback variables in `dotnet new` templates

Previously, we created our first custom dotnet new template and added our first input parameter for it. Next, let’s get a little more advanced with our parameters to make our life easier. In this post, we’ll create a template symbol that will function like a coalesce operator, taking a preferred input but falling back to a different input if the preferred value is not found. This is the third in a collection of posts about creating custom templates for the dotnet new system. Sample code This is the third in a series of posts about creating custom templates for the dotnet new system. I’ll be working from the results of the prior blog post, but the approach can be used to add this functionality to any dotnet new template. If you want a starter template project to get you going, you can clone the Git repo from that blog post and start from the prior 2-input-parameters template. Why a coalesce/fallback symbol? There are bound to be several great reasons to need a fallback variable, or one that coalesces between multiple potential inputs, but here are a few I’ve run across so far. Provide a generated value with a manual override… Continue reading