The Missing Command

While I’m sure you could make the argument that PowerShell has many “missing” commands compared to your standard POSIX compliant shell, I would say I miss which the most.

Thankfully, Takuya Matsuyama or better known as @devaslife on YouTube, wrote a quick function that I have carried with me across multiple $PROFILE’s.

The Code

function which ($command) {
  Get-Command -Name $command -ErrorAction SilentlyContinue |
    Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}

If you’re unfamiliar with the which command, it shows the origin of the command you’re running. If you’re running an alias, it will show you what you have aliased.

which cat
cat: aliased to bat

If you’re running a command it will show you it’s location on the filesystem.

which fssh
/Users/hacdan/.local/bin/fssh

Conclusion

I’m grateful that Takuya saved us all a bunch of time and wrote a quick PowerShell function to fill this missing hole in PowerShell. I always love these little snippets as they smooth over workflows that are otherwise interrupted my small nuances.

Until next time!