Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created December 6, 2017 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nohwnd/e5773c6b1514c88e6beb3fc80252d20f to your computer and use it in GitHub Desktop.
Save nohwnd/e5773c6b1514c88e6beb3fc80252d20f to your computer and use it in GitHub Desktop.
emojicode in PowerShell
function πŸ™ {
$name,$params = $args.Where({$_ -eq 'πŸ’©'},'Until')
$null,$groups = $args.Where({$_ -eq 'πŸ’©'},'SkipUntil')
$params = @($params |? {$_})
$bodyText = $groups | %{
$enumerator = [System.Globalization.StringInfo]::GetTextElementEnumerator($_)
$letters = while ($enumerator.MoveNext())
{
$enumerator.Current
}
$literal = $false
$body = $letters | % {
if ($_ -eq "πŸ”€")
{
$literal = -not $literal
"'"
} elseif ((-not $literal) -and ( Get-Command $_ -ErrorAction SilentlyContinue))
{
"(&(Get-Command $_))"
}
elseif ((-not $literal) -and ( $_ -in $params)) {
$c = [Guid]::NewGuid().ToString('N')
"(&{if (`$$c=(Get-Command `${$_} -ErrorAction silentlyContinue)) { &`$$c } else { `${$_} }})"
}
else
{
$_
}
}
$body -join ''
}
$func = @"
param($(($params |% {"`${$_}"})-join','))
$bodyText
"@
"function global:$name {$func}" |Invoke-Expression
}
πŸ™ πŸ₯“ πŸ’© πŸ”€πŸ₯“πŸ”€
πŸ™ 1️⃣ πŸ’© 1
πŸ™ 2️⃣ πŸ’© 2
πŸ™ βž• πŸ…° πŸ…± πŸ’© πŸ…°+πŸ…±
'bacon definition'
get-command πŸ₯“ | % definition
'plus definition'
get-command βž• | % definition
βž• πŸ₯“ πŸ₯“
βž• 1️⃣ 2️⃣
βž• 1 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment