Adding common commands + Minor modifications

Reload-MyScripts modified to check for past aliases that might block it
from working.
Aliases dir created with some basic aliases
Invoke-Sudo to make sudo command line calling simpler.
This commit is contained in:
lksz 2020-10-03 16:17:11 -04:00
parent 38aa7720de
commit 968b6c2bbb
11 changed files with 41 additions and 6 deletions

1
Aliases/edit Normal file
View File

@ -0,0 +1 @@
Edit-TextFile

1
Aliases/nvim Normal file
View File

@ -0,0 +1 @@
Edit-TextFile

1
Aliases/vi Normal file
View File

@ -0,0 +1 @@
Edit-TextFile

1
Aliases/vim Normal file
View File

@ -0,0 +1 @@
Edit-TextFile

2
ConvertFrom-Base64.ps1 Normal file
View File

@ -0,0 +1,2 @@
param([string]$Base64String)
return [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($Base64String))

View File

@ -66,7 +66,8 @@ if( -not $ScriptPaths ) {
foreach( $local:p in $ScriptPaths ) { foreach( $local:p in $ScriptPaths ) {
$local:parentPath = Split-Path -Parent $p; $local:parentPath = Split-Path -Parent $p;
if( -not (Test-Path $p) -and -not (Test-Path $parentPath) ) { 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
} }
} }

6
Invoke-Sudo.ps1 Normal file
View File

@ -0,0 +1,6 @@
[CmdletBinding(SupportsShouldProcess)]param(
[Parameter(Mandatory = $true,Position = 0, ValueFromRemainingArguments = $true)]
$expr
)
. Invoke-ExpressionEx -sudo $expr

View File

@ -1,5 +1,6 @@
[CmdletBinding(SupportsShouldProcess)]param() [CmdletBinding(SupportsShouldProcess)]param()
try { Get-Alias Get-MyAliases -ErrorAction Stop | ForEach-Object { Remove-Item "Alias:$($_.Name)" } } catch {}
function Get-MyAliases { function Get-MyAliases {
[CmdletBinding(SupportsShouldProcess)]param([switch]$ScriptsOnly) [CmdletBinding(SupportsShouldProcess)]param([switch]$ScriptsOnly)
@ -29,9 +30,13 @@ function Get-MyAliases {
$allAliases $allAliases
} }
function getScriptName{param([string]$FullPath)
$FullPath -replace '\.ps1$','' -replace "^$([regex]::Escape($MyPSScriptRoot)).",''
}
$local:myAliases = [ordered]@{} $local:myAliases = [ordered]@{}
if( Test-Path $(Join-Path $MyPSScriptRoot Aliases) ) { 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 $_ $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" } 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 { 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)';" ". '$($_.FullName)';"
} | Invoke-Expression } | Invoke-Expression
$local:CommandsToAlias = ( $local:CommandsToAlias = (
@( $MyPSScriptRoot ) + $( @( $MyPSScriptRoot ) + $(
[SystemName]::_GetValidValues("",$true,$true) | ForEach-Object { [SystemName]::_GetValidValues("",$true,$true) | ForEach-Object {
Join-Path $MyPSScriptRoot $_ Join-Path $MyPSScriptRoot "sys.$_"
} }
)) | ForEach-Object { )) | ForEach-Object {
if( Test-Path $_ ) { if( Test-Path $_ ) {
@ -72,10 +77,12 @@ $local:CommandsToAlias = (
} }
$CommandsToAlias | ForEach-Object { $CommandsToAlias | ForEach-Object {
Write-Verbose "Creating alias for $(getScriptName $_.FullName) Script..."
Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope
} }
foreach( $local:alias in $myAliases.Keys ) { foreach( $local:alias in $myAliases.Keys ) {
Write-Verbose "Adding $($alias) alias..."
Set-Alias -Name $alias -Value $myAliases[$alias] -Description '#MyAlias' -Scope $MyAliasScope Set-Alias -Name $alias -Value $myAliases[$alias] -Description '#MyAlias' -Scope $MyAliasScope
} }

12
dps.ps1 Normal file
View File

@ -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

4
sys.Linux/ls.ps1 Normal file
View File

@ -0,0 +1,4 @@
$local:params = $args -join ' '
if( -not $params ) { $params = '-la' }
/usr/bin/env ls $params

View File

@ -1,2 +1 @@
Invoke-ExpressionEx -sudo "`$env:TERM='tmux-256color'; `$env:EDITOR='$env:EDITOR'; ranger $args"
Invoke-ExpressionEx -sudo "`$env:TERM='tmux-256color'; `$env:EDITOR='$env:EDITOR'; ranger"