Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for capitalizing, upcasing, and downcasing words #2912

Closed
1 task done
3N4N opened this issue Oct 9, 2021 · 8 comments · Fixed by #3365
Closed
1 task done

Add support for capitalizing, upcasing, and downcasing words #2912

3N4N opened this issue Oct 9, 2021 · 8 comments · Fixed by #3365
Labels

Comments

@3N4N
Copy link
Contributor

3N4N commented Oct 9, 2021

Prerequisites

  • Write a descriptive title.

Description of the new feature/enhancement

In GNU Readline, I can use Emacs-like keys to capitalize, upcase, or lowercase the word after the cursor position. I can even change the keybindings. In my .bashrc, for example, I have:

# bind keys for case conversion
bind '"\ei": capitalize-word'    # default is alt-c
bind '"\eo": upcase-word'     # default is alt-u
bind '"\eu": downcase-word'  # default is alt-l

Clink for Windows CMD has this feature.

Proposed technical implementation details (optional)

I haven't looked into the PSReadline codebase yet. Strictly an user here. But I could look around out of curiosity if someone could point me to the code where stuff like alt-del or alt-f/b was implemented.

@3N4N 3N4N added the Issue-Enhancement It's a feature request. label Oct 9, 2021
@ghost ghost added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Oct 9, 2021
@lzybkr
Copy link
Member

lzybkr commented Oct 11, 2021

It's generally easy to find the source for specific key bindings - the name of the function in the source matches exactly what you see when you run Get-PSReadLineKeyHandler.

For the specific case of Alt+f the function is ForwardWord, but sometimes it is rebound with ShellFowardWord which defines a word as a PowerShell token instead of a simple word delimited by the characters in the option WordDelimiters.

It might be worth a brief discussion on whether or not it makes sense to add the "shell word" variants for these case changing functions. I initially thought yes, but maybe they wouldn't be useful at all as I don't think it would do what people expect, e.g. it would do nothing if the cursor is inside a string literal.

Vi mode does implement ~ - the function is named InvertCase, so you have some sample code to invert a single character.

@daxian-dbw daxian-dbw removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Oct 11, 2021
@3N4N
Copy link
Contributor Author

3N4N commented Oct 12, 2021

About the shellword variants: I also don't think it'd be useful. But I don't use ShellForwardWord or other shellword variants either. So I may not be the best person to argue its usefulness.

And I wanted to try and see if I could add the support. Doesn't seem that difficult. Take the text from cursor position to where ForwardWord would move to and edit that text. But I don't understand how to import the module I just edited and built. There are build tutorials in the contribution guideline but no import tutorial. A default workflow scenario would help a lot the newcomers.

@lzybkr
Copy link
Member

lzybkr commented Oct 12, 2021

The easiest way to try out changes is in MockPSConsole which you can just build and run from this projects solution file.

Other ways a bit cumbersome because PowerShell loads PSReadLine by default.

@springcomp
Copy link
Contributor

@3N4N I just published #2939 to outline and give you an idea how to quickly and effortlessly debug a custom build of PSReadLine on your own machine.

@lzybkr I hope you do not mind me hi-jacking the pull request infrastructure for this.

@lzybkr
Copy link
Member

lzybkr commented Oct 28, 2021

@springcomp - that's more involved than my approach, which was to:

  • exit all instances of PowerShell
  • launch an instance w/ -noprofile -noninteractive and in this instance:
    • backup the files I'm replacing in the PSReadLine module directory
    • copy over the files (usually just PSReadLine.dll)

This approach requires being an admin or installing a user local version of the module.

Alternatively, you could change the environment variable PSModulePath and avoid some of this, but I typically never did that because I knew I'd be using the version I built right away anyway.

@springcomp
Copy link
Contributor

@lzybkr yes, your are right, it is a lot more involved.

However, it also means that the original instance of PSReadLine is always available and both can be run side by side.
I’m typically working on PSRL only occasionnaly and like to have a stable development environment otherwise.

Once the initial setup step hurdle is done, I find that I can quickly jump to working on a PSRL feature right away with a couple of keystrokes, without impacting other PowerShell sessions from the terminal or from Visual Studio code instances running.

I’m gonna go ahead an close my pull request and will try and work on drafting a wiki page detailing all three approaches:

– Using MockPSConsole.
– Using drop-in replacements of PSRL assemblies.
– Running a custom-built version of PSRL side-by-side.

Would that be helpful?

springcomp added a commit to springcomp/PSReadLine that referenced this issue Jan 10, 2022
@ghost ghost added the In-PR A PR is opened targeting the issue label Jul 2, 2022
@3N4N
Copy link
Contributor Author

3N4N commented Jul 2, 2022

@lzybkr Sorry for being late. GH notifications must've been turned off back then.

I whipped something up yesterday. Opened a pull request. I'll move the conversation over there. Check that out when you have time. And thanks for the responses.

@ghost
Copy link

ghost commented Mar 8, 2023

🎉 This issue was addressed in 3365, which has now been successfully released in v2.3.0-beta0. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants