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