Skip to content

Commit cfae011

Browse files
authored
Merge pull request #39 from fdncred/terminal_profile
updated to try and find nushell so it can be used as a terminal
2 parents 049a9d1 + f13ee8b commit cfae011

File tree

9 files changed

+1186
-2219
lines changed

9 files changed

+1186
-2219
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ All notable changes to the "vscode-nushell-lang" extension will be documented in
7474
- syntax changed to allow optional `$` in variable name
7575
- syntax changed to allow space after custom command parameters
7676
- added `in` to go with `for`
77+
- 0.4.2
78+
- added contribute custom terminal feature it is easier to use nushell as a terminal in vscode

dist/extension.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/extension.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/extension.js

Lines changed: 87 additions & 2139 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/extension.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 928 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-nushell-lang",
33
"displayName": "vscode-nushell-lang",
44
"description": "nushell language for vscode",
5-
"version": "0.4.1",
5+
"version": "0.4.2",
66
"preview": true,
77
"license": "MIT",
88
"publisher": "TheNuProjectContributors",
@@ -15,30 +15,33 @@
1515
"url": "https://github.com/nushell/vscode-nushell-lang/issues"
1616
},
1717
"engines": {
18-
"vscode": "^1.52.0"
18+
"vscode": "^1.59.0"
1919
},
2020
"icon": "assets/nushell.ico",
2121
"categories": [
2222
"Programming Languages",
2323
"Snippets"
2424
],
2525
"activationEvents": [
26-
"*"
26+
"onTerminalProfile:nushell_default"
2727
],
28-
"main": "./out/extension.js",
28+
"main": "./dist/extension",
2929
"scripts": {
30-
"vscode:prepublish": "npm run compile",
31-
"compile": "tsc -p ./",
32-
"lint": "eslint . --ext .ts,.tsx",
33-
"watch": "tsc -watch -p ./"
30+
"vscode:prepublish": "webpack --mode production",
31+
"webpack": "webpack --mode development",
32+
"webpack-dev": "webpack --mode development --watch",
33+
"test-compile": "tsc -p ./"
3434
},
3535
"devDependencies": {
36-
"@types/node": "^12.20.18",
37-
"@types/vscode": "^1.52.0",
38-
"@typescript-eslint/eslint-plugin": "^4.29.0",
39-
"@typescript-eslint/parser": "^4.29.0",
36+
"@types/node": "^12.20.23",
37+
"@types/vscode": "^1.59.0",
38+
"@typescript-eslint/eslint-plugin": "^4.30.0",
39+
"@typescript-eslint/parser": "^4.30.0",
4040
"eslint": "^7.32.0",
41-
"typescript": "^4.3.5"
41+
"ts-loader": "^9.2.5",
42+
"typescript": "^4.4.2",
43+
"webpack": "^5.51.2",
44+
"webpack-cli": "^4.8.0"
4245
},
4346
"keywords": [
4447
"nushell",
@@ -104,6 +107,18 @@
104107
"language": "nushell",
105108
"path": "./snippets/nushell.json"
106109
}
107-
]
110+
],
111+
"terminal": {
112+
"profiles": [
113+
{
114+
"title": "Nushell",
115+
"id": "nushell_default"
116+
}
117+
]
118+
}
119+
},
120+
"dependencies": {
121+
"glob": "^7.1.7",
122+
"os": "^0.1.2"
108123
}
109124
}

