r/PowerShell • • Mar 15 '16

¯\_(ツ)_/¯

function Get-AsciiShrug {
    $OutputEncoding = [System.Text.Encoding]::unicode
    write-output "¯_($(0x30C4|%{[char]$_}))_/¯" | clip
}
144 Upvotes

48 comments sorted by

View all comments

27

u/sup3rmark Mar 15 '16

I got sick of googling "ascii shrug" and copy/pasting from there all the time so i just put this function into my powershell profile.

0

u/[deleted] Mar 15 '16

[deleted]

2

u/[deleted] Mar 16 '16

The hero we need. This site will be getting a lot of hits from me.

0

u/[deleted] Mar 16 '16

[deleted]

1

u/SpyderTheSir Mar 16 '16

Reddit hug!

1

u/[deleted] Mar 16 '16

Nice! I shared it with a few of my coworkers as well, so we're driving some traffic your way!

5

u/ihaxr Mar 15 '16

... and into mine it goes.

2

u/derekhans Mar 15 '16

It'd be fun to flesh out more of this function. Is there an easy way to interpret the ascii code for these?

3

u/gangstanthony Mar 15 '16 edited Mar 15 '16

if you find the one you want (I'm using this site)

https://www.wikiwand.com/en/List_of_emoticons

you can copy/paste it into the ISE and do this to see the numbers:

[int[]][char[]]'ಠ_ಠ' -join ', '

gives

3232, 95, 3232

so we can do this

-join[char[]](3232,95,3232)

*note: OP is using hex, but it would work just as well with the decimal number

[char]12484

another example

[int[]][char[]]'(╯°□°)╯︵ ┻━┻' -join ', '

gives

40, 9583, 176, 9633, 176, 65289, 9583, 65077, 32, 9531, 9473, 9531

then we can mix and match

-join[char[]](40, 9583, 3232, 9633, 3232, 65289, 9583, 65077, 32, 9531, 9473, 9531)

*improved thanks to /u/da_chicken

13

u/spoonstar Mar 15 '16

I may or may not have used this to do this:

  function Get-Ascii {
    [cmdletbinding()]

    param (
        [switch]$Shrug,
        [switch]$Disapproval,
        [switch]$TableFlip,
        [switch]$TableBack,
        [switch]$TableFlip2,
        [switch]$TableBack2,
        [switch]$TableFlip3,
        [switch]$Denko,
        [switch]$BlowKiss,
        [switch]$Lenny,
        [switch]$Angry,
        [switch]$DontKnow
     )
     $OutputEncoding = [System.Text.Encoding]::unicode

     Switch ($PSBoundParameters.GetEnumerator().
      Where({$_.Value -eq $true}).Key)
     {
       # 'NAME' { [char[]]@() -join '' | clip }
       'Shrug' { [char[]]@(175,92,95,40,12484,41,95,47,175) -join '' | clip}
       'Disapproval' { [char[]]@(3232,95,3232) -join '' | clip }
       'TableFlip' { [char[]]@(40,9583,176,9633,176,65289,9583,65077,32,9531,9473,9531,41) -join '' | clip }
       'TableBack' { [char[]]@(9516,9472,9472,9516,32,175,92,95,40,12484,41) -join '' | clip }
       'TableFlip2' { [char[]]@(9531,9473,9531,32,65077,12541,40,96,1044,180,41,65417,65077,32,9531,9473,9531) -join '' | clip }
       'TableBack2' { [char[]]@(9516,9472,9516,12494,40,32,186,32,95,32,186,12494,41) -join '' | clip }
       'TableFlip3' { [char[]]@(40,12494,3232,30410,3232,41,12494,24417,9531,9473,9531) -join '' | clip }
       'Denko' { [char[]]@(40,180,65381,969,65381,96,41) -join '' | clip }
       'BlowKiss' { [char[]]@(40,42,94,51,94,41,47,126,9734) -join '' | clip}
       'Lenny' { [char[]]@(40,32,865,176,32,860,662,32,865,176,41) -join '' | clip }
       'Angry' { [char[]]@(40,65283,65439,1044,65439,41) -join '' | clip }
       'DontKnow' { [char[]]@(9488,40,39,65374,39,65307,41,9484) -join '' | clip }
     }
  }

10

u/codekaizen Mar 15 '16

Nice, though I'd prefer this encoding of the parameters:

[ValidateSet(
    'Shrug',
    'Disapproval',
    'TableFlip',
    'TableBack',
    'TableFlip2',
    'TableBack2',
    'TableFlip3',
    'Denko',
    'BlowKiss',
    'Lenny',
    'Angry',
    'DontKnow')]
[string]$Name

Then I can lazily cycle through them.

3

u/spoonstar Mar 15 '16

It does the same thing, I just have to prepend a hyphen beforehand. ValidateSet does make it quicker for me to add new ones though, so thanks for reminding me about it!

10

u/MattHodge Mar 16 '16

I have created a new version with all your ideas: https://github.com/MattHodge/MattHodgePowerShell/blob/master/Fun/Get-Ascii.ps1

  • Uses Validate Parameters

  • Outputs to console as well as clipboard

  • Doesn't copy the newline to the clipboard

2

u/gbrayut Mar 16 '16

Nice work!

2

u/mcwidget Mar 16 '16

This is great. I may have stolen it.

1

u/spoonstar Mar 16 '16

No newline! Great!

2

u/da_chicken Mar 15 '16

No need for the loop:

[int[]][char[]]'ಠ_ಠ' -join ', '

[char[]]@(3232,95,3232) -join ''

1

u/gangstanthony Mar 15 '16

thanks, I'll update.

1

u/runninginthedark Mar 18 '16

Yup, here you go.

function Show-AsciiFace{
    param(
        $Name = "Shrug"
    )
    
    $OutputEncoding = [System.Text.Encoding]::unicode
    
    switch ($Name){
        {$_ -like "Shrug*"}{return $([char[]](0xAF,0x5C,0x5F,0x28,0x30C4,0x29,0x5F,0x2F,0xAF)) -join ""}
        {$_ -like "Flip*"}{return $([char[]](0x28,0x256F,0xB0,0x25A1,0xB0,0xFF09,0x256F,0xFE35,0x253B,0x2501,0x2501,0x253B)) -join ""}
        {$_ -like "DoubleFlip*"}{return $([char[]](0x253B,0x2501,0x2501,0x253B,0xFE35,0x20,0x5C,0x28,0xB0,0x25A1,0xB0,0x29,0x2F,0x20,0xFE35,0x20,0x253B,0x2501,0x2501,0x253B)) -join ""}
        {$_ -like "Fix*"}{return $([char[]](0x252C,0x2500,0x2500,0x252C,0x20,0xFF89,0x28,0xB0,0x2014,0xB0,0xFF89,0x29)) -join ""}
        {$_ -like "Sunglasses*"}{return $([char[]](0x28,0x20,0x2022,0x5F,0x2022,0x29,0x20,0x28,0x20,0x2022,0x5F,0x2022,0x29,0x3E,0x2310,0x25A0,0x2D,0x25A0,0x20,0x28,0x2310,0x25A0,0x5F,0x25A0,0x29)) -join ""}
        {$_ -like "Disapprove*"}{return $([char[]](0xCA0,0x5F,0xCA0)) -join ""}
        {$_ -like "Angry*"}{return $([char[]](0x28,0x22DF,0xFE4F,0x22DE,0x29)) -join ""}
        {$_ -like "You*"}{return $([char[]](0x261E,0x28,0xFF9F,0x2200,0xFF9F,0x29,0x261E)) -join ""}
        {$_ -like "Gimmie*"}{return $([char[]](0xF3C,0x20,0x3064,0x20,0x25D5,0x5F,0x25D5,0x20,0xF3D,0x3064)) -join ""}
        {$_ -like "Yay*"}{return $([char[]](0x5C,0x28,0x2C6,0x2DA,0x2C6,0x29,0x2F)) -join ""}
        {$_ -like "ManTears*"}{return $([char[]](0xCA5,0x5F,0xCA5)) -join ""}
        {$_ -like "KeepAnEyeOut*"}{return $([char[]](0x28,0xCA0,0x5F,0x78,0x29,0x20,0xF3C,0x2609)) -join ""}
        {$_ -like "Fight*"}{return $([char[]](0x28,0xE07,0x2022,0x5F,0x2022,0x29,0xE07)) -join ""}
        default{
            write-Host "I don't recognize $Name"
            return $([char[]](0xAF,0x5C,0x5F,0x28,0x30C4,0x29,0x5F,0x2F,0xAF)) -join ""
        }
    }
}

function Get-AsciiFromString{
    param(
        $InputString
    )
    
    return "0x$(($([int[]][char[]]("$InputString")) | % {"{0:X0}" -f $_}) -join ",0x")"
}