add global to all powershell functions

This commit is contained in:
matan h 2023-07-27 23:36:43 +03:00 committed by GitHub
parent 42e1d5dd3b
commit 8c70bd2dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -6,7 +6,7 @@
# #
# Call zoxide binary, returning the output as UTF-8. # Call zoxide binary, returning the output as UTF-8.
function __zoxide_bin { function global:__zoxide_bin {
$encoding = [Console]::OutputEncoding $encoding = [Console]::OutputEncoding
try { try {
[Console]::OutputEncoding = [System.Text.Utf8Encoding]::new() [Console]::OutputEncoding = [System.Text.Utf8Encoding]::new()
@ -18,7 +18,7 @@ function __zoxide_bin {
} }
# pwd based on zoxide's format. # pwd based on zoxide's format.
function __zoxide_pwd { function global:__zoxide_pwd {
$cwd = Get-Location $cwd = Get-Location
if ($cwd.Provider.Name -eq "FileSystem") { if ($cwd.Provider.Name -eq "FileSystem") {
$cwd.ProviderPath $cwd.ProviderPath
@ -26,7 +26,7 @@ function __zoxide_pwd {
} }
# cd + custom logic based on the value of _ZO_ECHO. # cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd($dir, $literal) { function global:__zoxide_cd($dir, $literal) {
$dir = if ($literal) { $dir = if ($literal) {
Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop
} else { } else {
@ -59,7 +59,7 @@ function __zoxide_cd($dir, $literal) {
-#} -#}
{%- if hook == InitHook::Prompt -%} {%- if hook == InitHook::Prompt -%}
# Hook to add new entries to the database. # Hook to add new entries to the database.
function __zoxide_hook { function global:__zoxide_hook {
$result = __zoxide_pwd $result = __zoxide_pwd
if ($null -ne $result) { if ($null -ne $result) {
zoxide add -- $result zoxide add -- $result
@ -68,7 +68,7 @@ function __zoxide_hook {
{%- else if hook == InitHook::Pwd -%} {%- else if hook == InitHook::Pwd -%}
# Hook to add new entries to the database. # Hook to add new entries to the database.
$global:__zoxide_oldpwd = __zoxide_pwd $global:__zoxide_oldpwd = __zoxide_pwd
function __zoxide_hook { function global:__zoxide_hook {
$result = __zoxide_pwd $result = __zoxide_pwd
if ($result -ne $global:__zoxide_oldpwd) { if ($result -ne $global:__zoxide_oldpwd) {
if ($null -ne $result) { if ($null -ne $result) {
@ -85,7 +85,7 @@ if ($__zoxide_hooked -ne 1) {
$__zoxide_hooked = 1 $__zoxide_hooked = 1
$__zoxide_prompt_old = $function:prompt $__zoxide_prompt_old = $function:prompt
function prompt { function global:prompt {
if ($null -ne $__zoxide_prompt_old) { if ($null -ne $__zoxide_prompt_old) {
& $__zoxide_prompt_old & $__zoxide_prompt_old
} }
@ -99,7 +99,7 @@ if ($__zoxide_hooked -ne 1) {
# #
# Jump to a directory using only keywords. # Jump to a directory using only keywords.
function __zoxide_z { function global:__zoxide_z {
if ($args.Length -eq 0) { if ($args.Length -eq 0) {
__zoxide_cd ~ $true __zoxide_cd ~ $true
} }
@ -124,7 +124,7 @@ function __zoxide_z {
} }
# Jump to a directory using interactive search. # Jump to a directory using interactive search.
function __zoxide_zi { function global:__zoxide_zi {
$result = __zoxide_bin query -i -- @args $result = __zoxide_bin query -i -- @args
if ($LASTEXITCODE -eq 0) { if ($LASTEXITCODE -eq 0) {
__zoxide_cd $result $true __zoxide_cd $result $true