]> apps.delaporte.us Git - dotfiles.git/blob - files/Microsoft.PowerShell_profile.ps1
WIP luanti backups
[dotfiles.git] / files / Microsoft.PowerShell_profile.ps1
1 $env:src = "$HOME\src"
2 $env:dotfiles = Join-Path $HOME "dotfiles"
3 $env:journal = Join-Path $HOME "Journal"
4 $env:nvim = Join-Path $HOME "\AppData\Local\nvim"
5
6 if($IsWindows) {
7 $env:journal = Join-Path $HOME "Box\Journal"
8 $env:nvim = Join-Path $HOME "\AppData\Local\nvim"
9 }
10
11
12 Import-Module $env:dotfiles\psmodules\add_to_profile.psm1
13 Add-ToProfile $env:dotfiles\files\paths.ps1
14 Add-ToProfile $env:dotfiles\files\env.ps1
15
16 # Delay loading PoshGit for speed.
17 function Enable-PoshGit {
18 Import-Module posh-git
19 }
20 New-Alias pg Enable-PoshGit
21
22 Set-Alias code codium # Prefer Codium
23
24 # Dashboard
25 New-Alias dash Show-MyDashboard # from dash.psm1
26 New-Alias today Get-JournalAgenda
27 function journal {
28 param(
29 [ValidateSet('limited','shared','journal', 'dotfiles', 'nvim')]
30 [string]$key,
31 [switch]$limited = $false,
32 [switch]$shared = $false,
33 [switch]$dotfiles = $false
34 )
35 $path = $journal
36 switch($key){
37 'limited' { $path = "$HOME\Box\SecDevLimited" }
38 'shared' { $path = "$HOME\Box\Privacy & Cybersecurity\Cybersecurity Development" }
39 'journal' { $path = "$HOME\Box\Journal" }
40 'dotfiles' { $path = $env:dotfiles }
41 'nvim' { $path = $env:nvim }
42 }
43 cd $path; nvim $path
44 }
45
46 function dotfiles {
47 nvim "$HOME\dotfiles"
48 }
49
50 function open {
51 param (
52 [string]$searchText
53 )
54 $directories = @(
55 "$HOME\Box\Journal",
56 "$HOME\Box\SecDevLimited",
57 "$HOME\Box\Privacy & Cybersecurity\Cybersecurity Development"
58 )
59
60 $totalFiles = 0
61 $processedFiles = 0
62
63 foreach ($directory in $directories) {
64 if (Test-Path $directory) {
65 $totalFiles += (Get-ChildItem -Path $directory -Recurse -File).Count
66 } else {
67 Write-Host "Directory '$directory' does not exist."
68 }
69 }
70
71 $resultFiles = @()
72 $textFileExtensions = @(".txt", ".log", ".csv", ".json", ".xml", ".md")
73 foreach ($directory in $directories) {
74 Get-ChildItem -Path $directory -Recurse -File | Where-Object { $textFileExtensions -contains $_.Extension } | ForEach-Object {
75 $fileContent = Get-Content -Path $_.FullName -Raw
76
77 if ($fileContent -match $searchText) {
78 $resultFiles += $_.FullName
79 }
80 $processedFiles++
81 Write-Progress -Activity "Searching Files" -Status "$processedFiles / $totalFiles files processed" -PercentComplete (($processedFiles / $totalFiles) * 100)
82 }
83 }
84 nvim $resultFiles
85 }
86
87
88 # Vi
89 New-Alias vi nvim
90 New-Alias vim nvim
91
92 # You can pry my unix commands out of my cold dead fingers
93 if($iswindows) {
94 Set-Alias which get-command
95 }
96 # Reject Windows heritage, act like Vi
97 # Set-PSReadlineOption -HistorySavePath $env:src\PSHistory.log
98 Set-PSReadlineOption -BellStyle Visual
99 Set-PSReadlineOption -ViModeIndicator Prompt
100 Set-PSReadlineOption -EditMode Vi
101
102 Write-Host "+ Type 'pg' to enable PoshGit"
103 Write-Host 'See $env:realProfile for version controlled profile file.'
104
105 # Load dotfiles modules
106 $env:psmodules = "$env:dotfiles\psmodules"
107 Import-Module "$env:psmodules\dash.psm1"
108 Import-Module $env:psmodules\file_management.psm1
109 Import-Module "$env:psmodules\fix_vpn.psm1"
110
111 $maybe_mods = @(
112 "$env:src\travel-times\travel-times.psm1",
113 "$env:src\powershell-scripts\modules\AgileGitHubCLI.psm1"
114 )
115 $maybe_mods | ForEach-Object {
116 if(Test-Path $_) {
117 Import-Module $_
118 } else {
119 Write-Host "Not found: $_"
120 }
121 }
122
123 $env:nvim_config = "$HOME\AppData\Local\nvim"
124
125 # Load local source modules
126 # Import-Module $env:src\powershell-scripts\modules\MarkdownGitHub.psm1
127
128 # Let's face it, I'm about to cd into my source directory
129 if((Get-Location).Path -eq $HOME){ cd $env:src }