Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created April 8, 2025 15:58
Show Gist options
  • Save mklabs/6ac76c06d9eddcc4966ea16cbcf4cad1 to your computer and use it in GitHub Desktop.
Save mklabs/6ac76c06d9eddcc4966ea16cbcf4cad1 to your computer and use it in GitHub Desktop.
windows dotfiles powershell profile
# To put in ~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1
# ---
# Prompt
## Starship
# https://starship.rs
# https://github.com/starship/starship
Invoke-Expression (&starship init powershell)
Invoke-Expression -Command $(starship completions powershell | Out-String)
# https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory
function Invoke-Starship-PreCommand {
$loc = $executionContext.SessionState.Path.CurrentLocation;
$prompt = "$([char]27)]9;12$([char]7)"
if ($loc.Provider.Name -eq "FileSystem")
{
$prompt += "$([char]27)]9;9;`"$($loc.ProviderPath)`"$([char]27)\"
}
$host.ui.Write($prompt)
}
# Icons
# https://github.com/devblackops/Terminal-Icons
Import-Module Terminal-Icons
# PSReadLine
# https://github.com/PowerShell/PSReadLine
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
# Fzf
# https://github.com/junegunn/fzf
# https://github.com/kelleyma49/PSFzf
Import-Module PSFzf
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'
# Alias
Set-Alias vim nvim
Set-Alias g git
Set-Alias grep findstr
Set-Alias tig 'C:\Program Files\Git\usr\bin\tig.exe'
Set-Alias less 'C:\Program Files\Git\usr\bin\less.exe'
# Yazi
# https://github.com/sxyazi/yazi
function y {
$tmp = [System.IO.Path]::GetTempFileName()
yazi $args --cwd-file="$tmp"
$cwd = Get-Content -Path $tmp
if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) {
Set-Location -LiteralPath $cwd
}
Remove-Item -Path $tmp
}
# eza
# https://github.com/eza-community/eza
function lls {
eza -a --color=always --git @args
}
function ll {
#eza -a --color=always --long --git --no-filesize --icons=always --no-time --no-user --no-permissions @args
eza -a --color=always --long --git --icons=always @args
}
function lll {
eza -a --color=always --long --git @args
}
function tree {
eza -a -T --level=2 @args
}
Set-Alias ls lls
# nvim
# Few utilities to start nvim with a different NVIM_APPNAME
function nvc {
$env:NVIM_APPNAME = 'nvim.custom';
nvim @args
}
function nvk {
$env:NVIM_APPNAME = 'nvim.kickstart';
nvim @args
}
function nvl {
$env:NVIM_APPNAME = 'nvim.lazy';
nvim @args
}
function nva {
$env:NVIM_APPNAME = 'nvim.advent';
nvim @args
}
# Utilities
function which($command) {
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
# Completions
## Git
# https://github.com/dahlbyk/posh-git
Import-Module posh-git
## Deno
#. C:\Users\danie\Documents\PowerShell\deno.completions.ps1
## Chocolatey
# Import the Chocolatey Profile that contains the necessary code to enable
# tab-completions to function for `choco`.
# Be aware that if you are missing these lines from your profile, tab completion
# for `choco` will not function.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
## github cli
# https://cli.github.com/
# https://github.com/cli/cli
#Invoke-Expression -Command $(gh completion -s powershell | Out-String)
## Docker
# https://github.com/matt9ucci/DockerCompletion
Import-Module DockerCompletion
# ---- At the end ----
## Zoxide
# https://github.com/ajeetdsouza/zoxide
Invoke-Expression (& { (zoxide init powershell | Out-String) })
Set-Alias -Name cd -Value z -Option AllScope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment