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
This commit is contained in:
parent
306e03874d
commit
310103c2f7
|
@ -0,0 +1 @@
|
|||
Edit-DockerCompose
|
|
@ -0,0 +1 @@
|
|||
docker-compose
|
|
@ -0,0 +1 @@
|
|||
ls
|
|
@ -0,0 +1 @@
|
|||
ls
|
|
@ -0,0 +1 @@
|
|||
Edit-DockerCompose
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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"
|
|
@ -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 }
|
||||
}
|
|
@ -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"
|
||||
|
|
@ -0,0 +1 @@
|
|||
docker-compose down --timeout=3 --volumes --remove-orphans "$args"
|
|
@ -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
|
||||
|
|
@ -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,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 );
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
#}
|
||||
|
||||
|
Loading…
Reference in New Issue