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