src/extension.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,98 @@
1+
'use strict';
2+
import * as vscode from 'vscode';
3+
export function activate(context: vscode.ExtensionContext) {
4+
console.log("Terminals: " + (<any>vscode.window).terminals.length);
5+
context.subscriptions.push(vscode.window.registerTerminalProfileProvider('nushell_default', {
6+
provideTerminalProfile(token: vscode.CancellationToken): vscode.ProviderResult<vscode.TerminalProfile> {
7+
const path = require('path');
8+
const fs = require('fs');
9+
const glob = require('glob');
10+
const os = require('os');
11+
12+
const pathsToCheck = [
13+
// cargo install location
14+
'~/.cargo/bin/nu',
15+
16+
// winget on Windows install location
17+
'c:\\program files\\nu\\bin\\nu.exe',
18+
// just add a few other drives for fun
19+
'd:\\program files\\nu\\bin\\nu.exe',
20+
'e:\\program files\\nu\\bin\\nu.exe',
21+
'f:\\program files\\nu\\bin\\nu.exe',
22+
23+
// SCOOP:TODO
24+
// all user installed programs and scoop itself install to
25+
// c:\users\<user>\scoop\ unless SCOOP env var is set
26+
// globally installed programs go in
27+
// c:\programdata\scoop unless SCOOP_GLOBAL env var is set
28+
// scoop install location
29+
'~/scoop/apps/nu/*/nu.exe',
30+
31+
// chocolatey install location - same as winget
32+
// 'c:\\program files\\nu\\bin\\nu.exe',
33+
34+
// macos dmg install
35+
// we currentl don't have a dmg install
36+
37+
// linux and mac zips can be put anywhere so it's hard to guess
38+
39+
// brew install location mac
40+
'/usr/local/bin/nu',
41+
42+
// fdncred install path
43+
'c:\\apps\\nushell\\nu_latest\\nu.exe',
44+
];
45+
46+
var found_nushell_path = "";
47+
const home = os.homedir();
48+
49+
for (var cur_val of pathsToCheck) {
50+
// console.log("Inspecting location: " + cur_val);
51+
var constructed_file = "";
52+
if (cur_val.startsWith('~/scoop')) {
53+
// console.log("Found scoop: " + cur_val);
54+
var p = path.join(home, cur_val.slice(1));
55+
// console.log("Expanded ~: " + p);
56+
var file = glob.sync(p, "debug").toString();
57+
// console.log("Glob for files: " + file);
58+
59+
if (file) {
60+
// console.log("Found some file: " + file);
61+
// if there are slashes, reverse them to back slashes
62+
constructed_file = file.replace(/\//g, '\\');
63+
}
64+
}
65+
else if (cur_val.startsWith('~')) {
66+
constructed_file = path.join(home, cur_val.slice(1));
67+
// console.log("Found ~, constructing path: " + constructed_file);
68+
} else {
69+
constructed_file = cur_val;
70+
}
71+
72+
if (fs.existsSync(constructed_file)) {
73+
// console.log("File exists, returning: " + constructed_file);
74+
found_nushell_path = constructed_file;
75+
break;
76+
} else {
77+
// console.log("File not found: " + constructed_file);
78+
}
79+
}
80+
81+
if (found_nushell_path.length > 0) {
82+
return {
83+
options: {
84+
name: 'Nushell',
85+
shellPath: found_nushell_path
86+
}
87+
}
88+
}
89+
else {
90+
console.log("Nushell not found, returning undefined");
91+
return undefined;
92+
}
93+
}
94+
}));
95+
}
196
// import * as vscode from "vscode";
297
// export function activate(context: vscode.ExtensionContext) {
398
// const keywordsWithSubCommandsProvider =

webpack.config.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//@ts-check
2+
3+
'use strict';
4+
5+
const path = require('path');
6+
7+
/**@type {import('webpack').Configuration}*/
8+
const config = {
9+
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
10+
11+
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
12+
output: {
13+
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
14+
path: path.resolve(__dirname, 'dist'),
15+
filename: 'extension.js',
16+
libraryTarget: 'commonjs2',
17+
devtoolModuleFilenameTemplate: '../[resource-path]'
18+
},
19+
devtool: 'source-map',
20+
externals: {
21+
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
22+
},
23+
resolve: {
24+
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
25+
extensions: ['.ts', '.js']
26+
},
27+
module: {
28+
rules: [
29+
{
30+
test: /\.ts$/,
31+
exclude: /node_modules/,
32+
use: [
33+
{
34+
loader: 'ts-loader'
35+
}
36+
]
37+
}
38+
]
39+
}
40+
};
41+
module.exports = config;

0 commit comments

Comments
 (0)