diff --git a/Aliases/dcedit.ps1 b/Aliases/dcedit.ps1 new file mode 100644 index 0000000..a5533c7 --- /dev/null +++ b/Aliases/dcedit.ps1 @@ -0,0 +1 @@ +Edit-DockerCompose diff --git a/Aliases/dco.ps1 b/Aliases/dco.ps1 new file mode 100644 index 0000000..e41f756 --- /dev/null +++ b/Aliases/dco.ps1 @@ -0,0 +1 @@ +docker-compose diff --git a/Aliases/l.ps1 b/Aliases/l.ps1 new file mode 100644 index 0000000..9e2740c --- /dev/null +++ b/Aliases/l.ps1 @@ -0,0 +1 @@ +ls diff --git a/Aliases/ll.ps1 b/Aliases/ll.ps1 new file mode 100644 index 0000000..9e2740c --- /dev/null +++ b/Aliases/ll.ps1 @@ -0,0 +1 @@ +ls diff --git a/Aliases/vidc.ps1 b/Aliases/vidc.ps1 new file mode 100644 index 0000000..a5533c7 --- /dev/null +++ b/Aliases/vidc.ps1 @@ -0,0 +1 @@ +Edit-DockerCompose diff --git a/Edit-DockerCompose.ps1 b/Edit-DockerCompose.ps1 new file mode 100644 index 0000000..9557e54 --- /dev/null +++ b/Edit-DockerCompose.ps1 @@ -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 diff --git a/Edit-MyConfig.ps1 b/Edit-MyConfig.ps1 new file mode 100644 index 0000000..882f5cf --- /dev/null +++ b/Edit-MyConfig.ps1 @@ -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 diff --git a/Stop-ProcessTree.ps1 b/Stop-ProcessTree.ps1 new file mode 100644 index 0000000..9e838e0 --- /dev/null +++ b/Stop-ProcessTree.ps1 @@ -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 diff --git a/Update-ArchOSz.ps1 b/Update-ArchOSz.ps1 new file mode 100644 index 0000000..2c8e0b2 --- /dev/null +++ b/Update-ArchOSz.ps1 @@ -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" diff --git a/Update-OSz.ps1 b/Update-OSz.ps1 new file mode 100644 index 0000000..a82dfcc --- /dev/null +++ b/Update-OSz.ps1 @@ -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 } +} diff --git a/Update-UbuntuOSz.ps1 b/Update-UbuntuOSz.ps1 new file mode 100644 index 0000000..71bc9bf --- /dev/null +++ b/Update-UbuntuOSz.ps1 @@ -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" + diff --git a/dcc.ps1 b/dcc.ps1 new file mode 100644 index 0000000..f8a1e1c --- /dev/null +++ b/dcc.ps1 @@ -0,0 +1 @@ +docker-compose config | less diff --git a/dcdown.ps1 b/dcdown.ps1 new file mode 100644 index 0000000..a7cd9c5 --- /dev/null +++ b/dcdown.ps1 @@ -0,0 +1 @@ +docker-compose down --timeout=3 --volumes --remove-orphans "$args" diff --git a/dcl.ps1 b/dcl.ps1 new file mode 100644 index 0000000..d41ca60 --- /dev/null +++ b/dcl.ps1 @@ -0,0 +1 @@ +docker-compose logs --tail=40 --follow "$args" diff --git a/dcll.ps1 b/dcll.ps1 new file mode 100644 index 0000000..a5ffc0d --- /dev/null +++ b/dcll.ps1 @@ -0,0 +1 @@ +docker-compose logs "$args" diff --git a/dcr.ps1 b/dcr.ps1 new file mode 100644 index 0000000..6406f9e --- /dev/null +++ b/dcr.ps1 @@ -0,0 +1 @@ +docker-compose run --rm "$args" diff --git a/dcre.ps1 b/dcre.ps1 new file mode 100644 index 0000000..f0fc796 --- /dev/null +++ b/dcre.ps1 @@ -0,0 +1 @@ +docker-compose restart "$args" diff --git a/dcreup.ps1 b/dcreup.ps1 new file mode 100644 index 0000000..052c0d5 --- /dev/null +++ b/dcreup.ps1 @@ -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 + diff --git a/dcup.ps1 b/dcup.ps1 new file mode 100644 index 0000000..5ab64b0 --- /dev/null +++ b/dcup.ps1 @@ -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 diff --git a/dcx.ps1 b/dcx.ps1 new file mode 100644 index 0000000..130dda9 --- /dev/null +++ b/dcx.ps1 @@ -0,0 +1 @@ +docker-compose exec "$args" diff --git a/di.ps1 b/di.ps1 new file mode 100644 index 0000000..97c8027 --- /dev/null +++ b/di.ps1 @@ -0,0 +1 @@ +docker inspect "$args" diff --git a/dl.ps1 b/dl.ps1 new file mode 100644 index 0000000..6d4edec --- /dev/null +++ b/dl.ps1 @@ -0,0 +1 @@ +docker logs --tail=40 --follow "$args" diff --git a/dll.ps1 b/dll.ps1 new file mode 100644 index 0000000..cadf8c1 --- /dev/null +++ b/dll.ps1 @@ -0,0 +1 @@ +docker logs "$args" diff --git a/dx.ps1 b/dx.ps1 new file mode 100644 index 0000000..d69452c --- /dev/null +++ b/dx.ps1 @@ -0,0 +1 @@ +docker exec "$args" diff --git a/profile.d/MyConfig.class.ps1 b/profile.d/MyConfig.class.ps1 index 19f3d52..eb4a92f 100644 --- a/profile.d/MyConfig.class.ps1 +++ b/profile.d/MyConfig.class.ps1 @@ -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 ); } diff --git a/src/smartsudo.inc.ps1 b/src/smartsudo.inc.ps1 new file mode 100644 index 0000000..0dee229 --- /dev/null +++ b/src/smartsudo.inc.ps1 @@ -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" +} diff --git a/sys.Linux/ls.ps1 b/sys.Linux/ls.ps1 index 42cc8eb..89ef76e 100644 --- a/sys.Linux/ls.ps1 +++ b/sys.Linux/ls.ps1 @@ -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 diff --git a/sz-df.ps1 b/sz-df.ps1 new file mode 100644 index 0000000..c1adf10 --- /dev/null +++ b/sz-df.ps1 @@ -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' +#} + + diff --git a/sz-du.ps1 b/sz-du.ps1 new file mode 100644 index 0000000..134e3bf --- /dev/null +++ b/sz-du.ps1 @@ -0,0 +1 @@ +sudo /bin/du --human-readable --max-depth=1 --one-file-system $args | sort --human-numeric-sort --reverse