diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 75a9b5d..5f40fc5 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -44,7 +44,7 @@ jobs: id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - name: Upload binaries to release - uses: svenstaro/upload-release-action@v1-release + uses: alexis-opolka/upload-release-action with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: target/tar/navi.${{ steps.build.outputs.EXTENSION }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e2f261..5bc3566 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,10 @@ # for simplicity we are compiling and testing everything on the Ubuntu environment only. # For multi-OS testing see the `cross.yml` workflow. -on: [push] +on: + push: + pull_request: + branches: [master] name: CI diff --git a/docs/widgets/howto/VIM.md b/docs/widgets/howto/VIM.md index 97c75d0..70af1c9 100644 --- a/docs/widgets/howto/VIM.md +++ b/docs/widgets/howto/VIM.md @@ -1,13 +1,13 @@ -## vim - -If you want syntax highlighting support for Navi in Vim, add those syntax rules -to your syntax files such as at `$VIMRUNTIME/syntax/navi.vim`. -The rules are defined based on the [Cheatsheet syntax](cheatsheet_syntax.md). - -```vim -syntax match Comment "\v^;.*$" -syntax match Statement "\v^\%.*$" -syntax match Operator "\v^\#.*$" -syntax match String "\v\<.*\>" -syntax match String "\v^\$.*$" -``` +## vim + +If you want syntax highlighting support for Navi in Vim, add those syntax rules +to your syntax files such as at `$VIMRUNTIME/syntax/navi.vim`. +The rules are defined based on the [Cheatsheet syntax](cheatsheet_syntax.md). + +```vim +syntax match Comment "\v^;.*$" +syntax match Statement "\v^\%.*$" +syntax match Operator "\v^\#.*$" +syntax match String "\v\<.{-}\>" +syntax match String "\v^\$.*$" +``` diff --git a/shell/navi.plugin.ps1 b/shell/navi.plugin.ps1 index 0cf73da..f31d74a 100644 --- a/shell/navi.plugin.ps1 +++ b/shell/navi.plugin.ps1 @@ -1,60 +1,55 @@ -### This script installs the Powershell module under the user's Powershell modules path -### For modifications of the Powershell Navi plugin, see /shell/navi.plugin/navi.plugin.psm1. - -param ( - ### Controls if we update the current module (otherwise we don't rewrite the already existing module, if present) - [Switch]$Update, - ### Should the verbosity be enabled? - [Switch]$Verbose -) -function InstallNaviWidgetModule(){ - [String]$PwshModulePath = $env:PSModulePath.Split(";")[0]; - [String]$NAVI_PLUGIN = "navi.plugin"; +$null = New-Module { - Write-Debug "Are we updating the PowerShell module: $Update" - Write-Debug "Current Root Powershell Module path is: $PwshModulePath" + function Invoke-Navi { + $startArgs = @{ + FileName = "navi"; + Arguments = $args; + RedirectStandardOutput = $true; + WorkingDirectory = $PWD; + UseShellExecute = $false; + } + $p = [System.Diagnostics.Process]@{StartInfo = $startArgs} - ### If we're updating the module, Copy the newly updated contents to the currently installed module - ### then quit with a successful exit code. - ### We're not supposed to update the shortcut binding. - if ($Update){ - Write-Debug "Updating Navi-Widget PowerShell module" - Copy-Item -Path .\navi.plugin\ -Destination $PwshModulePath -Force -Recurse - exit 0 + [void]$p.Start() + $result = $p.StandardOutput.ReadToEnd() + $p.WaitForExit() + + $result } - ### If we're not updating, check if we don't have the module already installed - if (-Not (Test-Path -Path $PwshModulePath\$NAVI_PLUGIN)) { - Write-Debug "Copying Item to the path" - Copy-Item -Path .\navi.plugin\ -Destination $PwshModulePath -Recurse - } else { - Write-Error "Navi-Widget is already installed for PowerShell!" - exit 1 + + ### Initial code from @lurebat (https://github.com/lurebat/) + ### See #570 (https://github.com/denisidoro/navi/issues/570) for its original contribution + function Invoke-NaviWidget { + $ast = $tokens = $errors = $cursor = $null + [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $ast, [ref] $tokens, [ref] $errors, [ref] $cursor) + + $line = $ast.ToString().Trim() + $output = $null + + if ([String]::IsNullOrEmpty($line)) { + $output = (Invoke-Navi "--print" | Out-String).Trim() + } + else { + $best_match = (Invoke-Navi "--print --best-match --query `"$line`"" | Out-String).Trim() + if ([String]::IsNullOrEmpty($best_match)) { + $output = (Invoke-Navi "--print --query `"$line`"" | Out-String).Trim() + } + else { + $output = $best_match + } + } + + [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt() + + ### Handling the case when the user escapes without selecting any entry + if (-Not([String]::IsNullOrEmpty($output))) { + [Microsoft.PowerShell.PSConsoleReadLine]::Insert([String]$output) + } } - Write-Debug "Registering the navi shortcut inside the current shell session" Set-PSReadlineKeyHandler -BriefDescription "A keybinding to open Navi Widget" -Chord Ctrl+g -ScriptBlock { Invoke-NaviWidget } - - Write-Debug "Appending the navi shortcut inside the current user's profile" - ### Adding a new line - Write-Output "Import-Module navi.plugin" >> $PROFILE - Write-Output "" >> $PROFILE - Write-Output 'Set-PSReadlineKeyHandler -BriefDescription "A keybinding to open Navi Widget" -Chord Ctrl+g -ScriptBlock { Invoke-NaviWidget }' >> $PROFILE - - - Write-Output "Navi plugin has been installed!" - exit 0 ### Succesful installation -} - -if ($Verbose) { - ### Enabling verbose/debug output at the start of the script - $DebugPreference = 'Continue' - InstallNaviWidgetModule -Update $Update - ### Disabling verbose/debug output at the end of the script - ### in order to not modify the current user's shell environment - $DebugPreference = 'SilentlyContinue' -} else { - InstallNaviWidgetModule -Update $Update + Export-ModuleMember -Function @() } diff --git a/shell/navi.plugin/navi.plugin.psd1 b/shell/navi.plugin/navi.plugin.psd1 deleted file mode 100644 index 86e8da3..0000000 --- a/shell/navi.plugin/navi.plugin.psd1 +++ /dev/null @@ -1,25 +0,0 @@ -# -# Module manifest for module 'navi.plugin' -# -# Generated by: Alexis Opolka (@alexis-opolka) - - -@{ -RootModule = './navi.plugin.psm1' -ModuleVersion = '1.0' -GUID = '59287935-a9b6-4a7f-a1f5-bd6180d9056f' -Author = 'Alexis-Opolka' -CompanyName = 'None' -Copyright = '(c) Alexis Opolka & Navi contributors. All rights reserved.' -FunctionsToExport = @('Invoke-NaviWidget') -CmdletsToExport = @() -VariablesToExport = '*' -AliasesToExport = @() -PrivateData = @{ - PSData = @{ - } -} -### Here should go the HelpInfo XML file if it's supported in -### a later version. -HelpInfoURI = '' -} diff --git a/shell/navi.plugin/navi.plugin.psm1 b/shell/navi.plugin/navi.plugin.psm1 deleted file mode 100644 index 7088afe..0000000 --- a/shell/navi.plugin/navi.plugin.psm1 +++ /dev/null @@ -1,56 +0,0 @@ - -[CmdletBinding()] -param ( - ### Should we debug this PS Script ? - ### Caution: Set-PSDebug is not limited to this script but enables session-wide calls - ### Be sure to disable Verbose output before calling any other shell modules or scripts. - [Parameter()] - [bool] - $VerboseOutput -) - -if ($VerboseOutput) { - ### Outputs the running code if required - ### - ### For more details on how it works, please see: - ### - https://stackoverflow.com/a/41334715/13025136 - ### An answer and explaination from @michael-sorens (https://stackoverflow.com/users/115690/michael-sorens) - ### on how Set-PSDebug relates to set-x in LINUX/UNIX environments. - ### - ### - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-7.4 - ### Microsoft's Reference and documentation for the `Set-PSDebug` function. - Set-PSDebug -Trace 1 -} else { - Set-PSDebug -Trace 0 -} - - -### Initial code from @lurebat (https://github.com/lurebat/) -### See #570 (https://github.com/denisidoro/navi/issues/570) for its original contribution -function Invoke-NaviWidget { - $ast = $tokens = $errors = $cursor = $null - [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $ast, [ref] $tokens, [ref] $errors, [ref] $cursor) - - $line = $ast.ToString().Trim() - $output = $null - - if ([String]::IsNullOrEmpty($line)) { - $output = navi --print - } - else { - $best_match = (navi --print --best-match --query $line | Out-String).Trim() - if ([String]::IsNullOrEmpty($best_match)) { - $output = (navi --print --query "$line" | Out-String).Trim() - } - else { - $output = $best_match - } - } - - [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() - - ### Handling the case when the user escapes without selecting any entry - if (-Not([String]::IsNullOrEmpty($output))) { - [Microsoft.PowerShell.PSConsoleReadLine]::Insert([String]$output) - } -} \ No newline at end of file diff --git a/src/commands/shell.rs b/src/commands/shell.rs index 992b92b..3d932bb 100644 --- a/src/commands/shell.rs +++ b/src/commands/shell.rs @@ -14,7 +14,7 @@ impl Display for Shell { Self::Fish => "fish", Self::Elvish => "elvish", Self::Nushell => "nushell", - Self::PowerShell => "powershell", + Self::Powershell => "powershell", }; write!(f, "{s}") @@ -37,7 +37,7 @@ impl Runnable for Input { Shell::Fish => include_str!("../../shell/navi.plugin.fish"), Shell::Elvish => include_str!("../../shell/navi.plugin.elv"), Shell::Nushell => include_str!("../../shell/navi.plugin.nu"), - Shell::PowerShell => include_str!("../../shell/navi.plugin.ps1"), + Shell::Powershell => include_str!("../../shell/navi.plugin.ps1"), }; println!("{content}"); diff --git a/src/common/shell.rs b/src/common/shell.rs index 13f5bbf..c9d86a6 100644 --- a/src/common/shell.rs +++ b/src/common/shell.rs @@ -12,7 +12,7 @@ pub enum Shell { Fish, Elvish, Nushell, - PowerShell, + Powershell, } #[derive(Error, Debug)] diff --git a/src/common/terminal.rs b/src/common/terminal.rs index e20432b..b88bf41 100644 --- a/src/common/terminal.rs +++ b/src/common/terminal.rs @@ -50,7 +50,7 @@ pub fn parse_ansi(ansi: &str) -> Option { } #[derive(Debug, Clone)] -pub struct Color(pub style::Color); +pub struct Color(#[allow(unused)] pub style::Color); // suppress warning: field `0` is never read. impl FromStr for Color { type Err = &'static str; diff --git a/src/parser.rs b/src/parser.rs index bcdda8f..e1d4d2b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -254,9 +254,8 @@ impl<'a> Parser<'a> { } // duplicate - if !item.tags.is_empty() { - item.comment.is_empty(); - } + // if !item.tags.is_empty() && !item.comment.is_empty() {} + // blank if line.is_empty() { if !item.snippet.is_empty() { diff --git a/src/structures/item.rs b/src/structures/item.rs index da4a181..f5eae53 100644 --- a/src/structures/item.rs +++ b/src/structures/item.rs @@ -18,6 +18,6 @@ impl Item { } pub fn hash(&self) -> u64 { - fnv(&format!("{}{}", &self.tags.trim(), &self.comment.trim())) + fnv(&format!("{}{}{}", &self.tags.trim(), &self.comment.trim(), &self.snippet.trim())) } }