Browse Source

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.
master
lksz 1 year ago
parent
commit
968b6c2bbb
11 changed files with 41 additions and 6 deletions
  1. +1
    -0
      Aliases/edit
  2. +1
    -0
      Aliases/nvim
  3. +1
    -0
      Aliases/vi
  4. +1
    -0
      Aliases/vim
  5. +2
    -0
      ConvertFrom-Base64.ps1
  6. +2
    -1
      Edit-MyScript.ps1
  7. +6
    -0
      Invoke-Sudo.ps1
  8. +10
    -3
      Reload-MyScripts.ps1
  9. +12
    -0
      dps.ps1
  10. +4
    -0
      sys.Linux/ls.ps1
  11. +1
    -2
      sys.Linux/sranger.ps1

+ 1
- 0
Aliases/edit View File

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

+ 1
- 0
Aliases/nvim View File

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

+ 1
- 0
Aliases/vi View File

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

+ 1
- 0
Aliases/vim View File

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

+ 2
- 0
ConvertFrom-Base64.ps1 View File

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

+ 2
- 1
Edit-MyScript.ps1 View File

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



+ 6
- 0
Invoke-Sudo.ps1 View File

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

. Invoke-ExpressionEx -sudo $expr

+ 10
- 3
Reload-MyScripts.ps1 View File

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


+ 12
- 0
dps.ps1 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
- 0
sys.Linux/ls.ps1 View File

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


+ 1
- 2
sys.Linux/sranger.ps1 View File

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

Loading…
Cancel
Save