Browse Source

A lot of new stuff

Docker and Docker-Compose commands and aliases:
- dco: docker-compose
- dcc: docker-compose config
- dcedit/vidc/Edit-DockerCompose:
    edit docker-compose.yml and satellite files
- dcdown.ps1
- dl/dll/dcl/dcll:
    view docker/docker-compose logs
    l : follow
    ll : just list
- dx/dcx: docker / docker-compose exec
- dcdown: docker-compose down
- dcup: docker-compose up
- dcr: docker-compose run
- dcre: docker-compose restart
- dcreup: docker-compose up with force recreate
- di: docker inspect

A bunch of other aliases and tools:
- l/ll - shortcuts for ls -la
- Edit-MyConfig with MyConfig.class: Edit various configuration files
- Update-ArchOSz: my common update params for Arch all ready to run
- Update-UbuntuOSz: my common update params for Ubuntu all ready to run
- sz-df - a ps stylized df
- sz-du - what's the size of a dir
- sys.Linux/ls - a Linux specific ls (with all required configuration)

Works in progress (not completely tested yet):
- Stop-ProcessTree
- Update-OSz.ps1
- src/smartsudo.inc.ps1
master
lksz 1 year ago
parent
commit
310103c2f7
29 changed files with 226 additions and 8 deletions
  1. +1
    -0
      Aliases/dcedit.ps1
  2. +1
    -0
      Aliases/dco.ps1
  3. +1
    -0
      Aliases/l.ps1
  4. +1
    -0
      Aliases/ll.ps1
  5. +1
    -0
      Aliases/vidc.ps1
  6. +14
    -0
      Edit-DockerCompose.ps1
  7. +21
    -0
      Edit-MyConfig.ps1
  8. +13
    -0
      Stop-ProcessTree.ps1
  9. +13
    -0
      Update-ArchOSz.ps1
  10. +10
    -0
      Update-OSz.ps1
  11. +14
    -0
      Update-UbuntuOSz.ps1
  12. +1
    -0
      dcc.ps1
  13. +1
    -0
      dcdown.ps1
  14. +1
    -0
      dcl.ps1
  15. +1
    -0
      dcll.ps1
  16. +1
    -0
      dcr.ps1
  17. +1
    -0
      dcre.ps1
  18. +11
    -0
      dcreup.ps1
  19. +10
    -0
      dcup.ps1
  20. +1
    -0
      dcx.ps1
  21. +1
    -0
      di.ps1
  22. +1
    -0
      dl.ps1
  23. +1
    -0
      dll.ps1
  24. +1
    -0
      dx.ps1
  25. +47
    -6
      profile.d/MyConfig.class.ps1
  26. +18
    -0
      src/smartsudo.inc.ps1
  27. +3
    -2
      sys.Linux/ls.ps1
  28. +35
    -0
      sz-df.ps1
  29. +1
    -0
      sz-du.ps1

+ 1
- 0
Aliases/dcedit.ps1 View File

@@ -0,0 +1 @@
Edit-DockerCompose

+ 1
- 0
Aliases/dco.ps1 View File

@@ -0,0 +1 @@
docker-compose

+ 1
- 0
Aliases/l.ps1 View File

@@ -0,0 +1 @@
ls

+ 1
- 0
Aliases/ll.ps1 View File

@@ -0,0 +1 @@
ls

+ 1
- 0
Aliases/vidc.ps1 View File

@@ -0,0 +1 @@
Edit-DockerCompose

+ 14
- 0
Edit-DockerCompose.ps1 View File

@@ -0,0 +1,14 @@
[CmdletBinding(SupportsShouldProcess)]param([string[]]$ProjectPath=@($PWD))

$local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml')
$local:editFiles = @()
foreach( $local:fileName in $EditCandidates ) {
foreach( $local:path in $ProjectPath ) {
$local:testPath = Join-Path $path $fileName
if( Test-Path $testPath ) { $editFiles += $testPath }
}
}

Edit-TextFile $editFiles

docker-compose config -q

+ 21
- 0
Edit-MyConfig.ps1 View File

@@ -0,0 +1,21 @@
[CmdletBinding(SupportsShouldProcess)]param(
[Parameter(Position = 0, ValueFromRemainingArguments)]
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[MyConfig]::_GetValidValues($wordToComplete,$true) | Sort-Object
})]
[string[]]$ConfigName,
[switch]$Force
)
if( -not $ConfigName ) {
([MyConfig]::_GetValidValues('',$true)) | Sort-Object
return
}
$local:ScriptPaths = [MyConfig]::GetConfigPaths($ConfigName,$Force)

Edit-TextFile $ScriptPaths

+ 13
- 0
Stop-ProcessTree.ps1 View File

