yhirose / vscode-filtertext

Filter Text extension for VS Code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set current working directory for the command to match the opened directory

kankri opened this issue · comments

I was happy to discover this extension and will use it heavily. However, there is one change which would make it even more convenient for me.

I'd like to execute e.g. wc -l *, but currently (at least on Windows) that would give contents from the installation directory (C:\Program Files (x86)\Microsoft VS Code).

To work around the issue I currently need to explicitly start a shell and switch to the correct directory, e.g:

cmd /c "cd MYDIRECTORY && wc -l *"

I can think of several alternatives for the default directory:

  • Take the directory of the current editor
  • If the current editor is Untitled-x, take the directory opened in VS Code
  • If there is no directory opened, just individual files, pick one of their directories
  • Default to user's home directory

Maybe there could be a directory selection box below the command input box which shows the alternatives but would allow the user to type something different (combo box).

@kankri, thanks for the suggestion. I implemented it and tested on my MacBook. (I haven't tested on Windows because I don't have a Windows machine right now...)

Hope the new version 0.0.7 works for you. If you find any problem, please let me know.

Thanks!

This is how it seems to work for me now:

  • If the tab has a file which is part of an opened directory, the working directory is the opened directory. 👍
  • If the tab is Untitled, the working directory is the home directory. This is better than previously, but if it were the opened directory, I think it would be even better!
  • If the windows doesn't have a directory open and the tab is Untitled, the working directory is the home directory. 👍
  • If the window doesn't have a directory open and the tab contains a file, the command fails to execute and the developer console shows:
    TypeError: Cannot read property 'length' of undefined
        at getCurrentWorkingDirectory (C:\Users\user\.vscode\extensions\yhirose.filtertext-0.0.7\out\src\extension.js:142:20)
        at C:\Users\user\.vscode\extensions\yhirose.filtertext-0.0.7\out\src\extension.js:32:29
    

This last problem is clearly a bug!

@kankri, thanks for the detailed report! I'll looking into the last one when I get a Windows environment.

@kankri, I just published the new version. I fixed the latest issue. Please let me know if you still havw the problem with this version.

Sorry I forgot to reply sooner... I'm not seeing errors any more! This is what I'm getting:

Untitled foo/bar.txt
no directory open $HOME $HOME
directory baz/ open $HOME baz/

Thanks for your effort and the quick fix!

If it's possible and you feel for it, these would be my ideal defaults:

Untitled foo/bar.txt
no directory open $HOME foo/
directory baz/ open baz/ baz/

If the tab is Untitled, the working directory is the home directory. This is better than previously, but if it were the opened directory, I think it would be even better!

I have issued a pull-request #13 to fix this.

@johnnytemp, thanks for the pull request #13.
@kankri, I just released version 0.0.11 including your suggestion.