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.

Revisions

  1. ninmonkey revised this gist Jul 11, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Standalone Set-SetClipboard sugar for your profile.ps1
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,8 @@ function GetClipboardItem {
    $Item = Get-Item -ea ignore $_
    }
    if( -not $item ) {
    ' invalid input: returning nothing' | Write-Host -fg '#3379c4'
    # ' invalid input: returning nothing' | Write-Host -fg '#3379c4'
    throw 'invalid input: returning nothing' # useful for: $foo | gcl.gi | cl
    return
    }
    $global:GI = $Item
  2. ninmonkey revised this gist Jul 11, 2024. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions Standalone Set-SetClipboard sugar for your profile.ps1
    Original file line number Diff line number Diff line change
    @@ -24,9 +24,12 @@ function GetClipboardItem {
    } else {
    $Item = Get-Item -ea ignore $_
    }
    if( -not $item ) { return }
    if( -not $item ) {
    ' invalid input: returning nothing' | Write-Host -fg '#3379c4'
    return
    }
    $global:GI = $Item
    $Item
    $Item | join-string -f 'Copied: "{0}"' | Write-host -fg 'gray60' -bg 'gray2'
    $Item | join-string -f ' => Copied: "{0}"' | Write-host -fg 'gray60' -bg 'gray2'
    }
    }
  3. ninmonkey revised this gist Jul 11, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Standalone Set-SetClipboard sugar for your profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # 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

  4. ninmonkey revised this gist Jul 11, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion Standalone Set-SetClipboard sugar for your profile.ps1
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,11 @@ function GetClipboardItem {
    [Alias('Gcl.Gi')]
    param()
    process {
    $Item = Get-Clipboard | Get-Item -ea ignore $_
    if( $null -eq $_ ) {
    $Item = Get-Clipboard | Get-Item -ea ignore
    } else {
    $Item = Get-Item -ea ignore $_
    }
    if( -not $item ) { return }
    $global:GI = $Item
    $Item
  5. ninmonkey revised this gist Jul 11, 2024. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions Standalone Set-SetClipboard sugar for your profile.ps1
    Original file line number Diff line number Diff line change
    @@ -11,18 +11,18 @@ Set-Alias 'gcl' 'Get-Clipboard'
    function GetClipboardItem {
    <#
    .description
    This sets your clipboard returns a non-null value,
    if and only if the path exists
    invalid paths skip set-clipbaord
    # optionally you can set a global, and set-
    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
    #>
    param()

    [Alias('Gcl.Gi')]
    param()
    process {
    $Item = Get-Item -ea ignore $_
    $Item = Get-Clipboard | Get-Item -ea ignore $_
    if( -not $item ) { return }
    $global:GI = $Item
    $Item | Set-Clipboard -passthru:$false
    $Item
    $Item | join-string -f 'Copied: "{0}"' | Write-host -fg 'gray60' -bg 'gray2'
    }
    }
  6. ninmonkey created this gist Jul 11, 2024.
    28 changes: 28 additions & 0 deletions Standalone Set-SetClipboard sugar for your profile.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # 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>

    # 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 sets your clipboard returns a non-null value,
    if and only if the path exists
    invalid paths skip set-clipbaord
    # optionally you can set a global, and set-
    #>
    param()

    process {
    $Item = Get-Item -ea ignore $_
    if( -not $item ) { return }
    $global:GI = $Item
    $Item | Set-Clipboard -passthru:$false
    $Item
    }
    }