title: How do I trap signals in PowerShell?
body: <p>Is this possible? I've finally decided to start setting up my personal .NET development environment to closer mimic how I'd set up a *NIX dev environment, which means learning Powershell in earnest.</p>
  
  <p>I'm currently writing a function that recurses through the file system, setting the working directory as it goes in order to build things. One little thing that bothers me is that if I Ctrl+C out of the function, it leaves me wherever the script last was. I've tried setting a <code>trap</code> block that changes the dir to the starting point when run, but this seems to only be intended (and fire) on Exception. </p>
  
  <p>If this were in a language that had root in Unix, I'd set up a signal handler for <code>SIGINT</code>, but I can't find anything similar searching in Powershell. Putting on my .NET cap, I'm imagining there's some sort of event that I can attach a handler to, and if I had to guess, it'd be an event of <code>$host</code>, but I can't find any canonical documentation for <code>System.Management.Automation.Internal.Host.InternalHostUserInterface</code>, and nothing anecdotal that I've been able to search for has been helpful.</p>
  
  <p>Perhaps I'm missing something completely obvious?</p>