From f7df96c55d89b69d5fcf7323930de9b8aef568c3 Mon Sep 17 00:00:00 2001 From: lksz Date: Thu, 18 Feb 2021 10:53:32 -0500 Subject: [PATCH] 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 --- base.linux/Get-Mount.ps1 | 14 ++++ base/Edit-TextFile.ps1 | 6 +- base/Get-Path.ps1 | 49 ++++++++------ base/Get-RandomMacAddress.ps1 | 11 ++++ base/src/config.files.json | 116 ++++++++++++++++++---------------- docker/dcup.ps1 | 4 +- docker/profile.d/env.ps1 | 5 ++ 7 files changed, 127 insertions(+), 78 deletions(-) create mode 100644 base.linux/Get-Mount.ps1 create mode 100644 base/Get-RandomMacAddress.ps1 create mode 100644 docker/profile.d/env.ps1 diff --git a/base.linux/Get-Mount.ps1 b/base.linux/Get-Mount.ps1 new file mode 100644 index 0000000..e75496e --- /dev/null +++ b/base.linux/Get-Mount.ps1 @@ -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 = $_ + }) + } diff --git a/base/Edit-TextFile.ps1 b/base/Edit-TextFile.ps1 index 91adefb..65da834 100644 --- a/base/Edit-TextFile.ps1 +++ b/base/Edit-TextFile.ps1 @@ -23,11 +23,7 @@ if( $editor -match 'code(\.exe)?$' ) { } } -$local:arguments = $($Path | ForEach-Object { - if ($Path -match '\*|\?|~') { - Get-ChildItem -Path $_ | Select-Object -ExpandProperty FullName - } else { $_ } - } ) -join "' '" +$local:arguments = $Path | Get-Path | Join-String -Separator "' '" if( $Path ) { $arguments = "'$arguments'" } if( $PSCmdlet.ShouldProcess( "Edit ($editor): $arguments" ) ) { diff --git a/base/Get-Path.ps1 b/base/Get-Path.ps1 index 37d6cfe..d58f521 100644 --- a/base/Get-Path.ps1 +++ b/base/Get-Path.ps1 @@ -1,25 +1,38 @@ -[CmdletBinding()]param([string]$Path) +[CmdletBinding()]param( + [Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName,Position=0)] + [Alias("FullName")] + [string[]]$Path +) +process { -function Get-FullPath { - param([string]$Path) + function Get-FullPath { + param([string]$Path) - if([System.IO.Path]::IsPathRooted($Path)){ - [System.IO.Path]::GetFullPath($Path) - }else{ - [System.IO.Path]::GetFullPath((Join-Path $PWD $Path)) + if([System.IO.Path]::IsPathRooted($Path)){ + [System.IO.Path]::GetFullPath($Path) + }else{ + [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 { # get-item $Path -Force -ErrorAction Stop | # Select-Object -ExpandProperty FullName diff --git a/base/Get-RandomMacAddress.ps1 b/base/Get-RandomMacAddress.ps1 new file mode 100644 index 0000000..90ebae1 --- /dev/null +++ b/base/Get-RandomMacAddress.ps1 @@ -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 diff --git a/base/src/config.files.json b/base/src/config.files.json index b8b3ae6..1da83fb 100644 --- a/base/src/config.files.json +++ b/base/src/config.files.json @@ -1,56 +1,64 @@ { - "neovim": [ - "~/.config/nvim/init.vim", - "~/.config/nvim/vim-plug/plugins.vim", - "#vim", - "#vi" - ], - "vi": "~/.virc", - "zshrc": "~/.zshrc", - "shrc": "~/.shrc", - "sz-aliases-sh": "~/.sz.aliases.sh", - "sz-shrc": [ - "~/.sz.shrc.sh", - "#shrc", - "@shell-loading-snippets/bash", - "@shell-loading-snippets/sh" - ], - "sz-zshrc": [ - "~/.sz.zshrc.sh", - "#zshrc", - "@shell-loading-snippets/zsh" - ], - "sz-rc-all": [ - "#sz-aliases-sh", - "#sz-local-rc", - "#sz-shrc", - "#sz-zshrc", - "#zshrc" - ], - "sz-local-rc": "~/.sz.local.sh", - "ansible": [ - "/etc/ansible/ansible.cfg", - "/opt/ansible/ansible.cfg", - "/opt/ansible/hosts" - ], - "vim": [ - "~/.vimrc", - "~/.vim/vimrc" - ], - "nvim": [ - "~/.config/nvim/init.vim", - "~/.nvimrc", - "#vim" - ], - "tmux": [ - "~/.tmux.conf", - "~/.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" ] + "neovim": [ + "~/.config/nvim/init.vim", + "~/.config/nvim/vim-plug/plugins.vim", + "#vim", + "#vi" + ], + "vi": "~/.virc", + "zshrc": "~/.zshrc", + "shrc": "~/.shrc", + "sz-aliases-sh": "~/.sz.aliases.sh", + "sz-shrc": [ + "~/.sz.shrc.sh", + "#shrc", + "@shell-loading-snippets/bash", + "@shell-loading-snippets/sh" + ], + "sz-zshrc": [ + "~/.sz.zshrc.sh", + "#zshrc", + "@shell-loading-snippets/zsh" + ], + "sz-rc-all": [ + "#sz-aliases-sh", + "#sz-local-rc", + "#sz-shrc", + "#sz-zshrc", + "#zshrc" + ], + "sz-local-rc": "~/.sz.local.sh", + "ansible": [ + "/etc/ansible/ansible.cfg", + "/opt/ansible/ansible.cfg", + "/opt/ansible/hosts" + ], + "emacs": [ + "~/.emacs", + "~/.emacs.d" + ], + "spacemacs": [ + "~/.spacemacs", + "#emacs" + ], + "vim": [ + "~/.vimrc", + "~/.vim/vimrc" + ], + "nvim": [ + "~/.config/nvim/init.vim", + "~/.nvimrc", + "#vim" + ], + "tmux": [ + "~/.tmux.conf", + "~/.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" ] } diff --git a/docker/dcup.ps1 b/docker/dcup.ps1 index d9e93e7..591ffe7 100644 --- a/docker/dcup.ps1 +++ b/docker/dcup.ps1 @@ -15,7 +15,7 @@ [switch]$NoPull, [array]$PullParams, [array]$LogsParams, - [array]$UpParams=@('-d','--remove-orphans'), + [array]$UpParams=@('--detach','--remove-orphans'), [Parameter(Position = 0, ValueFromRemainingArguments = $true)] [array]$Containers ) @@ -44,6 +44,8 @@ if( -not $LogsParams[0] ) { $logsParams[0] += @("--tail=$tailLen") } +$local:moreParams = @() +#if( $ForceNoFollow ) { $moreParams = @('--no-color', '--quiet-pull') } $PullParams[0] = @('pull' ) + $PullParams[0] + $Containers if( $ForceNoFollow ) { $PullParams[0] = @('&') + $PullParams[0] } $UpParams[0] = @('up' ) + $UpParams[0] + $Containers diff --git a/docker/profile.d/env.ps1 b/docker/profile.d/env.ps1 new file mode 100644 index 0000000..32ebcc9 --- /dev/null +++ b/docker/profile.d/env.ps1 @@ -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