Compare commits
8 Commits
b129a0e308
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| fc57d48814 | |||
| 5ec851fe11 | |||
| d219cd1479 | |||
| 75496f76cd | |||
| f61e0768d2 | |||
| cb09d8bb11 | |||
| 5abb4c4268 | |||
| e5a9f09709 |
5
alias.ps1
Normal file
5
alias.ps1
Normal file
@@ -0,0 +1,5 @@
|
||||
# Remove builtin aliases
|
||||
Remove-Item Alias:curl
|
||||
Remove-Item Alias:wget
|
||||
Remove-Item Alias:cd
|
||||
Remove-Item Alias:rm
|
||||
25
completion.ps1
Normal file
25
completion.ps1
Normal file
@@ -0,0 +1,25 @@
|
||||
# Enable Git completions & prompt.
|
||||
Import-Module Posh-Git
|
||||
$GitPromptSettings.EnableFileStatus = $false
|
||||
$GitPromptSettings.DefaultPromptPath = ""
|
||||
$GitPromptSettings.DefaultPromptPrefix.Text = ""
|
||||
$GitPromptSettings.DefaultPromptSuffix.Text = ""
|
||||
$GitPromptSettings.BeforeStatus = ""
|
||||
$GitPromptSettings.AfterStatus = ""
|
||||
# Enable Scoop completions.
|
||||
if (Get-Command scoop.ps1 -ErrorAction SilentlyContinue) {
|
||||
$ScoopCompletion = "$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\modules\scoop-completion"
|
||||
if (Test-Path $ScoopCompletion) {
|
||||
Import-Module $ScoopCompletion
|
||||
}
|
||||
}
|
||||
# Enable Chocolatey completions.
|
||||
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
||||
# Enable op completions.
|
||||
if (Test-Path "$env:LOCALAPPDATA\1Password\cli\opProfile.psm1") {
|
||||
Import-Module "$env:LOCALAPPDATA\1Password\cli\opProfile.psm1"
|
||||
}
|
||||
# Enable gh completions.
|
||||
if (Get-Command "gh" -ErrorAction SilentlyContinue) {
|
||||
Invoke-Expression -Command $(gh completion -s powershell | Out-String)
|
||||
}
|
||||
15
environment.ps1
Normal file
15
environment.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
# Set environment variables
|
||||
if (Get-Command nvim.exe -ErrorAction SilentlyContinue) {
|
||||
$Env:EDITOR = 'nvim.exe'
|
||||
}
|
||||
|
||||
# FIXME: These run to early since profile.ps1 loads before VS dev env setup.
|
||||
if (Get-Command cmake.exe -ErrorAction SilentlyContinue) {
|
||||
if (Get-Command ninja.exe -ErrorAction SilentlyContinue) {
|
||||
$Env:CMAKE_GENERATOR = 'Ninja'
|
||||
}
|
||||
if (Get-Command ccache.exe -ErrorAction SilentlyContinue) {
|
||||
$Env:CMAKE_C_COMPILER_LAUNCHER = 'ccache.exe'
|
||||
$Env:CMAKE_CXX_COMPILER_LAUNCHER = 'ccache.exe'
|
||||
}
|
||||
}
|
||||
26
install.ps1
Normal file
26
install.ps1
Normal file
@@ -0,0 +1,26 @@
|
||||
if (Get-Command scoop.ps1 -ErrorAction SilentlyContinue) {
|
||||
$ScoopCompletion = "$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\modules\scoop-completion"
|
||||
if (!(Test-Path $ScoopCompletion)) {
|
||||
scoop bucket add extras
|
||||
scoop install scoop-completion
|
||||
}
|
||||
}
|
||||
|
||||
if (!(Test-Path -PathType Container $env:LOCALAPPDATA\layouts)) {
|
||||
New-Item -ItemType Directory -Path $env:LOCALAPPDATA\layouts
|
||||
Write-Output "changed: created directory $env:LOCALAPPDATA\layouts"
|
||||
}
|
||||
|
||||
$layouts = (
|
||||
'window-wide-right.ps1',
|
||||
'window-wide-left.ps1'
|
||||
)
|
||||
|
||||
foreach ($layout in $layouts) {
|
||||
$source = "$env:USERPROFILE\Documents\WindowsPowerShell\layouts\$layout"
|
||||
$dest = "$env:LOCALAPPDATA\layouts\$layout"
|
||||
if (!(Test-Path -PathType Leaf $dest)) {
|
||||
New-Item -ItemType SymbolicLink -Path "$dest" -Target "$source"
|
||||
Write-Output "changed: created symlink $dest"
|
||||
}
|
||||
}
|
||||
11
layout.ps1
Normal file
11
layout.ps1
Normal file
@@ -0,0 +1,11 @@
|
||||
function layout {
|
||||
param (
|
||||
[parameter(mandatory=$true)]
|
||||
[string]$layoutName,
|
||||
[string]$tabName
|
||||
)
|
||||
& $env:LOCALAPPDATA\layouts\$layoutName.ps1
|
||||
if ($tabName -ne "") {
|
||||
wezterm.exe cli set-tab-title $tabName
|
||||
}
|
||||
}
|
||||
1
layouts/window-wide-left.ps1
Normal file
1
layouts/window-wide-left.ps1
Normal file
@@ -0,0 +1 @@
|
||||
wezterm.exe cli split-pane --horizontal --percent 43 --cwd (get-location).path
|
||||
1
layouts/window-wide-right.ps1
Normal file
1
layouts/window-wide-right.ps1
Normal file
@@ -0,0 +1 @@
|
||||
wezterm.exe cli split-pane --horizontal --percent 57 --cwd (get-location).path
|
||||
104
profile.ps1
104
profile.ps1
@@ -1,97 +1,15 @@
|
||||
# Enable Git completions & prompt.
|
||||
Import-Module Posh-Git
|
||||
$GitPromptSettings.EnableFileStatus = $false
|
||||
$GitPromptSettings.DefaultPromptPath = ""
|
||||
$GitPromptSettings.DefaultPromptPrefix.Text = ""
|
||||
$GitPromptSettings.DefaultPromptSuffix.Text = ""
|
||||
$GitPromptSettings.BeforeStatus = ""
|
||||
$GitPromptSettings.AfterStatus = ""
|
||||
# Enable Chocolatey completions.
|
||||
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
||||
# Enable op completions.
|
||||
if (Test-Path "$env:LOCALAPPDATA\1Password\cli\opProfile.psm1") {
|
||||
Import-Module "$env:LOCALAPPDATA\1Password\cli\opProfile.psm1"
|
||||
}
|
||||
# Enable gh completions.
|
||||
if (Get-Command "gh" -ErrorAction SilentlyContinue) {
|
||||
Invoke-Expression -Command $(gh completion -s powershell | Out-String)
|
||||
}
|
||||
|
||||
# Customize PowerShell prompt.
|
||||
function Prompt {
|
||||
$exitCode = $LastExitCode
|
||||
# Line one
|
||||
Get-Date -Format "HH:mm:ss " | Write-Host -ForegroundColor DarkGray -NoNewline
|
||||
$location = (Get-Location).Path
|
||||
if ($location.StartsWith($env:USERPROFILE)) {
|
||||
$location = $location.Replace($env:USERPROFILE, "~")
|
||||
}
|
||||
$location | Write-Host -ForegroundColor DarkCyan -NoNewline
|
||||
if ($exitCode -ne 0) {
|
||||
" $exitCode" | Write-Host -ForegroundColor DarkRed -NoNewline
|
||||
}
|
||||
& $GitPromptScriptBlock | Write-Host -NoNewline
|
||||
Write-Host
|
||||
# Line two
|
||||
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$principal = [Security.Principal.WindowsPrincipal] $identity
|
||||
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
$userName = $Env:USERNAME.ToLower()
|
||||
if($principal.IsInRole($adminRole)) {
|
||||
$userName | Write-Host -ForegroundColor DarkRed -NoNewline
|
||||
} else {
|
||||
$userName | Write-Host -ForegroundColor DarkGreen -NoNewline
|
||||
}
|
||||
return ' '
|
||||
}
|
||||
|
||||
# Set UTF-8 as the character set for pipes and output objects.
|
||||
# Set UTF-8 as the character set for pipes and output objects.
|
||||
# https://gist.github.com/xoner/4671514
|
||||
$OutputEncoding = New-Object -typename System.Text.UTF8Encoding
|
||||
[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8
|
||||
|
||||
# Enable Vi line editing mode.
|
||||
Set-PSReadLineOption -BellStyle None -EditMode Vi
|
||||
# Make C-w backward delete a word.
|
||||
Set-PSReadLineKeyHandler -Chord Ctrl+w -Function BackwardDeleteWord
|
||||
# Make C-[ escape insert mode.
|
||||
# https://github.com/PowerShell/PSReadLine/issues/906#issuecomment-916847040
|
||||
Set-PSReadLineKeyHandler -Chord 'Ctrl+Oem4' -Function ViCommandMode
|
||||
# Enable menu style tab completions. https://stackoverflow.com/a/37715242
|
||||
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
|
||||
|
||||
# Autosuggestion bindings for PSReadLine 2.1.0+
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+p" -Function ForwardChar
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+o" -Function ForwardWord
|
||||
# Use grey but not italic for autosuggestion highlights
|
||||
Set-PSReadLineOption -Colors @{ InlinePrediction = "$([char]0x1b)[38;5;238m" }
|
||||
|
||||
# Change cursor shape based on what Vi mode the line editor is in.
|
||||
# Tested and works with PowerShell 5.1
|
||||
# NOTE: Requires: Install-Module PsReadline -Scope CurrentUser -Force
|
||||
# TODO: This doesn't handle all cases well. For example when exiting terminal
|
||||
# nvim in a PowerShell session the cursor is a block while in insert mode.
|
||||
function OnViModeChange {
|
||||
if ($args[0] -eq 'Command') {
|
||||
# Set the cursor to non-blinking block.
|
||||
Write-Host -NoNewLine "$([char]0x1b)[2 q"
|
||||
} else {
|
||||
# Set the cursor to non-blinking line.
|
||||
Write-Host -NoNewLine "$([char]0x1b)[6 q"
|
||||
}
|
||||
}
|
||||
Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange
|
||||
# And set the cursor to a non-blinking line on profile load.
|
||||
Write-Host -NoNewLine "$([char]0x1b)[6 q"
|
||||
|
||||
# Remove these aliases to PowerShell builtins which clobber the actaul exes.
|
||||
Remove-Item alias:curl
|
||||
Remove-Item alias:wget
|
||||
|
||||
# Set environment variables
|
||||
# TODO: Wrap Enter-VsDevShell to also set these?
|
||||
if ((Get-Command cmake.exe -ErrorAction SilentlyContinue).Source) {
|
||||
$env:CMAKE_GENERATOR = 'Ninja'
|
||||
$env:CMAKE_C_COMPILER_LAUNCHER = 'cmake.exe'
|
||||
$env:CMAKE_CXX_COMPILER_LAUNCHER = 'cmake.exe'
|
||||
}
|
||||
# Load config from files
|
||||
. $PSScriptRoot\environment.ps1
|
||||
. $PSScriptRoot\completion.ps1
|
||||
. $PSScriptRoot\prompt.ps1
|
||||
. $PSScriptRoot\readline.ps1
|
||||
. $PSScriptRoot\alias.ps1
|
||||
. $PSScriptRoot\utils.ps1
|
||||
. $PSScriptRoot\layout.ps1
|
||||
# TODO: . $PSScriptRoot\build.ps1
|
||||
# TODO: . $PSScriptRoot\autoenv.ps1
|
||||
|
||||
27
prompt.ps1
Normal file
27
prompt.ps1
Normal file
@@ -0,0 +1,27 @@
|
||||
# Customize PowerShell prompt.
|
||||
function Prompt {
|
||||
$exitCode = $LastExitCode
|
||||
# Line one
|
||||
Get-Date -Format "HH:mm:ss " | Write-Host -ForegroundColor DarkGray -NoNewline
|
||||
$location = (Get-Location).Path
|
||||
if ($location.StartsWith($env:USERPROFILE)) {
|
||||
$location = $location.Replace($env:USERPROFILE, "~")
|
||||
}
|
||||
$location | Write-Host -ForegroundColor DarkCyan -NoNewline
|
||||
if ($exitCode -ne 0) {
|
||||
" $exitCode" | Write-Host -ForegroundColor DarkRed -NoNewline
|
||||
}
|
||||
& $GitPromptScriptBlock | Write-Host -NoNewline
|
||||
Write-Host
|
||||
# Line two
|
||||
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$principal = [Security.Principal.WindowsPrincipal] $identity
|
||||
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
$userName = $Env:USERNAME.ToLower()
|
||||
if($principal.IsInRole($adminRole)) {
|
||||
$userName | Write-Host -ForegroundColor DarkRed -NoNewline
|
||||
} else {
|
||||
$userName | Write-Host -ForegroundColor DarkGreen -NoNewline
|
||||
}
|
||||
return ' '
|
||||
}
|
||||
33
readline.ps1
Normal file
33
readline.ps1
Normal file
@@ -0,0 +1,33 @@
|
||||
# Enable Vi line editing mode.
|
||||
Set-PSReadLineOption -BellStyle None -EditMode Vi
|
||||
# Make C-w backward delete a word.
|
||||
Set-PSReadLineKeyHandler -Chord Ctrl+w -Function BackwardDeleteWord
|
||||
# Make C-[ escape insert mode.
|
||||
# https://github.com/PowerShell/PSReadLine/issues/906#issuecomment-916847040
|
||||
Set-PSReadLineKeyHandler -Chord 'Ctrl+Oem4' -Function ViCommandMode
|
||||
# Enable menu style tab completions. https://stackoverflow.com/a/37715242
|
||||
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
|
||||
|
||||
# Autosuggestion bindings for PSReadLine 2.1.0+
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+p" -Function ForwardChar
|
||||
Set-PSReadLineKeyHandler -Chord "Ctrl+o" -Function ForwardWord
|
||||
# Use grey but not italic for autosuggestion highlights
|
||||
Set-PSReadLineOption -Colors @{ InlinePrediction = "$([char]0x1b)[38;5;238m" }
|
||||
|
||||
# Change cursor shape based on what Vi mode the line editor is in.
|
||||
# Tested and works with PowerShell 5.1
|
||||
# NOTE: Requires: Install-Module PsReadline -Scope CurrentUser -Force
|
||||
# TODO: This doesn't handle all cases well. For example when exiting terminal
|
||||
# nvim in a PowerShell session the cursor is a block while in insert mode.
|
||||
function OnViModeChange {
|
||||
if ($args[0] -eq 'Command') {
|
||||
# Set the cursor to non-blinking block.
|
||||
Write-Host -NoNewLine "$([char]0x1b)[2 q"
|
||||
} else {
|
||||
# Set the cursor to non-blinking line.
|
||||
Write-Host -NoNewLine "$([char]0x1b)[6 q"
|
||||
}
|
||||
}
|
||||
Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange
|
||||
# And set the cursor to a non-blinking line on profile load.
|
||||
Write-Host -NoNewLine "$([char]0x1b)[6 q"
|
||||
47
utils.ps1
Normal file
47
utils.ps1
Normal file
@@ -0,0 +1,47 @@
|
||||
# Define cd to work more like Unix/Linux:
|
||||
# * No path argument changes to the users home directory
|
||||
# * Passing "-" for the path argument changes to the previous directory
|
||||
$Global:cdPreviousPath = Get-Location
|
||||
function cd {
|
||||
Param ([string]$Path)
|
||||
if ($Path -eq "") {
|
||||
$Path = "~"
|
||||
} elseif ($Path -eq "-") {
|
||||
$Path = $cdPreviousPath
|
||||
}
|
||||
$Global:cdPreviousPath = Get-Location
|
||||
Set-Location -Path $Path
|
||||
}
|
||||
|
||||
# Define rm to work like Unix/Linux
|
||||
# * Support -r and -f flags also -rf or -fr
|
||||
# * Support specifying multiple paths to remove
|
||||
function rm {
|
||||
Param (
|
||||
[Parameter(
|
||||
Mandatory=$true,
|
||||
ValueFromRemainingArguments=$true
|
||||
)][string[]]$Paths,
|
||||
[switch]$F, [switch]$Force,
|
||||
[switch]$R, [switch]$Recurse,
|
||||
[switch]$RF, [switch]$FR
|
||||
)
|
||||
$Command = "Remove-Item"
|
||||
if ($F -or $Force -or $RF -or $FR) {
|
||||
$Command = "$Command -Force"
|
||||
}
|
||||
if ($R -or $Recurse -or $RF -or $FR) {
|
||||
$Command = "$Command -Recurse"
|
||||
}
|
||||
foreach ($Path in $Paths) {
|
||||
Invoke-Expression -Command "$Command $Path"
|
||||
}
|
||||
}
|
||||
|
||||
# Define touch to create a new empty text file
|
||||
function touch {
|
||||
Param (
|
||||
[string]$Path
|
||||
)
|
||||
New-Item -Type File $Path
|
||||
}
|
||||
Reference in New Issue
Block a user