Skip to content

Commit 2a83724

Browse files
committedJan 2, 2022
feat: create/edit modules options prompt and helpers
1 parent 6b0bf46 commit 2a83724

File tree

4 files changed

+72
-40
lines changed

4 files changed

+72
-40
lines changed
 

‎Profile/functions/Module-Helpers.ps1

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# --------
2+
# Helpers
3+
# --------
4+
5+
Function Backup-Modules {
6+
$modpath = ($env:PSModulePath -split ";")[0]
7+
$ymlpath = "$modpath\modules.yml"
8+
$jsonpath = "$modpath\modules.json"
9+
$mods = (Get-ChildItem $modpath -Directory).Name
10+
If (!(Get-Module -Name powershell-yaml -ErrorAction SilentlyContinue)) {
11+
ConvertTo-Json $mods > $jsonpath
12+
} else {
13+
ConvertTo-Yaml -Data $mods -OutFile $ymlpath -Force
14+
}
15+
16+
}
17+
18+
Function Sync-Modules {
19+
$psdir = (Split-Path -Parent $profile)
20+
Set-Location $psdir
21+
git pull
22+
git add PowerShell/Modules/**
23+
git commit -m "config: Updated modules configurations"
24+
git-cliff -o "$HOME\Documents\CHANGELOG.md"
25+
git add CHANGELOG.md
26+
git commit -m "doc: update CHANGELOG.md for added modules"
27+
git push
28+
}
29+
30+
Function Restore-Modules {
31+
$mods = Get-Content ~/.dotfiles/powershell/modules.json | ConvertFrom-Json
32+
33+
foreach ($mod in $mods) {
34+
Write-Host "Installing PowerShell Module for Current User: $mod" -ForegroundColor Yellow
35+
Install-Module $mod -Scope CurrentUser -Force
36+
}
37+
}

‎Profile/modules.ps1

+6-40
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,15 @@
22
# Modules and Helper Functions
33
# -----------------------------
44

5+
# Required PSReadLine Beta Version
6+
If (!(!((Get-Module -Name PSReadLine).Version.Major -ge 2)) -and (!(Get-Module -Name PSReadLine).Version.Minor -ge 2)) {
7+
Install-Module -Name PSReadLine -AllowPrerelease -Force -AllowClobber -Scope CurrentUser
8+
}
9+
10+
Import-Module -Name PSReadLine
511
Import-Module -Name posh-git
612
Import-Module -Name oh-my-posh
713
Import-Module -Name Terminal-Icons
8-
Import-Module -Name PSReadLine
914

1015
# Enable Posh-Git
1116
$env:POSH_GIT_ENABLED = $true
12-
13-
# --------
14-
# Helpers
15-
# --------
16-
17-
Function Backup-Modules {
18-
$modpath = ($env:PSModulePath -split ";")[0]
19-
$ymlpath = "$modpath\modules.yml"
20-
$jsonpath = "$modpath\modules.json"
21-
$mods = (Get-ChildItem $modpath -Directory).Name
22-
If (!(Get-Module -Name powershell-yaml -ErrorAction SilentlyContinue)) {
23-
ConvertTo-Json $mods > $jsonpath
24-
} else {
25-
ConvertTo-Yaml -Data $mods -OutFile $ymlpath -Force
26-
}
27-
28-
}
29-
30-
Function Sync-Modules {
31-
$psdir = (Split-Path -Parent $profile)
32-
Set-Location $psdir
33-
git pull
34-
git add PowerShell/Modules/**
35-
git commit -m "config: Updated modules configurations"
36-
git-cliff -o "$HOME\Documents\CHANGELOG.md"
37-
git add CHANGELOG.md
38-
git commit -m "doc: update CHANGELOG.md for added modules"
39-
git push
40-
}
41-
42-
Function Restore-Modules {
43-
$mods = Get-Content ~/.dotfiles/powershell/modules.json | ConvertFrom-Json
44-
45-
foreach ($mod in $mods) {
46-
Write-Host "Installing PowerShell Module for Current User: $mod" -ForegroundColor Yellow
47-
Install-Module $mod -Scope CurrentUser -Force
48-
}
49-
}
50-

‎Profile/options.ps1

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Trust PSGallery
2+
$galleryinfo = Get-PSRepository | Where-Object { $_.Name -eq "PSGallery" }
3+
if (-not($galleryinfo.InstallationPolicy.Equals("Trusted"))) { Set-PSRepository -Name PSGallery -InstallationPolicy Trusted }
4+
5+
# Default Parameters
6+
$PSDefaultParameterValues = @{
7+
"Update-Module:Confirm"=$False;
8+
"Update-Module:Force"=$True;
9+
"Update-Module:Scope"="CurrentUser";
10+
"Update-Module:ErrorAction"="SilentlyContinue";
11+
"Update-Help:Force"=$True;
12+
"Update-Help:ErrorAction"="SilentlyContinue"
13+
}
14+
15+
# Set PSReadLineOptions's (Beta Version Required):
16+
Set-PSReadLineOption -PredictionSource History -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
17+
Set-PSReadLineOption -PredictionViewStyle ListView -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
18+
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
19+
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
20+
Set-PSReadlineOption -EditMode Windows

‎Profile/prompt.ps1

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Prompt
2+
Set-PoshPrompt -Theme wopian -ErrorAction SilentlyContinue
3+
4+
# Write Current Version and Execution Policy Details:
5+
Write-Host "PowerShell Version: $($psversiontable.psversion) - ExecutionPolicy: $(Get-ExecutionPolicy)" -ForegroundColor yellow
6+
7+
# ZLocation must be after all prompt changes:
8+
Import-Module ZLocation
9+
Write-Host -Foreground Green "`n[ZLocation] knows about $((Get-ZLocation).Keys.Count) locations.`n"

0 commit comments

Comments
 (0)
Please sign in to comment.