Coder Social home page Coder Social logo

ps-guicompletion's Introduction

GuiCompletion for PowerShell

This project has moved to https://github.com/nightroman/PS-GuiCompletion The published module is the same GuiCompletion. It is developed by @nightroman starting from v0.9.0.


This enables a GUI-style tab-completion menu for PowerShell. It integrates with PSReadLine which comes installed in PowerShell by default, and the GUI code is lifted straight from PowerTab.

Bugs? Please open an issue on Github: https://github.com/cspotcode/PS-GuiCompletion/issues

Animated example

Installation

Install from the PowerShell Gallery. (GuiCompletion's Gallery page)

Install-Module -Name GuiCompletion -Scope CurrentUser

You can omit -Scope but I use it to avoid requiring Administrator permissions.

Usage

Register it with the default Ctrl+Spacebar key shortcut:

Install-GuiCompletion

...or with another key shortcut:

Install-GuiCompletion -Key Tab

Install-GuiCompletion is a one-line helper that wrap PSReadLine's Set-PSReadLineKeyHandler cmdlet. For more advanced scenarios, you can call the relevant PSReadLine commands directly:

Set-PSReadlineKeyHandler -Key Alt+Spacebar -ScriptBlock { Invoke-GuiCompletion }

You'll want to add these configuration commands to your PowerShell profile. Otherwise your configuration will not be applied to new PowerShell sessions.

TODOs

Mac and Linux support. GetKeyState and some of the rendering code is apparently Windows-only.

Changelog

v0.8.1

  • Fixes broken publication of v0.8.0

v0.8.0

  • Switches to Windows' default menu color scheme (#5, @nightroman)
    • If you want to use the old theme or customize colors, modify the $GuiCompletionConfig.Colors global variable.
  • Fixes rendering glitch where some vertical lines could be left over after the menu closes (#6, @nightroman)
  • Switches to TabExpansion2 for computing completions, which allows other modules to plugin custom completions (#7, @nightroman)

ps-guicompletion's People

Contributors

cspotcode avatar nightroman avatar

Stargazers

ddurgit avatar  avatar  avatar Bartosz avatar Tianyu Geng avatar David Brockmeier avatar  avatar Creeper Lv avatar Anders Chen avatar Matthew Gray avatar 野声 avatar Billy Vierra avatar Kevin Blumenfeld avatar  avatar  avatar Charlie Langerhans avatar imr avatar Ryouko Konpaku avatar Manuel Berfelde avatar  avatar Andy Babiec avatar Tim avatar Jonas avatar Mikael Olenfalk avatar Nagy-Egri Máté Ferenc avatar OmariO avatar Jakub Podhorský avatar Michael Kelley avatar Kurt De Greeff avatar Craig Forrester avatar PRASOON KARUNAN V avatar Doug Finke avatar  avatar Sergei Vorobev avatar Tom-- avatar sheldonhull avatar  avatar Thomas Malkewitz avatar taichi avatar Miodrag Milić avatar Brian Napolitano avatar Deepak Singh Dhami avatar Kenneth P. Barquero avatar François-Xavier Cat avatar James Martindale avatar Troy Campbell avatar Flavien MICHALECZEK avatar Peter Kurlak avatar Corey Fonseca avatar Windroid Xie avatar Thomas Runting avatar Jason Tucker avatar Andy Sipe avatar  avatar Zachary Loeber avatar Blake Jakopovic avatar  avatar Peet avatar Adam Mcchesney avatar

Watchers

 avatar James Cloos avatar  avatar space avatar  avatar Adam Mcchesney avatar  avatar

Forkers

t-t-t-t-t

ps-guicompletion's Issues

PS-GuiCompletion does not work in PowerShell Core 7.0 on Linux

PS /mnt/c/Users/coren> Write-[TAB]An exception occurred in custom key handler, see $error for more information: Exception calling "GetBufferContents" with "1" argument(s): "The method or operation is not implemented."

PS /mnt/c/Users/coren> $ERROR

MethodInvocationException: /home/cola/.local/share/powershell/Modules/GuiCompletion/0.8.1/powertab/ConsoleLib.ps1:455
Line |
 455 |          $OldBuffer = $Host.UI.RawUI.GetBufferContents((New-Object Sys …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "GetBufferContents" with "1" argument(s): "The method or operation is not implemented."

Invoke-GuiCompletion should use TabExpansion2

Invoke-GuiCompletion should use TabExpansion2, not [System.Management.Automation.CommandCompletion]::CompleteInput because TabExpansion2 opens doors for user extensions. The latter does not, it just calls the default not configurable method. I will submit the PR.

Fuzzy matching

Fuzzy matching means you can omit parts of the string you want to match. For example, type "-lip" and it'll match "-LiteralPath".

For performance it probably makes sense to implement the filtering in a background thread. (See #3)

This library implements a fuzzy matching algorithm; are there C# implementations I can use? https://github.com/atom/fuzzaldrin
C# possibility:
https://github.com/kdjones/fuzzystring

Nice-to-haves: render with matched characters highlighted a-la VSCode

Exception in "CompleteInput" with UNC paths or when there are no matches

When I hit Tab at a partial UNC path I get an exception in "CompleteInput" and expansion doesn't work:

> gci //pnjnas/p/photos/class*

    Directory:  C:\Users\steph

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        2020-04-19     21:20        1   classées

> gci //pnjnas/p/photos/classAn exception occurred in custom key handler, see $error for more information: Exception calling "CompleteInput" with "3" argument(s): "Object reference not set to an instance of an object."

> $error[0] | select *

PSMessageDetails      :
Exception             : System.Management.Automation.MethodInvocationException: Exception calling "CompleteInput" with
                        "3" argument(s): "Object reference not set to an instance of an object."
                         ---> System.NullReferenceException: Object reference not set to an instance of an object.
                           at
                        System.Management.Automation.CompletionCompleters.InvokeScriptArgumentCompleter(ScriptBlock
                        scriptBlock, Object[] argumentsToCompleter, List`1 result)
                           at
                        System.Management.Automation.CompletionCompleters.InvokeScriptArgumentCompleter(ScriptBlock
                        scriptBlock, String commandName, String parameterName, String wordToComplete, CommandAst
                        commandAst, CompletionContext context, List`1 resultList)
                           at System.Management.Automation.CompletionCompleters.NativeCommandArgumentCompletion(String
                        commandName, CompiledCommandParameter parameter, List`1 result, CommandAst commandAst,
                        CompletionContext context, Dictionary`2 boundArguments)
                           at System.Management.Automation.CompletionCompleters.ProcessParameter(String commandName,
                        CommandAst commandAst, CompletionContext context, List`1 result,
                        MergedCompiledCommandParameter parameter, Dictionary`2 boundArguments)
                           at System.Management.Automation.CompletionCompleters.GetArgumentCompletionResultsWithSuccess
                        fulPseudoBinding(CompletionContext context, ArgumentLocation argLocation, CommandAst
                        commandAst)
                           at
                        System.Management.Automation.CompletionCompleters.CompleteCommandArgument(CompletionContext
                        context)
                           at System.Management.Automation.CompletionAnalysis.GetResultForIdentifier(CompletionContext
                        completionContext, Int32& replacementIndex, Int32& replacementLength, Boolean isQuotedString)
                           at System.Management.Automation.CompletionAnalysis.GetResultHelper(CompletionContext
                        completionContext, Int32& replacementIndex, Int32& replacementLength, Boolean isQuotedString)
                           at System.Management.Automation.CompletionAnalysis.GetResults(PowerShell powerShell, Int32&
                        replacementIndex, Int32& replacementLength)
                           at System.Management.Automation.CommandCompletion.CompleteInputImpl(Ast ast, Token[]
                        tokens, IScriptPosition positionOfCursor, Hashtable options)
                           at System.Management.Automation.CommandCompletion.CompleteInput(String input, Int32
                        cursorIndex, Hashtable options)
                           at CallSite.Target(Closure , CallSite , Type , String , Int32 , Hashtable )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
                        funcContext, Exception exception)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame
                        frame)
                           at
                        System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
                        frame)
                           at
                        System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
                        frame)
                           at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
                           at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object
                        dollarUnderbar, Object inputToProcess)
                           at System.Management.Automation.CommandProcessorBase.Complete()
TargetObject          :
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : NullReferenceException
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock><End>, <No file>: line 38
                        at Invoke-GuiCompletion,
                        C:\Users\steph\OneDrive\Documents\PowerShell\Modules\GuiCompletion\0.8.1\GuiCompletion.psm1:
                        line 22
                        at <ScriptBlock>,
                        C:\Users\steph\OneDrive\Documents\PowerShell\Modules\GuiCompletion\0.8.1\GuiCompletion.psm1:
                        line 8
                        at PSConsoleHostReadLine,
                        C:\Users\steph\OneDrive\Documents\PowerShell\Modules\PSReadLine\2.0.0\PSReadLine.psm1: line 4
PipelineIterationInfo : {}


How can I (help) troubleshoot(ing) that?

I'm running 0.8.1, with PSReadLine 2.0.0. Issue occurs both in Windows PowerShell 5.1 and PowerShell 7.0.

The same exception is raised when there are no matches:

> ls c:/nomatchAn exception occurred in custom key handler, see $error for more information: Exception calling "CompleteInput" with "3" argument(s): "Object reference not set to an instance of an object."

On closing the menu vertical lines may stay visible in the console

This is a known defect of the console (before Windows 10) with clear type fonts. On closing the menu some vertical ghost lines may stay visible, namely, at the left or right menu border or both.

The remedy is to store/restore not just the buffer area of the menu but the buffer rectangle from the left most to the right most. I will submit the PR shortly.

Modifying `$GuiCompletionConfig` has no effect

Modifying colors or other settings via $GuiCompletionConfig in $PROFILE or interactively has no effect - while modifications in default-config.ps1 have the desired effect.

This seems to be a bug and not a user error because $GuiCompletionConfig.DoubleBorder = $false (for instance) has no effect while $PowerTabConfig.DoubleBorder = $false (with PowerTab instead of GuiCompletion imported) works.

Broken on PowerShell Core 7

I'm getting this when completion triggers:

❯ ls -la /SAn exception occurred in custom key handler, see $error for more information: Exception calling "GetBufferContents" with "1" argument(s): "The method or operation is not implemented."

Filtering in background thread

Use the threadpool to run filtering in a background thread. This keeps the UI responsive while you type.

While foreground is waiting for keystrokes, background thread must be able to interrupt with updates and trigger re-rendering of the dropdown.

When user hits ctrl+space, capture input state and launch background thread to fetch completion results.
Immediately render a blank completion dropdown.
When background thread has a list ready, notify foreground to re-render dropdown. Immediately start filtering based on typed input.
As characters are entered, send updated input strings to background thread.
As list is narrowed down, send updated narrowed list to foreground.
When list re-renders, preserve selection if selected item is still in the list.

Configurable colors with less aggressive default, perhaps?

Is it or will it be possible to configure colors?

Regardless, is it possible to offer less "aggressive" default colors? I know,
this is a matter of personal taste. But many people are rather familiar with
sort of "standard" menu colors, see F7 history menu in cmd.exe
console. Why not use it as the default?

Remove HelpInfoURI from the manifest. It make problems for Update-Help.

HelpInfoURI in the manifest makes problems for Update-Help:

Update-Help : Failed to update Help for the module(s) 'GuiCompletion' with UI culture(s) {en-US} : The value of the HelpInfoUri key in the module manifest must
resolve to a container or root URL on a website where the help files are stored. The HelpInfoUri 'https://github.com/cspotcode/PS-GuiCompletion' does not resolve
to a container.
At line:1 char:1
+ Update-Help -Verbose -ErrorAction Continue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : InvalidHelpInfoUri,Microsoft.PowerShell.Commands.UpdateHelpCommand

I removed it in my "active" branch nightroman-2: 09b246e

Perhaps others branches should remove it, too.

Load on Powershell Start

I am having trouble getting this to be the default config for Powershell. Each time I launch powershell.exe I have to run "install-guicompletion -key tab"

Is there anyway to make this load automatically?

Love this module

I hope you are keeping it alive. It has been a while since the last release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.