Hacky script to set gifs as the background to the new Windows Terminal => iwr http://bit.ly/gifterm | iex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
iwr http://bit.ly/gifterm | iex | |
$env:gifq='cats and dogs'; iwr http://bit.ly/gifterm | iex | |
#> | |
using namespace System.IO | |
param( | |
[string]$Query = ($env:gifq), | |
[string]$QueryRoot = 'https://giphy.com/search' | |
) | |
Clear-Host | |
$script:ErrorActionPreference = 'Ignore' | |
$script:ProgressPreference = 'SilentlyContinue' | |
try { | |
if(!$Query) { $Query = 'cats' } | |
else { $Query = $Query.Replace(' ', '-') } | |
function GetGifs { | |
$result = Invoke-WebRequest "$Queryroot/$query" -UseBasicParsing | |
$gifsLine = $result.Content -split '\n' | Select-String -Pattern 'gifs:' | Select-Object -ExpandProperty Line | |
($gifsLine.Trim().Substring(5).Trim().Trim(',') | ConvertFrom-Json).embed_url | |
} | |
# Check there is a Windows Terminal install | |
$profilesJson = [Path]::Combine($env:LOCALAPPDATA, 'Packages', 'Microsoft.WindowsTerminal_8wekyb3d8bbwe', 'RoamingState', 'profiles.json') | |
if(Test-Path $profilesJson){ | |
$json = Get-Content $profilesJson -Raw | ConvertFrom-Json | |
$gifs = GetGifs | |
$gifsDir = [Directory]::GetParent($profilesJson) | |
$json.profiles | ForEach-Object { | |
$gif = $gifs[(Get-Random -Minimum 0 -Maximum $gifs.Length)] | |
$gifId = $gif.Substring($gif.LastIndexOf('/')+1) | |
$gifPath = Join-Path $gifsDir "$gifId.gif" | |
if(!(Test-Path $gifPath)){ | |
Invoke-WebRequest "https://i.giphy.com/media/$gifId/giphy.gif" -OutFile $gifPath | |
} | |
if($_.psobject.properties['backgroundImage']){ | |
$_.backgroundImage = $gifPath | |
} else { | |
$_ | Add-Member -NotePropertyName 'backgroundImage' -NotePropertyValue $gifPath | |
} | |
# useAcrylic must be set to false enable the background image | |
if($_.psobject.properties['useAcrylic']){ | |
$_.useAcrylic = $false | |
} else { | |
$_ | Add-Member -NotePropertyName 'useAcrylic' -NotePropertyValue $false | |
} | |
} | |
$json | ConvertTo-Json -Depth 100 | Set-Content $profilesJson | |
} | |
} finally { | |
Clear-History | |
Get-Process -PID $pid | Stop-Process | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment