dduan / tre

Tree command, improved.
MIT License
728 stars 15 forks source link

pwsh not detecting `eNum` #123

Open brian6932 opened 1 year ago

brian6932 commented 1 year ago

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 commented 5 months ago

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: https://github.com/PowerShell/PSReadLine/issues/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: https://github.com/dduan/tre/blob/a813038b1c0e52cbc6ce44a28bc828476f161585/src/output.rs#L126

jman4747 commented 4 weeks ago

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:

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:

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.