Skip to content

Instantly share code, notes, and snippets.

@toenuff toenuff/hgrep.ps1
Last active Dec 24, 2015

What would you like to do?
Hgrep is a function that provides similar functionality to the unix commands history |grep something
function hgrep {
[Parameter(Mandatory=$false, Position=0)]
$commands = get-history |?{$_.commandline -match $regex}
if ($full) {
$commands |ft *
else {
foreach ($command in ($commands |select -ExpandProperty commandline)) {
# This ensures that only the first line is shown of a multiline command
# You can always get the full command using get-history or you can fork and remove this from the gist
if ($command -match '\r\n') {
($command -split '\r\n')[0] + " ..."
else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.