@@ -0,0 +1,13 @@
[cmdletbinding()]param([string]$ProcessName)
$local:new_KillPIDs = @() + (Get-Process -name $processName | Select-Object -ExpandProperty ID)
$local:KillPIDs = @()
Do {
$KillPIDs += $new_KillPIDs | Where-Object { $_ -notin $KillPIDs }
Write-Verbose "Again"
Write-Verbose $new_KillPIDs -join ", "
$new_KillPIDs = $new_KillPIDs | ForEach-Object { Get-CimInstance -ClassName Win32_Process -Filter "ParentProcessId = $_" } | Select-Object -ExpandProperty ProcessId
} Until ( -not $new_KillPIDs )

Write-Verbose "Done"

start-process powershell -ArgumentList "-command","Stop-Process -Force -Id @($($KillPIDs -join '', ''))" -WindowStyle Minimized

+ 13
- 0
Update-ArchOSz.ps1 View File

@@ -0,0 +1,13 @@
param(
[ValidateSet('List','Update','Auto','All')]
[string]$Mode = 'List'
)

$script:yayCli = "cat /run/check.yay.updates/list"
switch( $Mode ){
'Update' { $yayCli = "yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux" }
'Auto' { $yayCli = "yay -Syu --needed --noconfirm --ignore docker || yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux --noconfirm" }
'All' { $yayCli = "yay -Syu --needed" }
}

& sh "-c" "$yayCli" -replace '#args',"$args"

+ 10
- 0
Update-OSz.ps1 View File

@@ -0,0 +1,10 @@
param(
[ValidateSet('List','Update','Auto','All')]
[string]$Mode = 'List'
)

$local:detectedDisistro = cat /etc/os-release | Select-String -Pattern "^ID=" | ForEach-Object { $_ -split '=' | Select-Object -Skip 1 }
switch ($detectedDisistro) {
'arch' { Update-ArchOSz -Mode:$Mode $args }
'ubuntu' { Update-UbuntuOSz -Mode:$Mode $args }
}

+ 14
- 0
Update-UbuntuOSz.ps1 View File

@@ -0,0 +1,14 @@
param(
[ValidateSet('List','Update','Auto','All')]
[string]$Mode = 'List'
)

$script:aptCli = "echo 'not defined'"
switch( $Mode ){
'List' { }
'Auto' { $aptCli = "sudo apt-get update && sudo apt-get upgrade --auto-remove --assume-yes" }
default { $aptCli = "sudo apt-get update && sudo apt-get upgrade --auto-remove " }
}

& sh "-c" "$aptCli" -replace '#args',"$args"


+ 1
- 0
dcc.ps1 View File

@@ -0,0 +1 @@
docker-compose config | less

+ 1
- 0
dcdown.ps1 View File

@@ -0,0 +1 @@
docker-compose down --timeout=3 --volumes --remove-orphans "$args"

+ 1
- 0
dcl.ps1 View File

@@ -0,0 +1 @@
docker-compose logs --tail=40 --follow "$args"

+ 1
- 0
dcll.ps1 View File

@@ -0,0 +1 @@
docker-compose logs "$args"

+ 1
- 0
dcr.ps1 View File

@@ -0,0 +1 @@
docker-compose run --rm "$args"

+ 1
- 0
dcre.ps1 View File

@@ -0,0 +1 @@
docker-compose restart "$args"

+ 11
- 0
dcreup.ps1 View File

@@ -0,0 +1,11 @@
#[CmdletBinding(SupportsShouldProcess)]param()

$local:dcParams = [string]::Empty
if( $args ) {
$dcParams = $args | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
}
}
docker-compose up -d --force-recreate --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams


+ 10
- 0
dcup.ps1 View File

@@ -0,0 +1,10 @@
#[CmdletBinding(SupportsShouldProcess)]param()

$local:dcParams = [string]::Empty
if( $args ) {
$dcParams = $args | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
}
}
docker-compose up -d --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams

+ 1
- 0
dcx.ps1 View File

@@ -0,0 +1 @@
docker-compose exec "$args"

+ 1
- 0
di.ps1 View File

@@ -0,0 +1 @@
docker inspect "$args"

+ 1
- 0
dl.ps1 View File

@@ -0,0 +1 @@
docker logs --tail=40 --follow "$args"

+ 1
- 0
dll.ps1 View File

@@ -0,0 +1 @@
docker logs "$args"

+ 1
- 0
dx.ps1 View File

@@ -0,0 +1 @@
docker exec "$args"

+ 47
- 6
profile.d/MyConfig.class.ps1 View File

