Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ninmonkey/e9968c829185a310574e61f2365105a4 to your computer and use it in GitHub Desktop.
Save ninmonkey/e9968c829185a310574e61f2365105a4 to your computer and use it in GitHub Desktop.
Tiny Set-Clipboard Sugar
# Here's tiny clipboard sugar for a profile
# context: there was a thread about creating a custom clipboard uri, and clipboard cmdlets
# <https://discord.com/channels/180528040881815552/447476117629304853/1260981998479081562>
Import-Module Pansies
# It's nice to get a confirmation that your clip was saved
$PSDefaultParameterValues['Set-ClipBoard:PassThru'] = $true
Set-alias 'cl' 'Set-ClipBoard' # 'sc' already exists
Set-Alias 'gcl' 'Get-Clipboard'
function GetClipboardItem {
<#
.description
This reads the clipboard, converts to an item
if and only if the path exists
invalid paths do not return a value
invalid paths will not erase previous $global:gi values
#>
[Alias('Gcl.Gi')]
param()
process {
if( $null -eq $_ ) {
$Item = Get-Clipboard | Get-Item -ea ignore
} else {
$Item = Get-Item -ea ignore $_
}
if( -not $item ) {
# ' invalid input: returning nothing' | Write-Host -fg '#3379c4'
throw 'invalid input: returning nothing' # useful for: $foo | gcl.gi | cl
return
}
$global:GI = $Item
$Item
$Item | join-string -f ' => Copied: "{0}"' | Write-host -fg 'gray60' -bg 'gray2'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment