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