@@ -1,13 +1,54 @@
class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
static [hashtable]$configDirectory = [ordered]@{
'vi' = '~/.virc'
'vim' = '~/.vimrc','~/.vim/vimrc'
'neovim' = '~/.config/nvim/init.vim','~/.config/nvim/vim-plug/plugins.vim','#vim','#vi'
static [hashtable]$configDirectory = @{};
static ReloadConfigPaths() {
[MyConfig]::ConfigDirectory = [ordered]@{
'vi' = '~/.virc'
'vim' = '~/.vimrc','~/.vim/vimrc'
'neovim' = '~/.config/nvim/init.vim','~/.config/nvim/vim-plug/plugins.vim','#vim','#vi'
'zshrc' = '~/.zshrc'
'sz-zshrc' = '~/.sz.zshrc.sh', '#zshrc'
'sz-local-rc' = '~/.sz.local.sh'
'sz-aliases-sh' = '~/.sz.aliases.sh'
'sz-shrc' = '~/.sz.shrc.sh'
'sz-rc-all' = '#sz-aliases-sh', '#sz-local-rc', '#sz-shrc', '#sz-zshrc', '#zshrc'
'tmux' = '~/.tmux.conf', '~/.byobu/.tmux.conf'
}
}
static [string[]] GetConfigPaths([string[]]$ConfigNames) {
return $null
static [string[]] GetConfigPaths([string[]]$ConfigNames,[switch]$Force) {
[MyConfig]::ReloadConfigPaths()
$local:result = [string[]]@()
$local:flat = $false
while(-not $flat) {
$flat = $true
$ConfigNames += $ConfigNames | ForEach-Object {
[MyConfig]::configDirectory[$_]
} | Where-Object { $_ -match '^#[\w-\.]+$' } | ForEach-Object {
$_.Substring(1)
} | Where-Object { $_ -notin $ConfigNames } | ForEach-Object {
$flat = false; $_;
}
}

$local:flatConfigList = $ConfigNames | ForEach-Object {
[MyConfig]::configDirectory[$_]
} | Where-Object { $_ -notmatch '^#[\w-\.]+$' }

$local:exists = $false;
$local:first = $null
foreach( $local:configPath in $flatConfigList ) {
if( -not $first ) { $first = $configPath }
if( $Force -or (Test-Path $configPath) ) {
$result += Resolve-Path $configPath
$exists = $true
}
}
if( -not $exists -and -not $Force ) {
$result += $first
}
return $result
}
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
[MyConfig]::ReloadConfigPaths()
$local:possibleValues = [MyConfig]::configDirectory.Keys
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}


+ 18
- 0
src/smartsudo.inc.ps1 View File

@@ -0,0 +1,18 @@
function smartsudo() {
[CmdletBinding(SupportsShouldProcess)]param(
[switch]$sudo,
[switch]$Force,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$expr
)

if( $sudo -and -not $(Test-IsAdmin) ) {
Write-Verbose "Perofrming the following command line via SUDO:`n$($expr -join ' ')"
$local:base64command = ConvertTo-Base64 "$expr"
/usr/bin/env sudo pwsh -EncodedCommand $base64command
return
}
Write-Verbose "Perofrming the following expression in-line:`n$($expr -join ' ')"
Invoke-Expression "$expr"
}

+ 3
- 2
sys.Linux/ls.ps1 View File

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

/usr/bin/env ls --color=auto $params


+ 35
- 0
sz-df.ps1 View File

@@ -0,0 +1,35 @@
param([ValidateSet('KB','GB','TB')]$SizeUnitName = 'GB')
$local:zpool_cmd = $null
$local:excludeType = ''

$script:SizeUnit = Invoke-Expression "1$SizeUnitName"
$script:SizeRound = 2
$SizeUnit /= 1KB

function NewDataRow{param($Size,$Used,$Available,$Percent,$Source,$FSType,$Target)
[PSCustomObject]@{
"Size$SizeUnitName" = [Math]::Round($Size /$SizeUnit, $SizeRound)
"Used$SizeUnitName" = [Math]::Round($Used /$SizeUnit, $SizeRound)
"Available$SizeUnitName" = [Math]::Round($Available/$SizeUnit, $SizeRound)
'Used%' = [int]($Percent -replace '%$','')
Source = $Source
FSType = $FSType
Target = $Target
}
}

$local:df = @()
& df '--output=size,used,avail,pcent,source,fstype,target' |
Select-Object -Skip 1 | ForEach-Object {
$local:df = $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)
NewDataRow $df[0] $df[1] $df[2] $df[3] $df[4] $df[5] $df[6]
} | Where-Object {
-not ($_.FSType -eq 'zfs' -and $_.Source -match '/')
} | Sort-Object -Property Target

#$zpool_cmd = get-command zpool | Where-Object CommandType -eq 'Application' | Select-Object -ExpandProperty Source
#if( $zpool_cmd ) {
# $excludeType = '--exclude-type=zfs'
#}



+ 1
- 0
sz-du.ps1 View File

@@ -0,0 +1 @@
sudo /bin/du --human-readable --max-depth=1 --one-file-system $args | sort --human-numeric-sort --reverse

Loading…
Cancel
Save