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

pwsh not detecting eNum #123

Open
brian6932 opened this issue Aug 11, 2022 · 3 comments
Open

pwsh not detecting eNum #123

brian6932 opened this issue Aug 11, 2022 · 3 comments

Comments

@brian6932
Copy link

brian6932 commented Aug 11, 2022

image
I used the script from the readme:
image

Shell: PowerShell 7.3.0-preview.6
tre: tre-command 0.4.0

Same thing occurs on Windows' system PowerShell (5.1)

@hiyorijl
Copy link

hiyorijl commented Jan 28, 2024

Same issue here. I think it's because pwsh doesn't work with Doskey while cmd does, Powershell works with PSReadLine .

Doskey apart from being incompatible with PSReadLine see: PowerShell/PSReadLine#353 Doskey doesn't work with pwsh, it also will not be supported by the devs as linked before so it should be replaced with PSReadLine completely.

this is the file that should be changed in any case to make it work with PSReadline instead:

"doskey /exename=pwsh.exe e{}={} {}\ndoskey /exename=powershell.exe e{}={} {}",

@jman4747
Copy link

jman4747 commented Jun 6, 2024

One solution, instead of using doskey to create the aliases, is to generate a PowerShell module containing functions named e<NUM> and then import that module using the tre.ps1 file.

I'm testing out a patch that does that currently.

The difference is we:

  • generate an aliases file with the .psm1 suffix
  • add PowerShell functions in the form: Function e<index> { <editor> $args "<path>"} for each entry
  • add Export-ModuleMember -Function * to the end

This yields the following aliases file for me when invoked on the tre/src directory:

Function e0 { nvim.exe $args "src"}
Function e1 { nvim.exe $args "src/cli.rs"}
Function e2 { nvim.exe $args "src/diagram_formatting.rs"}
Function e3 { nvim.exe $args "src/file_tree.rs"}
Function e4 { nvim.exe $args "src/json_formatting.rs"}
Function e5 { nvim.exe $args "src/main.rs"}
Function e6 { nvim.exe $args "src/output.rs"}
Function e7 { nvim.exe $args "src/path_finders.rs"}
Function e8 { nvim.exe $args "src/tre.rs"}
Export-ModuleMember -Function *

In the new tre.ps1 script file we:

  • remove that module if it exists from prior invocations of tre.exe
  • invoke tre.exe as normal
  • import the module as generated by the current invocation of tre.exe

New tre.ps1 script:

# Remove the tre.exe aliases module created by the previous invocation
# if it exists
if (Get-Module tre_aliases_$env:USERNAME)
{
    Remove-Module -Force tre_aliases_$env:USERNAME
}

# Call tre.exe with the args passed to this script and the editor flag
tre.exe $args -e

# Import the new aliases module created by tre.exe
Import-Module $Env:TEMP\tre_aliases_$env:USERNAME.psm1

I can then type e5 to open src/main.rs assuming $EDITOR=nvim.exe.

@SVendittelli
Copy link

Did you run into any issues with your patch @jman4747

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

No branches or pull requests

4 participants