Skip to content

Instantly share code, notes, and snippets.

@giovannicandido
Created October 8, 2024 22:33
Show Gist options
  • Save giovannicandido/aaf05fa6b68457a698eb7ea86fb58a8f to your computer and use it in GitHub Desktop.
Save giovannicandido/aaf05fa6b68457a698eb7ea86fb58a8f to your computer and use it in GitHub Desktop.
Instale o powershell 7 e edite o arquivo de perfil com o commando: code $PROFILE
# Terminal-Icons
# Import-Module -Name Terminal-Icons
# . "C:\Applications\bin\oci-cli\Lib\site-packages\oci_cli\bin\OciTabExpansion.ps1"
# Import-Module posh-git
#
$MaximumHistoryCount = 20000
Function Test-CommandExists
{
Param ($command)
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'stop'
try { if (Get-Command $command) { RETURN $true } }
Catch { Write-Host "$command does not exist"; RETURN $false }
Finally { $ErrorActionPreference = $oldPreference }
} #end function test-CommandExists
Function Get-PubIP {
(Invoke-WebRequest http://ifconfig.me/ip ).Content
}
function find-file($name) {
Get-ChildItem -recurse -filter "*${name}*" -ErrorAction SilentlyContinue | ForEach-Object {
$place_path = $_.directory
Write-Output "${place_path}\${_}"
}
}
function df {
get-volume
}
function pkill($name) {
Get-Process $name -ErrorAction SilentlyContinue | Stop-Process
}
function pgrep($name) {
Get-Process $name
}
function which($name) {
Get-Command $name | Select-Object -ExpandProperty Definition
}
$LazyLoadProfileRunspace = [RunspaceFactory]::CreateRunspace()
$LazyLoadProfile = [PowerShell]::Create()
$LazyLoadProfile.Runspace = $LazyLoadProfileRunspace
$LazyLoadProfileRunspace.Open()
[void]$LazyLoadProfile.AddScript({Import-Module posh-git}) # (1)
[void]$LazyLoadProfile.AddScript({Import-Module DockerCompletion}) # (1)
[void]$LazyLoadProfile.AddScript({Import-Module Terminal-Icons}) # (1)
[void]$LazyLoadProfile.AddScript({Import-Module PSReadLine}) # (1)
[void]$LazyLoadProfile.BeginInvoke()
$null = Register-ObjectEvent -InputObject $LazyLoadProfile -EventName InvocationStateChanged -Action {
Import-Module -Name posh-git # (2)
Import-Module -Name DockerCompletion # (2)
Import-Module -Name Terminal-Icons # (2)
Import-Module -Name PSReadLine # (2)
# Uses tab for autocompletion
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# History definitions
#$HistoryFilePath = Join-Path ([Environment]::GetFolderPath('UserProfile')) .ps_history
#Register-EngineEvent PowerShell.Exiting -Action { Get-History | Export-Clixml $HistoryFilePath } | out-null
#if (Test-path $HistoryFilePath) { Import-Clixml $HistoryFilePath | Add-History }
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -ShowToolTips
Set-PSReadLineOption -PredictionSource History
$global:GitPromptSettings.DefaultPromptPrefix.Text = 'PS '
$global:GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n'
$LazyLoadProfile.Dispose()
$LazyLoadProfileRunspace.Close()
$LazyLoadProfileRunspace.Dispose()
}
#Import-Module DockerCompletion
#Import-Module posh-git
#Import-Module -Name Terminal-Icons
#Import-Module Get-ChildItemColor
#Import-Module PSReadLine
# Aliases
Set-Alias which Get-Command
Set-Alias open Invoke-Item
Set-Alias -Name vim -Value nvim
Set-Alias -Name cd -Value z -Option AllScope
Set-Alias -Name k -Value kubectl
function ll() { Get-ChildItem | Format-Table }
function la() { Get-ChildItem | Format-Wide }
function lb() { Get-ChildItem | Format-List }
#Set-Alias ls lsd
Set-Alias tree Exa-Tree
function Exa-Tree {
exa -hHiS --long --tree
}
function md5 { Get-FileHash -Algorithm MD5 $args }
function sha1 { Get-FileHash -Algorithm SHA1 $args }
function sha256 { Get-FileHash -Algorithm SHA256 $args }
function tail { Get-Content $args -Tail 30 -Wait }
function Get-PubIP {
(Invoke-WebRequest http://ifconfig.me/ip ).Content
}
function uptime {
#Windows Powershell only
If ($PSVersionTable.PSVersion.Major -eq 5 ) {
Get-WmiObject win32_operatingsystem |
Select-Object @{EXPRESSION={ $_.ConverttoDateTime($_.lastbootuptime)}} | Format-Table -HideTableHeaders
} Else {
net statistics workstation | Select-String "since" | foreach-object {$_.ToString().Replace('Statistics since ', '')}
}
}
<# $null = New-Module { # Load as dynamic module
# Define a succinct alias.
}
set-alias cf ConvertTo-TempFile
function ConvertTo-TempFile {
[CmdletBinding(DefaultParameterSetName='Cleanup')]
param(
[Parameter(ParameterSetName='Standard', Mandatory=$true, Position=0)]
[ScriptBlock] $ScriptBlock
, [Parameter(ParameterSetName='Standard', Position=1)]
[string] $LiteralPath
, [Parameter(ParameterSetName='Standard')]
[string] $Extension
, [Parameter(ParameterSetName='Standard')]
[switch] $BOM
)
$prevFilePath = Test-Path variable:__cttfFilePath
if ($PSCmdlet.ParameterSetName -eq 'Cleanup') {
if ($prevFilePath) {
Write-Verbose "Removing temp. file: $__cttfFilePath"
Remove-Item -ErrorAction SilentlyContinue $__cttfFilePath
Remove-Variable -Scope Script __cttfFilePath
} else {
Write-Verbose "Nothing to clean up."
}
} else { # script block specified
if ($Extension -and $Extension -notlike '.*') { $Extension = ".$Extension" }
if ($LiteralPath) {
# Since we'll be using a .NET framework classes directly,
# we must sync .NET's notion of the current dir. with PowerShell's.
[Environment]::CurrentDirectory = $pwd
if ([System.IO.Directory]::Exists($LiteralPath)) {
$script:__cttfFilePath = [IO.Path]::Combine($LiteralPath, [IO.Path]::GetRandomFileName() + $Extension)
Write-Verbose "Creating file with random name in specified folder: '$__cttfFilePath'."
} else { # presumptive path to a *file* specified
if (-not [System.IO.Directory]::Exists((Split-Path $LiteralPath))) {
Throw "Output folder '$(Split-Path $LiteralPath)' must exist."
}
$script:__cttfFilePath = $LiteralPath
Write-Verbose "Using explicitly specified file path: '$__cttfFilePath'."
}
} else { # Create temp. file in the user's temporary folder.
if (-not $prevFilePath) {
if ($Extension) {
$script:__cttfFilePath = [IO.Path]::Combine([IO.Path]::GetTempPath(), [IO.Path]::GetRandomFileName() + $Extension)
} else {
$script:__cttfFilePath = [IO.Path]::GetTempFilename()
}
Write-Verbose "Creating temp. file: $__cttfFilePath"
} else {
Write-Verbose "Reusing temp. file: $__cttfFilePath"
}
}
if (-not $BOM) { # UTF8 file *without* BOM
# Note: Out-File, sadly, doesn't support creating UTF8-encoded files
# *without a BOM*, so we must use the .NET framework.
# [IO.StreamWriter] by default writes UTF-8 files without a BOM.
$sw = New-Object IO.StreamWriter $__cttfFilePath
try {
. $ScriptBlock | Out-String -Stream | % { $sw.WriteLine($_) }
} finally { $sw.Close() }
} else { # UTF8 file *with* BOM
. $ScriptBlock | Out-File -Encoding utf8 $__cttfFilePath
}
return $__cttfFilePath
}
} #>
#oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/atomic.omp.json" | Invoke-Expression
#oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/nordtron.omp.json" | Invoke-Expression
#oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/devious-diamonds.omp.json" | Invoke-Expression
#oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/kali.omp.json" | Invoke-Expression
#oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/cobalt2.omp.json" | Invoke-Expression
$ENV:STARSHIP_CONFIG = "$env:HOMEPATH/.config/starship.toml"
Invoke-Expression (&starship init powershell)
helm completion powershell | Out-String | Invoke-Expression
# Maybe forcing a oci update on each shell startup
#if (Get-Command kubectl -ErrorAction SilentlyContinue) {
# kubectl completion powershell | Out-String | Invoke-Expression
#}
$prompt = ""
function Invoke-Starship-PreCommand {
$current_location = $executionContext.SessionState.Path.CurrentLocation
if ($current_location.Provider.Name -eq "FileSystem") {
$ansi_escape = [char]27
$provider_path = $current_location.ProviderPath -replace "\\", "/"
$prompt = "$ansi_escape]7;file://${env:COMPUTERNAME}/${provider_path}$ansi_escape\"
}
$host.ui.Write($prompt)
}
Invoke-Expression (& { (zoxide init powershell --hook pwd | Out-String) })
# winfetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment