tjx666 / open-in-external-app

Open file with external application in VSCode
https://marketplace.visualstudio.com/items?itemName=YuTengjing.open-in-external-app
MIT License
55 stars 9 forks source link

Current file name(s) for args? #35

Closed martinhoess closed 1 year ago

martinhoess commented 2 years ago

Is there a var/placeholder for the current file name(s) which can be used in the args settings? I have a special application which for which the file parameter must be at a certain position

{
    "title": "specialapp",    
    "openCommand": "C:\\Program Files\\special.exe",    
    "args": ["-firstarg -secondarg $filename -thirdarg"]
}

Edit: since it was marked as enhancement:

tjx666 commented 2 years ago

try in latest version, you can using all variables defined in https://code.visualstudio.com/docs/editor/variables-reference

martinhoess commented 2 years ago

thanks for the update, but unfortunately I can't get it to work simple test should open windows explorer with the current dir, it opens the explorer but always with user/documents

I've also tried other apps but at least the directory variables do not seem to work


{
    "extensionName": "*",
    "apps": [
        {
            "title": "Explorer",
            "openCommand": "Explorer.exe",
            "args": ["/root,${workspaceFolder}"]
        }
    ]
}
tjx666 commented 2 years ago

@martinhoess try the latest version with settings like:

"openInExternalApp.openMapper": [

        {
            "extensionName": "*",
            "apps": [
                {
                    "title": "Explorer",
                    // shell command combined with placeholder
                    "shellCommand": "Explorer.exe /root ${workspaceFolder}"
                }
            ]
        }
    ]
martinhoess commented 2 years ago

@tjx666 seems to work I've also tried to combine 2 placeholders which also works ${fileWorkspaceFolder}\\${relativeFileDirname} Only thing, in the example you posted there is a , missing between root and $ which is necessary "shellCommand": "Explorer.exe /root,${workspaceFolder}"

martinhoess commented 2 years ago

${fileDirname} does somehow not work for stuff outside the working project but if the file is inside the working project it works but ${file} works for both (inside and outside working project)

tjx666 commented 2 years ago

I can't reproduce it:

image

Does that path contains space? If file path contains space, you may need to wrap it with quotes.

{
    "extensionName": "ts",
    "apps": [
        {
            "title": "run ts file",
            // wrap with quote
            "shellCommand": "ts-node '${file}'"
        }
    ]
}
martinhoess commented 2 years ago

no none of the path or filenames contains spaces. Like I said, it has to do if the opened file is part of the opend folder or not.

given folder structure:

C:\test\subfolder\project\ with a project.txt inside the "project" folder and a test.txt inside "test" folder

then in VSCode file -> open folder -> open C:\test\subfolder\project\ then from within VSCode explorer pane open the porject.txt and then via file -> open file -> open the test.txt image

then with this setting

  "openInExternalApp.openMapper": [
      {
          "extensionName": "*",
          "apps": [
              {
                  "title": "Explorer",
                  // shell command combined with placeholder
                  "shellCommand": "Explorer.exe /root,${fileDirname}"
              }
          ]
      }
  ],

try to open the project.txt and test.txt externally Folder of project.txt is opened correctly Folder of test.txt is not opened correctly (instead the user document folder is opended)

if you do the same but open folder "C:\test\" then it works fine for both files

I hope this helps somehow

tjx666 commented 2 years ago

@martinhoess please test the latest version

martinhoess commented 1 year ago

latest version looks good! thank you!