aboutsummaryrefslogtreecommitdiff
path: root/powershell
diff options
context:
space:
mode:
authorclaw0ry <me@claw0ry.net>2024-12-11 13:58:21 +0100
committerclaw0ry <me@claw0ry.net>2024-12-11 13:58:21 +0100
commitb56b0d3ca316395a903ed1c7a040bda0ae321c36 (patch)
treeda8a7e975f0f426095350403dc3b39f4fd1ad5dd /powershell
fresh start
Diffstat (limited to 'powershell')
-rw-r--r--powershell/Microsoft.PowerShell_profile.ps1115
1 files changed, 115 insertions, 0 deletions
diff --git a/powershell/Microsoft.PowerShell_profile.ps1 b/powershell/Microsoft.PowerShell_profile.ps1
new file mode 100644
index 0000000..2545417
--- /dev/null
+++ b/powershell/Microsoft.PowerShell_profile.ps1
@@ -0,0 +1,115 @@
+# -----------------------------------------------------------------------------
+# - MODULES -
+# -----------------------------------------------------------------------------
+
+Import-Module -Name PSFzf
+Import-Module -Name posh-git
+
+if ($IsWindows) {
+ $env:XDG_CONFIG_HOME = "$env:USERPROFILE/.config"
+ if (-not(Test-Path -Path $env:XDG_CONFIG_HOME -PathType Container)) {
+ New-Item -Path $env:XDG_CONFIG_HOME -ItemType Directory
+ }
+} else {
+ $env:XDG_CONFIG_HOME = "$env:HOME/.config"
+}
+
+# -----------------------------------------------------------------------------
+# - PROMPT -
+# -----------------------------------------------------------------------------
+
+oh-my-posh init pwsh --config "$env:XDG_CONFIG_HOME/oh-my-posh/config.yml" | Invoke-Expression
+
+# -----------------------------------------------------------------------------
+# - ENVIRONMENT VARIABLES -
+# -----------------------------------------------------------------------------
+
+$env:PATH += ":$env:HOME/go/bin"
+$env:EDITOR = "nvim"
+$env:VISUAL = "nvim"
+
+# -----------------------------------------------------------------------------
+# - CUSTOM FUNCTIONS -
+# -----------------------------------------------------------------------------
+
+function New-Note {
+ param(
+ [Parameter()]
+ [string] $Name = "{0}.md" -f (New-Guid)
+ )
+
+ $path = Join-Path $env:HOME "notes" $Name
+
+ "$env:EDITOR $path" | Invoke-Expression
+}
+
+function Open-Note {
+ param(
+ [Parameter()]
+ [string] $Name = ""
+ )
+
+ $notesPath = Join-Path $env:HOME "notes"
+ $path = Join-Path $notesPath $Name
+
+ if (Test-Path $path) {
+ "$env:EDITOR $path" | Invoke-Expression
+ } else {
+ "$env:EDITOR $notesPath" | Invoke-Expression
+ }
+}
+
+# -----------------------------------------------------------------------------
+# - PSREADLINE CONFIGURATIONS -
+# -----------------------------------------------------------------------------
+
+Set-PSReadLineOption -PredictionSource History
+Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord
+Set-PSReadLineKeyHandler -Chord "Alt+RightArrow" -Function ForwardWord
+Set-PSReadLineKeyHandler -Chord "Alt+LeftArrow" -Function BackwardWord
+Set-PSReadLineKeyHandler -Chord "Alt+LeftArrow" -Function BackwardWord
+Set-PSReadLineKeyHandler -Chord "Ctrl+Backspace" -Function DeleteWord
+
+Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'
+
+# --- Hide sensitive information from history
+Set-PSReadLineOption -AddToHistoryHandler {
+ param(
+ [string]$line
+ )
+ $sensitive = "password|asplaintext|token|secret"
+ return ($line -notmatch $sensitive)
+}
+
+Set-PSReadLineOption -Colors @{ Member = "`e[95m"; Number = "`e[95m" }
+Set-PSReadLineOption -Colors @{
+ Member = "`e[95m"
+ Parameter = "`e[97m"
+ Number = "`e[97m"
+}
+
+# -----------------------------------------------------------------------------
+# - ALIASES -
+# -----------------------------------------------------------------------------
+function ListFilesAndFolders { param([string]$path = ".") Get-ChildItem -Path $path }
+Set-Alias -Name ll -Value ListFilesAndFolders
+
+function ListAllFilesAndFolders { param([string]$path = ".") Get-ChildItem -Path $path -Force }
+Set-Alias -Name la -Value ListAllFilesAndFolders
+
+function ListAllFilesAndFoldersSorted { param([string]$path = ".") Get-ChildItem -Path $path -Force | Sort-Object LastWriteTime }
+Set-Alias -Name lss -Value ListAllFilesAndFoldersSorted
+
+function GitCommitAlias { git commit -m $args[0] }
+Set-Alias -Name gcmm -Value GitCommitAlias
+
+function GitStatusAll { git status -uall }
+Set-Alias -Name gsa -Value GitStatusAll
+
+function GitCommitPatch { git commit -p }
+Set-Alias -Name gcp -Value GitCommitPatch
+
+function GitAddPatch { git add -p $args }
+Set-Alias -Name gap -Value GitAddPatch
+
+Set-Alias -Name vim -Value nvim