add: powershell profile

This commit is contained in:
juancwu 2023-01-17 15:59:13 -05:00
commit 52c6ceb3ab
No known key found for this signature in database

View file

@ -10,58 +10,80 @@ Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineOption -BellStyle None Set-PSReadLineOption -BellStyle None
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadLineOption -PredictionSource History Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView # Set-PSReadLineOption -PredictionViewStyle ListView
# Fzf # Fzf
Import-Module PSFzf Import-Module PSFzf
# Simulate the peco change directory functionality from mac/linux setups # Simulate the peco change directory functionality from mac/linux setups
function Fuzzy-Find { # function Fuzzy-Find {
param( # param(
[boolean]$file = $false, # [boolean]$file = $false,
[boolean]$a = $false, # shows only current working directory # [boolean]$a = $false, # shows only current working directory
[int]$depth = 2 # [int]$depth = 1
) # )
#
$ghq = "$env:USERPROFILE\ghq" # $ghq = "$env:USERPROFILE\ghq"
$app_data = "$env:USERPROFILE\AppData\Local" # $app_data = "$env:USERPROFILE\AppData\Local"
$cwd_ = (Get-Location).Path # $cwd = (Get-Location).Path
#
# if ($file) {
if ($file) { # if (!$a) {
if (!$a) { # $items = Get-ChildItem $cwd -Recurse -Attributes !Directory -Depth $depth
$items = Get-ChildItem $cwd_ -Recurse -Attributes !Directory -Depth $depth # } else {
} else { # $f1 = Get-ChildItem $cwd, $app_data -Recurse -Attributes !Directory -Depth $depth
$f1 = Get-ChildItem $cwd_, $app_data -Recurse -Attributes !Directory -Depth $depth # $f2 = Get-ChildItem $ghq -Recurse -Attributes !Directory -Depth 3
$f2 = Get-ChildItem $ghq -Recurse -Attributes !Directory -Depth 3 # $items = @($f1 ; $f2)
$items = @($f1 ; $f2) # }
} # } else {
} else { # if (!$a) {
if (!$a) { # $items = Get-ChildItem $cwd -Recurse -Attributes Directory -Depth $depth
$items = Get-ChildItem $cwd_ -Recurse -Attributes Directory -Depth $depth # } else {
} else { # $dir1 = Get-ChildItem $cwd, $app_data -Recurse -Attributes Directory -Depth $depth
$dir1 = Get-ChildItem $cwd_, $app_data -Recurse -Attributes Directory -Depth $depth # $dir2 = Get-ChildItem $ghq -Recurse -Attributes Directory -Depth 3
$dir2 = Get-ChildItem $ghq -Recurse -Attributes Directory -Depth 3 # $items = @($dir1 ; $dir2)
$items = @($dir1 ; $dir2) # }
} # }
} #
# $selected = $items | Invoke-Fzf
# if ($selected -ne $null) {
# if ($file) {
# vim $selected
# } else {
# Set-Location $selected
# }
# }
# }
# search file in current directory
function sf([int]$d=0) {
# Fuzzy-Find -file $true -a $a -depth $d
# This function should act like telescope inside nvim
# Include files and directoies at the surface level (include hidden)
$items = Get-ChildItem (Get-Location).Path -Attributes Directory,!Directory,Hidden -Depth $d
$selected = $items | Invoke-Fzf $selected = $items | Invoke-Fzf
if ($selected -ne $null) { if ($selected -ne $null) {
if ($file) { if (Test-Path $selected -PathType Leaf) {
# file so we open for edit
vim $selected vim $selected
} else { } else {
# directory so we navigate to it
Set-Location $selected Set-Location $selected
} }
} }
} }
# Alias to run the peco-like function # Opens the directories that I often go to
function sf([switch]$a, [int]$d=2) { # Fast Forward
Fuzzy-Find -file $true -a $a -depth $d function ff() {
$ghq = Get-ChildItem $env:USERPROFILE\ghq -Attributes Directory -Depth 1
$app_data = Get-ChildItem $env:USERPROFILE\AppData -Attributes Directory
$unity_projects = Get-ChildItem "E:\Unity Projects" -Attributes Directory
$directories = @($ghq ; $app_data ; $unity_projects)
$selected = $directories | Invoke-Fzf
if ($selected -ne $null) {
Set-Location $selected
} }
function sd([switch]$a, [int]$d=2) {
Fuzzy-Find -file $false -a $a -depth $d
} }