From c0131deba46a7f4a4eee6f5419b767365a11fbf3 Mon Sep 17 00:00:00 2001 From: Gal on Sygin Date: Thu, 3 Feb 2022 19:08:16 -0500 Subject: [PATCH] Introduction of BitWarden package + prep + BitWarden module for easy autologon (not very secure but convinent on personal machines) - Will think this over some more afterwards * Get-Path will always return without trailing directory separator (might want to make this 'always' for dirs, but unsure yet) + Added Edit-MountUnit scaffolding for later modifying it to import a template on new mount units, and easy edit of systemd mount and automount units. --- BitWarden/_.package.json | 19 +++++++++++++++++++ BitWarden/profile.d/env.ps1 | 10 ++++++++++ BitWarden/src/modules.json | 6 ++++++ base.linux/Edit-MountUnit.ps1 | 6 +++++- base.linux/Update-OSz.ps1 | 8 ++++++-- base.linux/profile.d/env.ps1 | 16 +++++++++++++++- base/Get-Path.ps1 | 20 +++----------------- 7 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 BitWarden/_.package.json create mode 100644 BitWarden/profile.d/env.ps1 create mode 100644 BitWarden/src/modules.json diff --git a/BitWarden/_.package.json b/BitWarden/_.package.json new file mode 100644 index 0000000..ccb690e --- /dev/null +++ b/BitWarden/_.package.json @@ -0,0 +1,19 @@ +{ + "package": { + "Name": "BitWarden", + "Condition": [ + { + "custom": null, + "System": null, + "Hostname": null, + "Username": null, + "CmdletExists": null, + "ModuleExists": null, + "AppExeExists": [ + "bw" + ], + "Logic": 0 + } + ] + } +} diff --git a/BitWarden/profile.d/env.ps1 b/BitWarden/profile.d/env.ps1 new file mode 100644 index 0000000..8b8eb9b --- /dev/null +++ b/BitWarden/profile.d/env.ps1 @@ -0,0 +1,10 @@ +if( -not (Test-Path env:BITWARDEN_CLI_PATH) ) { + $env:BITWARDEN_CLI_PATH = Get-Command bw -Type Application | Select-Object -First 1 -ExpandProperty Source +} + +$local:bwPath = Join-Path $HOME 'tmp' +$null = New-Item -ItemType Directory -Path $bwPath -Force +$bwPath = Join-Path $bwPath 'git-credential-bw.key' +if( Test-Path $bwPath ) { + $env:BW_SESSION= Get-Content $bwPath +} \ No newline at end of file diff --git a/BitWarden/src/modules.json b/BitWarden/src/modules.json new file mode 100644 index 0000000..ce3be90 --- /dev/null +++ b/BitWarden/src/modules.json @@ -0,0 +1,6 @@ +{ + "Always": [ + "BitwardenWrapper" + ] +} + diff --git a/base.linux/Edit-MountUnit.ps1 b/base.linux/Edit-MountUnit.ps1 index b9f8d69..2ee1430 100644 --- a/base.linux/Edit-MountUnit.ps1 +++ b/base.linux/Edit-MountUnit.ps1 @@ -5,6 +5,10 @@ $local:pathChar = [IO.Path]::DirectorySeparatorChar $MountPath = Get-Path $MountPath -$local:MountName = $MountPath -replace '-','\\x2d' -replace $pathChar,'-' -replace '^-','' -replace '-^','' +$local:MountName = $($($( + $MountPath -replace '-','\\x2d' + ).Replace( $pathChar, '-' ) + ) -replace '^-','' +) $MountName diff --git a/base.linux/Update-OSz.ps1 b/base.linux/Update-OSz.ps1 index a82dfcc..8a8df0a 100644 --- a/base.linux/Update-OSz.ps1 +++ b/base.linux/Update-OSz.ps1 @@ -5,6 +5,10 @@ param( $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 } + 'arch' { + Update-ArchOSz -Mode:$Mode $args + } + {$_ -in 'debian','ubuntu','zorin'} { + Update-UbuntuOSz -Mode:$Mode $args + } } diff --git a/base.linux/profile.d/env.ps1 b/base.linux/profile.d/env.ps1 index 4e3e64d..8fcd40d 100644 --- a/base.linux/profile.d/env.ps1 +++ b/base.linux/profile.d/env.ps1 @@ -6,4 +6,18 @@ if( -not (Test-Path env:XDG_DATA_HOME) ) { } if( -not (Test-Path env:XDG_CONFIG_HOME) ) { $env:XDG_CONFIG_HOME="$HOME/.config" -} \ No newline at end of file +} + +if( -not ( + Test-Path env:SHELL_PARENT + ) -and -not ( + $env:SHELL -match 'p(wsh|owershell)$' + ) -and ( + Test-Path env:SHELL + ) +) { + $env:COMPLETION_SHELL_PREFERENCE = $env:SHELL + $env:SHELL_PARENT = $env:SHELL +} +$env:SHELL = Get-Process -Id $PID | Select-Object -ExpandProperty Path +Set-UnixCompleter -Shell $env:COMPLETION_SHELL_PREFERENCE \ No newline at end of file diff --git a/base/Get-Path.ps1 b/base/Get-Path.ps1 index c07385e..b12326b 100644 --- a/base/Get-Path.ps1 +++ b/base/Get-Path.ps1 @@ -5,17 +5,6 @@ [string[]]$Path ) process { - - 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)) - } - } - foreach( $local:p in $Path ) { switch( $p[0] ) { '@' { $p = Join-Path $MyPSScriptRoot $p.Substring(1) } @@ -27,6 +16,9 @@ process { } } + # clean end of path from DirectorySeparatorChars + $p = $p -replace '[/\\]+$','' + $p = $p -replace '#C-','#C-#' -replace '\*','#C-A#' -replace '\?','#C-Q#' if([System.IO.Path]::IsPathRooted($p)){ $p = [System.IO.Path]::GetFullPath($p) @@ -44,9 +36,3 @@ process { $p } } -# try { -# get-item $Path -Force -ErrorAction Stop | -# Select-Object -ExpandProperty FullName -# } catch { -# $_.targetObject -# }