From bd54ea3ea9f903ac762d2d9c8f0cf8a64643c0c2 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Wed, 15 Dec 2021 01:13:45 +0530 Subject: [PATCH] Ignore CRLF for shell scripts (#315) --- .gitattributes | 7 +++++-- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 2 ++ README.md | 7 +++++++ man/zoxide-init.1 | 2 +- templates/powershell.txt | 28 +++++++++++++++------------- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/.gitattributes b/.gitattributes index 83a0a0b..a9a91a2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ -contrib/completions/* linguist-generated=true -contrib/completions/README.md linguist-generated=false +/contrib/completions/* eol=lf linguist-generated=true text +/contrib/completions/README.md -eol -linguist-generated -text +/init.fish eol=lf text +/templates/*.txt eol=lf text +/zoxide.plugin.zsh eol=lf text diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4439cf..e966359 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: components: rustfmt, clippy profile: minimal override: true - - uses: cachix/install-nix-action@v12 + - uses: cachix/install-nix-action@v15 if: ${{ matrix.os != 'windows-latest' }} with: nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz diff --git a/CHANGELOG.md b/CHANGELOG.md index 2291008..5128e07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fzf: better default options. - Fish: interactive completions are only triggered when the last argument is empty. +- PowerShell: installation instructions. ### Fixed @@ -24,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Zsh: fix errors with `set -eu`. - Fzf: handle early selection. - PowerShell: correctly handle escape characters in paths. +- Parse error on Cygwin/MSYS due to CRLF line endings. ## [0.7.9] - 2021-11-02 diff --git a/README.md b/README.md index 1d3fcbc..eb9213c 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,13 @@ Add this to your configuration (find it by running `echo $profile` in PowerShell): ```powershell +# For zoxide v0.8.0+ +Invoke-Expression (& { + $hook = if ($PSVersionTable.PSVersion.Major -lt 6) { 'prompt' } else { 'pwd' } + (zoxide init --hook $hook powershell | Out-String) +}) + +# For older versions of zoxide Invoke-Expression (& { $hook = if ($PSVersionTable.PSVersion.Major -lt 6) { 'prompt' } else { 'pwd' } (zoxide init --hook $hook powershell) -join "`n" diff --git a/man/zoxide-init.1 b/man/zoxide-init.1 index 38748d9..69a3a9e 100644 --- a/man/zoxide-init.1 +++ b/man/zoxide-init.1 @@ -46,7 +46,7 @@ PowerShell): .nf \fBInvoke-Expression (& { $hook = if ($PSVersionTable.PSVersion.Major -lt 6) { 'prompt' } else { 'pwd' } - (zoxide init --hook $hook powershell) -join "`n" + (zoxide init --hook $hook powershell | Out-String) })\fR .fi .TP diff --git a/templates/powershell.txt b/templates/powershell.txt index fd02b80..4b7e51a 100644 --- a/templates/powershell.txt +++ b/templates/powershell.txt @@ -14,12 +14,14 @@ function __zoxide_pwd { } # cd + custom logic based on the value of _ZO_ECHO. -function __zoxide_cd($dir) { +function __zoxide_cd($dir, $literal) { + $dir = if ($literal) { + Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop + } else { + Set-Location -Path $dir -Passthru -ErrorAction Stop + } {%- if echo %} - $dir = Set-Location -LiteralPath $dir -Passthru -ErrorAction Stop Write-Output $dir.Path -{%- else %} - Set-Location -LiteralPath $dir -ErrorAction Stop {%- endif %} } @@ -72,13 +74,13 @@ if ($__zoxide_hooked -ne 1) { # Jump to a directory using only keywords. function __zoxide_z { if ($args.Length -eq 0) { - __zoxide_cd ~ + __zoxide_cd ~ $true } - elseif ($args.Length -eq 1 -and $args[0] -eq '-') { - __zoxide_cd - - } - elseif ($args.Length -eq 1 -and (Test-Path $args[0] -PathType Container)) { - __zoxide_cd $args[0] + elseif ( + $args.Length -eq 1 -and + (($args[0] -eq '-' -or $args[0] -eq '+') -or (Test-Path $args[0] -PathType Container)) + ) { + __zoxide_cd $args[0] $false } else { $result = __zoxide_pwd @@ -89,7 +91,7 @@ function __zoxide_z { $result = zoxide query -- @args } if ($LASTEXITCODE -eq 0) { - __zoxide_cd $result + __zoxide_cd $result $true } } } @@ -98,7 +100,7 @@ function __zoxide_z { function __zoxide_zi { $result = zoxide query -i -- @args if ($LASTEXITCODE -eq 0) { - __zoxide_cd $result + __zoxide_cd $result $true } } @@ -122,4 +124,4 @@ Set-Alias -Name {{cmd}}i -Value __zoxide_zi -Option AllScope -Scope Global -Forc # To initialize zoxide, add this to your configuration (find it by running # `echo $profile` in PowerShell): # -# Invoke-Expression (& { $hook = if ($PSVersionTable.PSVersion.Major -ge 6) { 'pwd' } else { 'prompt' } (zoxide init powershell --hook $hook) -join "`n" }) +# Invoke-Expression (& { $hook = if ($PSVersionTable.PSVersion.Major -ge 6) { 'pwd' } else { 'prompt' } (zoxide init powershell --hook $hook | Out-String) })