New commands + fixes

+ Get-Mount (mounts retuned as objects for easy filtering)
+ Get-RandomMacAddress (for easy MAC Address generation)
* Get-Path modified to resolve ~, also made it work with pipeline input
* Edit-TextFile streamlined by using modified Get-Path
* Added emacs and spacemacs to MyConfig
* dcup - attempt at cleaner output
+ added docker/profile.d/env.ps1 for default docker vars
This commit is contained in:
lksz 2021-02-18 10:53:32 -05:00
parent f947b0b3b4
commit f7df96c55d
7 changed files with 127 additions and 78 deletions

14
base.linux/Get-Mount.ps1 Normal file
View File

@ -0,0 +1,14 @@
[CmdletBinding()]param()
& mount |
ForEach-Object {
$null = $_ -match "^(.*) on (/.*) type ([^ ]*)( (.*))?$";
[PSCustomObject]([ordered]@{
Path = $matches[2]
Type = $matches[3]
Name = $matches[1]
Options = $matches[5]
# Matches = $Matches
# Raw = $_
})
}

View File

@ -23,11 +23,7 @@ if( $editor -match 'code(\.exe)?$' ) {
} }
} }
$local:arguments = $($Path | ForEach-Object { $local:arguments = $Path | Get-Path | Join-String -Separator "' '"
if ($Path -match '\*|\?|~') {
Get-ChildItem -Path $_ | Select-Object -ExpandProperty FullName
} else { $_ }
} ) -join "' '"
if( $Path ) { $arguments = "'$arguments'" } if( $Path ) { $arguments = "'$arguments'" }
if( $PSCmdlet.ShouldProcess( "Edit ($editor): $arguments" ) ) { if( $PSCmdlet.ShouldProcess( "Edit ($editor): $arguments" ) ) {

View File

@ -1,25 +1,38 @@
[CmdletBinding()]param([string]$Path) [CmdletBinding()]param(
[Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName,Position=0)]
[Alias("FullName")]
[string[]]$Path
)
process {
function Get-FullPath { function Get-FullPath {
param([string]$Path) param([string]$Path)
if([System.IO.Path]::IsPathRooted($Path)){ if([System.IO.Path]::IsPathRooted($Path)){
[System.IO.Path]::GetFullPath($Path) [System.IO.Path]::GetFullPath($Path)
}else{ }else{
[System.IO.Path]::GetFullPath((Join-Path $PWD $Path)) [System.IO.Path]::GetFullPath((Join-Path $PWD $Path))
}
}
foreach( $local:p in $Path ) {
switch( $p[0] ) {
'@' { $p = Join-Path $MyPSScriptRoot $p.Substring(1) }
'~' {
if( $p -match '^~[^/]*' ) {
$local:m = $Matches[0]
$p = $p -replace "^$m",((Get-Item $m).FullName)
}
}
}
if([System.IO.Path]::IsPathRooted($p)){
[System.IO.Path]::GetFullPath($p)
}else{
[System.IO.Path]::GetFullPath((Join-Path $PWD $p))
}
} }
} }
if( $Path[0] -eq '@' ) {
$Path = Join-Path $MyPSScriptRoot $Path.Substring(1)
}
if([System.IO.Path]::IsPathRooted($Path)){
[System.IO.Path]::GetFullPath($Path)
}else{
[System.IO.Path]::GetFullPath((Join-Path $PWD $Path))
}
# try { # try {
# get-item $Path -Force -ErrorAction Stop | # get-item $Path -Force -ErrorAction Stop |
# Select-Object -ExpandProperty FullName # Select-Object -ExpandProperty FullName

View File

@ -0,0 +1,11 @@
[CmdletBinding()]param(
[string]$Delimiter=':'
)
$(0..5 | ForEach-Object {
'{0:x}{1:x}' -f (
Get-Random -Minimum 0 -Maximum 15
), (
Get-Random -Minimum 0 -Maximum 15
)
}) -join $Delimiter

View File

@ -1,56 +1,64 @@
{ {
"neovim": [ "neovim": [
"~/.config/nvim/init.vim", "~/.config/nvim/init.vim",
"~/.config/nvim/vim-plug/plugins.vim", "~/.config/nvim/vim-plug/plugins.vim",
"#vim", "#vim",
"#vi" "#vi"
], ],
"vi": "~/.virc", "vi": "~/.virc",
"zshrc": "~/.zshrc", "zshrc": "~/.zshrc",
"shrc": "~/.shrc", "shrc": "~/.shrc",
"sz-aliases-sh": "~/.sz.aliases.sh", "sz-aliases-sh": "~/.sz.aliases.sh",
"sz-shrc": [ "sz-shrc": [
"~/.sz.shrc.sh", "~/.sz.shrc.sh",
"#shrc", "#shrc",
"@shell-loading-snippets/bash", "@shell-loading-snippets/bash",
"@shell-loading-snippets/sh" "@shell-loading-snippets/sh"
], ],
"sz-zshrc": [ "sz-zshrc": [
"~/.sz.zshrc.sh", "~/.sz.zshrc.sh",
"#zshrc", "#zshrc",
"@shell-loading-snippets/zsh" "@shell-loading-snippets/zsh"
], ],
"sz-rc-all": [ "sz-rc-all": [
"#sz-aliases-sh", "#sz-aliases-sh",
"#sz-local-rc", "#sz-local-rc",
"#sz-shrc", "#sz-shrc",
"#sz-zshrc", "#sz-zshrc",
"#zshrc" "#zshrc"
], ],
"sz-local-rc": "~/.sz.local.sh", "sz-local-rc": "~/.sz.local.sh",
"ansible": [ "ansible": [
"/etc/ansible/ansible.cfg", "/etc/ansible/ansible.cfg",
"/opt/ansible/ansible.cfg", "/opt/ansible/ansible.cfg",
"/opt/ansible/hosts" "/opt/ansible/hosts"
], ],
"vim": [ "emacs": [
"~/.vimrc", "~/.emacs",
"~/.vim/vimrc" "~/.emacs.d"
], ],
"nvim": [ "spacemacs": [
"~/.config/nvim/init.vim", "~/.spacemacs",
"~/.nvimrc", "#emacs"
"#vim" ],
], "vim": [
"tmux": [ "~/.vimrc",
"~/.tmux.conf", "~/.vim/vimrc"
"~/.byobu/.tmux.conf" ],
], "nvim": [
"ssh-pub": "~/.ssh/id_*.pub", "~/.config/nvim/init.vim",
"ssh-id": ["~/.ssh/id_ed25519","~/.ssh/id_rsa"], "~/.nvimrc",
"ssh-auth": "~/.ssh/authorized_keys", "#vim"
"ssh-known": "~/.ssh/known_hosts", ],
"ssh-conf": "~/.ssh/config", "tmux": [
"sshd-conf": "/etc/ssh/sshd_config", "~/.tmux.conf",
"ssh" : [ "#ssh-auth", "#ssh-known", "#ssh-conf", "#sshd-conf", "#ssh-pub", "#ssh-id" ] "~/.byobu/.tmux.conf"
],
"ssh-pub": "~/.ssh/id_*.pub",
"ssh-id": ["~/.ssh/id_ed25519","~/.ssh/id_rsa"],
"ssh-auth": "~/.ssh/authorized_keys",
"ssh-known": "~/.ssh/known_hosts",
"ssh-conf": "~/.ssh/config",
"sshd-conf": "/etc/ssh/sshd_config",
"ssh" : [ "#ssh-auth", "#ssh-known", "#ssh-conf", "#sshd-conf", "#ssh-pub", "#ssh-id" ]
} }

View File

@ -15,7 +15,7 @@
[switch]$NoPull, [switch]$NoPull,
[array]$PullParams, [array]$PullParams,
[array]$LogsParams, [array]$LogsParams,
[array]$UpParams=@('-d','--remove-orphans'), [array]$UpParams=@('--detach','--remove-orphans'),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)] [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[array]$Containers [array]$Containers
) )
@ -44,6 +44,8 @@ if( -not $LogsParams[0] ) {
$logsParams[0] += @("--tail=$tailLen") $logsParams[0] += @("--tail=$tailLen")
} }
$local:moreParams = @()
#if( $ForceNoFollow ) { $moreParams = @('--no-color', '--quiet-pull') }
$PullParams[0] = @('pull' ) + $PullParams[0] + $Containers $PullParams[0] = @('pull' ) + $PullParams[0] + $Containers
if( $ForceNoFollow ) { $PullParams[0] = @('&') + $PullParams[0] } if( $ForceNoFollow ) { $PullParams[0] = @('&') + $PullParams[0] }
$UpParams[0] = @('up' ) + $UpParams[0] + $Containers $UpParams[0] = @('up' ) + $UpParams[0] + $Containers

5
docker/profile.d/env.ps1 Normal file
View File

@ -0,0 +1,5 @@
# 1 - Use native build, which is the default for docker compose
# Setting this supresses the following line, which would otherwise be displayed:
#### Building with native build. Learn about native build in
#### Compose here: https://docs.docker.com/go/compose-native-build/
$env:COMPOSE_DOCKER_CLI_BUILD=1