Skip to content

Commit

Permalink
✨ feat: support configure the arguments of openCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
tjx666 committed May 1, 2020
1 parent 821400a commit c980d30
Show file tree
Hide file tree
Showing 17 changed files with 959 additions and 1,106 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12.14.1
v12.14.3
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.0.7] - 2020-05-01

### Added

- support configure the openCommand arguments

## [0.0.6] - 2020-01-09

### Added
Expand Down
72 changes: 37 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Open file with external application in VSCode.

## 💡 Motivation

VSCode is a very excellent editor, but sometime I prefer to use external application to work with some files. For example, I like to use [typora](https://www.typora.io/) to edit the markdown files. Usually, I will right click to the file, and select `Reveal in Explorer` , then open the file using external application.
VSCode is a very excellent editor, but sometime I prefer to use external application to work with some files. For example, I like to use [typora](https://www.typora.io/) to edit the markdown files. Usually, I will right click to the file, and select `Reveal in File Explorer` , then open the file using external application.

But, with this extension, you can do it more simply. Just right click to the file, and select `Open in External App`, that file would be opened by system default application. You can also use this way to open `.psd` files with photoshop, `.html` files with browser, and so on...

Expand All @@ -23,48 +23,50 @@ Via custom configuration, you can make extensions more powerful. For example, to
Example configuration:

```javascript
"openInExternalApp.openMapper": [
{
// represent file extension name
"extensionName": "html",
// the external applications to open the file which extension name is html
"apps": [
// openCommand can be shell command or the complete executable application path
// title will be shown in the drop list if there are several apps
{ "title": "chrome", "openCommand": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"},
{ "title": "firefox", "openCommand": "C:\\Program Files\\Firefox Developer Edition\\firefox.exe"}
]
},
{
"extensionName": "tsx",
// apps can be Object array or just is openCommand
// the code is command you can access from shell
"apps": "code"
},
{
"extensionName": "psd",
"apps": "/path/to/photoshop.exe"
}
]
{
"openInExternalApp.openMapper": [
{
// represent file extension name
"extensionName": "html",
// the external applications to open the file which extension name is html
"apps": [
// openCommand can be shell command or the complete executable application path
// title will be shown in the drop list if there are several apps
{
"title": "chrome",
"openCommand": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
},
{
"title": "firefox",
"openCommand": "C:\\Program Files\\Firefox Developer Edition\\firefox.exe",
// open in firefox under private mode
"args": ["-private-window"]
}
]
},
{
"extensionName": "tsx",
// apps can be Object array or just is openCommand
// the code is command you can access from shell
"apps": "code"
},
{
"extensionName": "psd",
"apps": "/path/to/photoshop.exe"
}
]
}
```

![open multiple](https://github.com/tjx666/open-in-external-app/blob/master/images/open-multiple.png?raw=true)

In VSCode, Right-clicking is different from right-clicking while holding `alt` key. If you just right click the file, you will see the command `Open in External App`, but if you right click file while holding `alt` key, you will see the command `Open in Multiple External Apps`.

![ussage](https://github.com/tjx666/open-in-external-app/blob/master/images/usage.gif?raw=true)
![usage](https://github.com/tjx666/open-in-external-app/blob/master/images/usage.gif?raw=true)

## :syringe: ​Known issues
## :loudspeaker: Limits

Now, the extension doesn't support open file that file path includes non-ascii chars.

Related issues:

1. [provide API vscode.env.openItem](https://github.com/microsoft/vscode/issues/88273)
2. [shell.openExternal(path) does not work well if there are non-ascii chars in the path](https://github.com/electron/electron/issues/6302)
3. [In some places, allow to use URL in addition to URI](https://github.com/microsoft/vscode/issues/85930)

I will fix it as soon as VSCode provides a solution to deal with the issue.
For now, if you want to open a file in the application which is developed by electron such as typora, you need to configure typora as the default application to open markdown file in your operation system. The configuration of this extension about typora is invalid.

## 🧡 Backers

Expand Down
16 changes: 1 addition & 15 deletions build/configs/webpack.common.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { resolve } from 'path';
import { Configuration, BannerPlugin } from 'webpack';
import { Configuration } from 'webpack';
import WebpackBar from 'webpackbar';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import CircularDependencyPlugin from 'circular-dependency-plugin';
import HardSourceWebpackPlugin from 'hard-source-webpack-plugin';
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';

Expand Down Expand Up @@ -34,24 +32,12 @@ const commonWebpackConfig: Configuration = {
],
},
plugins: [
new BannerPlugin({
banner:
'/** @preserve powered by vscode-extension-boilerplate(https://github.com/tjx666/vscode-extension-boilerplate) */',
raw: true,
}),
new WebpackBar({
name: 'VSCode extension',
color: '#0066B8',
}),
new FriendlyErrorsPlugin(),
new CleanWebpackPlugin(),
new CaseSensitivePathsPlugin(),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: projectRoot,
}),
new HardSourceWebpackPlugin({
info: { mode: 'none', level: 'warn' },
}),
Expand Down
11 changes: 8 additions & 3 deletions build/configs/webpack.prod.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { argv } from 'yargs';
import { Configuration } from 'webpack';
import { Configuration, BannerPlugin } from 'webpack';
import merge from 'webpack-merge';
import TerserPlugin from 'terser-webpack-plugin';
import SpeedMeasurePlugin from 'speed-measure-webpack-plugin';
import SizePlugin from 'size-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';

import commonWebpackConfig from './webpack.common';

const mergedConfiguration: Configuration = merge(commonWebpackConfig, {
mode: 'production',
plugins: [new SizePlugin({ writeFile: false })],
plugins: [
new BannerPlugin({
banner:
'/** @preserve powered by vscode-extension-boilerplate(https://github.com/tjx666/vscode-extension-boilerplate) */',
raw: true,
}),
],
optimization: {
minimize: true,
minimizer: [
Expand Down
19 changes: 0 additions & 19 deletions build/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,3 @@ declare module 'speed-measure-webpack-plugin' {

export = SpeedMeasurePlugin;
}

declare module 'size-plugin' {
import { Plugin } from 'webpack';

interface SizePluginOptions {
pattern: string;
exclude: string;
filename: string;
publish: boolean;
writeFile: boolean;
stripHash: Function;
}

class SizePlugin extends Plugin {
constructor(options?: Partial<SizePluginOptions>);
}

export = SizePlugin;
}
142 changes: 73 additions & 69 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "open-in-external-app",
"displayName": "Open in External App",
"version": "0.0.6",
"version": "0.0.7",
"description": "Open file with external application in VSCode",
"publisher": "YuTengjing",
"author": {
Expand Down Expand Up @@ -111,51 +111,60 @@
"description": "mapper between the file extensionName and application to open it",
"default": [],
"items": {
"anyOf": [
{
"type": "object",
"required": [
"extensionName",
"apps"
],
"properties": {
"extensionName": {
"type": "string",
"description": "represent file extension name"
},
"apps": {
"type": "array",
"description": "external applications to open the file which extension name is specified in extensionName field",
"items": {
"anyOf": [
{
"type": "object",
"description": "app info",
"required": [
"title",
"openCommand"
],
"properties": {
"title": {
"type": "string",
"description": "title will be shown in the drop list if there are several apps"
},
"openCommand": {
"type": "string",
"description": "command you can access from shell or absolute path of executable program"
}
}
"type": "object",
"required": [
"extensionName",
"apps"
],
"properties": {
"extensionName": {
"type": "string",
"description": "represent file extension name"
},
"apps": {
"type": "array",
"description": "external applications to open the file which extension name is specified in extensionName field",
"items": {
"anyOf": [
{
"type": "object",
"description": "app info",
"required": [
"title",
"openCommand"
],
"properties": {
"title": {
"type": "string",
"description": "title will be shown in the drop list if there are several apps"
},
{
"openCommand": {
"type": "string",
"description": "command you can access from shell or absolute path of executable program"
},
"args": {
"type": "array",
"description": "arguments passed to openCommand",
"default": [],
"items": {
"type": "string"
}
},
"isElectronApp": {
"type": "boolean",
"description": "set to true when you config an electron app",
"default": false
}
]
}
},
{
"type": "string",
"description": "command you can access from shell or absolute path of executable program"
}
}
]
}
}
]
}
}
}
}
Expand All @@ -176,52 +185,47 @@
},
"dependencies": {
"joi": "^14.3.1",
"open": "6.4.0"
"open": "7.0.3"
},
"devDependencies": {
"@types/case-sensitive-paths-webpack-plugin": "^2.1.4",
"@types/circular-dependency-plugin": "^5.0.0",
"@types/friendly-errors-webpack-plugin": "^0.1.2",
"@types/glob": "^7.1.1",
"@types/hard-source-webpack-plugin": "^1.0.1",
"@types/joi": "^14.3.4",
"@types/mocha": "^7.0.1",
"@types/node": "^13.7.4",
"@types/mocha": "^7.0.2",
"@types/node": "^13.13.4",
"@types/terser-webpack-plugin": "^2.2.0",
"@types/vscode": "^1.40.0",
"@types/webpack": "^4.41.6",
"@types/vscode": "1.40.0",
"@types/webpack": "^4.41.12",
"@types/webpack-bundle-analyzer": "^2.13.3",
"@types/webpack-merge": "^4.1.5",
"@types/webpackbar": "^2.6.0",
"@types/yargs": "^15.0.3",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"case-sensitive-paths-webpack-plugin": "^2.3.0",
"circular-dependency-plugin": "^5.2.0",
"@types/webpackbar": "^4.0.0",
"@types/yargs": "^15.0.4",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"clean-webpack-plugin": "^3.0.0",
"cross-env": "^7.0.0",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-prettier": "^3.1.2",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-prettier": "^3.1.3",
"friendly-errors-webpack-plugin": "^1.7.0",
"glob": "^7.1.5",
"hard-source-webpack-plugin": "^0.13.1",
"husky": "^4.2.3",
"lint-staged": "^10.0.7",
"mocha": "^7.0.1",
"prettier": "^1.19.1",
"size-plugin": "^2.0.1",
"speed-measure-webpack-plugin": "^1.3.1",
"terser-webpack-plugin": "^2.3.5",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"typescript": "^3.7.5",
"husky": "^4.2.5",
"lint-staged": "^10.2.2",
"mocha": "^7.1.2",
"prettier": "^2.0.5",
"speed-measure-webpack-plugin": "^1.3.3",
"terser-webpack-plugin": "^2.3.6",
"ts-loader": "^7.0.2",
"ts-node": "^8.9.1",
"typescript": "^3.8.3",
"vscode-test": "^1.3.0",
"webpack": "^4.41.6",
"webpack-bundle-analyzer": "^3.6.0",
"webpack": "^4.43.0",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-merge": "^4.2.2",
"webpackbar": "^4.0.0",
"yargs": "^15.1.0"
"yargs": "^15.3.1"
}
}
4 changes: 2 additions & 2 deletions src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as vscode from 'vscode';
import openFile from '../openFile';
import openInExternalApp from '../openInExternalApp';

type Uri = vscode.Uri;

async function handler(uri: Uri | undefined) {
openFile(uri);
openInExternalApp(uri);
}

const command: CommandModule = {
Expand Down
Loading

0 comments on commit c980d30

Please sign in to comment.