Archives - Tag: Command Line
Cleaning up unused images in your Markdown content with PowerShell
I was recently tasked with cleaning up some Markdown content with a bunch of screenshots. Sometimes as content was revised, an image would no longer be used, but the image wasn’t deleted. As a result, the images folder would often be packed with files that were no longer used in the final Markdown content.
On a few blocks of content, I would do this manually in VS Code. From the file list (Ctrl+Shift+E), I’d select the file, copy the file name (F2, then Ctrl+C), search all the files for that file name (Ctrl+Shift+F, then Ctrl+V). This was painful to do for more than a few blocks, so I decided to turn to automation, Powershell in this case.
PowerShell is available on Windows and Linux/macOS, so it’s great for wherever I need it. It even seems to properly translate my path separators on different platforms.
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.
Copy command line output to the clipboard on macOS, Windows, and Linux
NOTE: Updated for PowerShell 7, with
Set-Clipboard
available to supported platforms (Linux still requires xclip).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.
Develop and test loaded PowerShell modules
I have a slowly evolving PowerShell script, more of a set of copy-paste commands at this point, that is evolving into a full-fledged module. I’m working on this module from my usual code location, but I still wish to be able to test it as if it were a registered module.
There are probably a few ways to do this, but here is how I’m making it work, as well as a bonus method that might be a solution for more serious PowerShell module developers. For the primary approach, we’ll make Windows think the PowerShell script file is actually in a proper module location.