diff --git a/Aliases/edit b/Aliases/edit new file mode 100644 index 0000000..e099b51 --- /dev/null +++ b/Aliases/edit @@ -0,0 +1 @@ +Edit-TextFile diff --git a/Aliases/nvim b/Aliases/nvim new file mode 100644 index 0000000..e099b51 --- /dev/null +++ b/Aliases/nvim @@ -0,0 +1 @@ +Edit-TextFile diff --git a/Aliases/vi b/Aliases/vi new file mode 100644 index 0000000..e099b51 --- /dev/null +++ b/Aliases/vi @@ -0,0 +1 @@ +Edit-TextFile diff --git a/Aliases/vim b/Aliases/vim new file mode 100644 index 0000000..e099b51 --- /dev/null +++ b/Aliases/vim @@ -0,0 +1 @@ +Edit-TextFile diff --git a/ConvertFrom-Base64.ps1 b/ConvertFrom-Base64.ps1 new file mode 100644 index 0000000..4dbbdeb --- /dev/null +++ b/ConvertFrom-Base64.ps1 @@ -0,0 +1,2 @@ +param([string]$Base64String) + return [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($Base64String)) diff --git a/Edit-MyScript.ps1 b/Edit-MyScript.ps1 index ddfbdbe..a3e57ba 100644 --- a/Edit-MyScript.ps1 +++ b/Edit-MyScript.ps1 @@ -66,7 +66,8 @@ if( -not $ScriptPaths ) { foreach( $local:p in $ScriptPaths ) { $local:parentPath = Split-Path -Parent $p; if( -not (Test-Path $p) -and -not (Test-Path $parentPath) ) { - New-Item -Directory $parentPath + Write-Verbose "Creating missing path $parentPath..." + New-Item -Type Directory $parentPath } } diff --git a/Invoke-Sudo.ps1 b/Invoke-Sudo.ps1 new file mode 100644 index 0000000..c8816d3 --- /dev/null +++ b/Invoke-Sudo.ps1 @@ -0,0 +1,6 @@ +[CmdletBinding(SupportsShouldProcess)]param( + [Parameter(Mandatory = $true,Position = 0, ValueFromRemainingArguments = $true)] + $expr +) + +. Invoke-ExpressionEx -sudo $expr diff --git a/Reload-MyScripts.ps1 b/Reload-MyScripts.ps1 index 2762b22..a2017bf 100644 --- a/Reload-MyScripts.ps1 +++ b/Reload-MyScripts.ps1 @@ -1,5 +1,6 @@ [CmdletBinding(SupportsShouldProcess)]param() +try { Get-Alias Get-MyAliases -ErrorAction Stop | ForEach-Object { Remove-Item "Alias:$($_.Name)" } } catch {} function Get-MyAliases { [CmdletBinding(SupportsShouldProcess)]param([switch]$ScriptsOnly) @@ -29,9 +30,13 @@ function Get-MyAliases { $allAliases } +function getScriptName{param([string]$FullPath) + $FullPath -replace '\.ps1$','' -replace "^$([regex]::Escape($MyPSScriptRoot)).",'' +} + $local:myAliases = [ordered]@{} if( Test-Path $(Join-Path $MyPSScriptRoot Aliases) ) { - Get-ChildItem Join-Path (Join-Path $MyPSScriptRoot Aliases) | ForEach-Object { + Get-ChildItem $(Join-Path $MyPSScriptRoot Aliases) | ForEach-Object { $myAliases[$_.BaseName] = Get-Content $_ } } @@ -56,14 +61,14 @@ if( Get-Command Remove-Alias -ErrorAction SilentlyContinue ) { if( $(. Get-ScopeDepth) -gt 0 ) { Write-Host -ForegroundColor Red "Try sourcing Reload-MyScripts instead of just running it" } Get-ChildItem $(Join-Path $MyPSScriptRoot profile.d) -Filter '*.ps1' | ForEach-Object { - Write-Verbose "Loading $($_.FullName -replace '\.ps1$','' -replace "^$([regex]::Escape($MyPSScriptRoot)).",'')..."; + Write-Verbose "Loading $(getScriptName $_.FullName)..."; ". '$($_.FullName)';" } | Invoke-Expression $local:CommandsToAlias = ( @( $MyPSScriptRoot ) + $( [SystemName]::_GetValidValues("",$true,$true) | ForEach-Object { - Join-Path $MyPSScriptRoot $_ + Join-Path $MyPSScriptRoot "sys.$_" } )) | ForEach-Object { if( Test-Path $_ ) { @@ -72,10 +77,12 @@ $local:CommandsToAlias = ( } $CommandsToAlias | ForEach-Object { + Write-Verbose "Creating alias for $(getScriptName $_.FullName) Script..." Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope } foreach( $local:alias in $myAliases.Keys ) { + Write-Verbose "Adding $($alias) alias..." Set-Alias -Name $alias -Value $myAliases[$alias] -Description '#MyAlias' -Scope $MyAliasScope } diff --git a/dps.ps1 b/dps.ps1 new file mode 100644 index 0000000..85aa8c6 --- /dev/null +++ b/dps.ps1 @@ -0,0 +1,12 @@ +#[CmdletBinding(SupportsShouldProcess)]param( +[CmdletBinding()]param([string[]]$OrderBy,[switch]$PassThru) + +$local:result = $(docker ps --format='{{ .Image }}\t{{ .Names }}\t{{ .Status }}\t{{ .Ports }}' | ForEach-Object { $local:l = $_ -split '\t'; [PSCustomObject](@{Image=$l[0];Names=$l[1];Status=$l[2];Ports=$l[3] -replace ', '," +"}) } ) | Sort-Object Names + +if( $OrderBy ) { + $result = $result | Sort-Object $OrderBy +} + +if( $PassThru ) { return $result } +$result | Format-Table -Wrap -Property Image,Names,Status,Ports diff --git a/sys.Linux/ls.ps1 b/sys.Linux/ls.ps1 new file mode 100644 index 0000000..42cc8eb --- /dev/null +++ b/sys.Linux/ls.ps1 @@ -0,0 +1,4 @@ +$local:params = $args -join ' ' +if( -not $params ) { $params = '-la' } +/usr/bin/env ls $params + diff --git a/sys.Linux/sranger.ps1 b/sys.Linux/sranger.ps1 index fa3e734..d8146d3 100644 --- a/sys.Linux/sranger.ps1 +++ b/sys.Linux/sranger.ps1 @@ -1,2 +1 @@ - -Invoke-ExpressionEx -sudo "`$env:TERM='tmux-256color'; `$env:EDITOR='$env:EDITOR'; ranger" +Invoke-ExpressionEx -sudo "`$env:TERM='tmux-256color'; `$env:EDITOR='$env:EDITOR'; ranger $args"