Git Product home page Git Product logo

egodigital / vscode-powertools Goto Github PK

View Code? Open in Web Editor NEW
162.0 8.0 15.0 19.9 MB

A swiss army knife with lots of tools, extensions and (scriptable) enhancements for Visual Studio Code.

Home Page: https://marketplace.visualstudio.com/items?itemName=ego-digital.vscode-powertools

License: GNU Lesser General Public License v3.0

TypeScript 11.03% CSS 26.27% JavaScript 62.14% EJS 0.57%
vscode-helpers vscode-extension nodejs events cronjobs buttons scripts autostart tools webapp

vscode-powertools's Introduction

vscode-powertools

that version of the extension is no longer supported! ... please backup, uninstall and change to new location

vscode-powertools's People

Contributors

ixlikro avatar mkloubert avatar mkloubertego avatar pitaj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-powertools's Issues

How to use current file extension in an if-clause?

I have set up a button to launch a shell-cmd on the current file. Works fine.
Now I wanted to only show that button if the file is of appropriate type.

Googled the following test and tried it i a debug-console:
(/(dyalog|mipage)$/ig.test(activeFile.substr((activeFile.lastIndexOf('.') +1))))

But this assumed we had a var activeFile which we don't. So I tried to code around that and ended up with the following - but it doesn't seem to work (does not show the icon for .dyalog-files):
"if": '(/(dyalog|mipage)$/ig.test("${activeFile}".substr(("${activeFile}".lastIndexOf(".") +1))))',

Can't I use ${activeFile} in `if´s or is there another mistake?

executeCommand("cmake.buildDirectory") gives: Cannot read property 'uri' of undefined

I am using vscode powertools to write a little script that enhances the ms-vscode.cmake-tools plugin. It used to work a month or two ago when I used it, but something changed in my setup (vs code version/powertools version/cmake tools version) that make my script say Cannot read property 'uri' of undefined.

I have narrowed the example down to the following script:

// relativeTargetPath.js
exports.execute = async (args) => {
    const vscode = args.require('vscode');
    return vscode.commands.executeCommand('cmake.buildDirectory');
};
// in my workspace settings
"ego.power-tools": {
    "commands": {
        "relativeTargetPath": {
            "script": "relativeTargetPath.js"
        }
    }

The odd thing is that the command cmake.buildDirectory works in a task:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo",
      "type": "shell",
      "command": "echo ${cmake.buildDirectory}"
    }
  ]
}

Is this something that could be going wrong in powertools or is it cmake tools or just vs code?

Info:
vs code 1.43.2
ms-vscode.cmake-tools 1.3.1
ego-digital.vscode-powertools 0.58.0

keyboard shortcuts?

fantastic plugin, really enjoy the custom button feature.

I am curious, would you consider keyboard shortcuts in-scope for this plugin? Is there already a VSCode native way to trigger a vscode-powertools script with a keyboard shortcut?

My use case is to have a keyboard shortcut that would trigger the same action as one of my buttons that would be active when I have VSCode open and in focus.

On the Make Order,"make all","make clean"....

{
    "ego.power-tools": {
        "buttons": [
            {
                "text": "make clean",
                "tooltip": "clean",
                "action": {
                    "type": "shell",
                    "command": "make clean"
                }
            },
            {
                "text": "make all-j8",
                "tooltip": "rebuild",
                "action": {
                    "type": "shell",
                    "command": "make all -j8"
                }
            }
}

I hope the console will display the current compilation information when I click on it.

How can this be achieved?
At present, he only has a box in the lower right corner. I can't see the return information of the console. This command is very common. Hope to have a tutorial.
image

Environment variable substitution in script location not working

I an environment variable on my system:
$ONETHINX_PACK_LOC which points to /Volumes/Data/VScode/GIT/VSCode_OnethinxPack_macOS

I have a button in my settings along with this script setup:
"script": "${env:ONETHINX_PACK_LOC}/config/scripts/onethinx.js"

When I press the button I get:
Could not execute button: [Error] 'Script '${env:ONETHINX_PACK_LOC}/config/scripts/onethinx.js' not found!'

I also tried to use it like this: "script": "$ONETHINX_PACK_LOC/config/scripts/onethinx.js" without reveal.
While hard-coding the location does work:
"script": "/Volumes/Data/VScode/GIT/VSCode_OnethinxPack_macOSconfig/scripts/onethinx.js"

Any ideas?

Complete VS Code freeze after trashing a terminal (opened using a button)

After I click the trash icon of the terminal, VS Code freeze completely. The terminal is launched from a custom script, triggered by a button:

freeze

I have a simple button in .vscode/settings.json:

"ego.power-tools": {
  "buttons": [
    {
      "text": "$(cloud-upload) deploy",
      "tooltip": "${workspaceName} - deploy this project",
      "if": "$fs.existsSync(`${$v['workspaceRoot']}/vendor/bin/dep`)",
      "action": {
        "type": "script",
        "script": "scripts/deploy.js"
      }
    }
  ]
}

I don't know if there is something wrong with my simple scripts/deploy.js:

exports.execute = async (args) => {
  const vscode = args.require('vscode');

  let targetHost = await vscode.window.showInputBox({
    prompt: 'Type the target host',
    placeHolder: 'Leave blank to deploy to all configured hosts',
  });
  if ('undefined' === typeof targetHost) {
    return;
  }
  targetHost = targetHost.trim();

  let command = 'vendor/bin/dep deploy';
  if ('' !== targetHost) {
    command += ` ${targetHost}`;
  }

  const terminal = vscode.window.createTerminal('deploy');
  terminal.sendText(command);
  terminal.show();
};

Add support for onWillSaveTextDocument

Powertools only supports triggering a script when the file is changed or saved. It would be really handy to be able to trigger on the onWillSaveTextDocument event as well.

Feature request: commands in menus

Would it be possible to let us configure certain commands to be available in file-explorer context menus?

I'm not sure whether vscode allows extensions to add context-menu commands dynamically. But if so, this would allow us to write commands that work on directories, not just files, and make it easier to run them.

Create new global command command

Sorry if the title is not clear. I'm not sure how to better word it.
The request is to add a command that allows you to create a new global command (or button,or script).
If my understanding is correct, you need to edit settings.json, add it there, and then create a file inder the .vscode-powertools home folder. Right?
It would be awesome (and more new users friedly) to have a command taking care of that.

Regards

Move to next space

I am trying to use the previous examples you posted for me, but I couldn't work this out.. the function I am trying is to go to the next space from the cursor position. This is what I have so far.

In my settings.json I have:

    "ego.power-tools": {
        "buttons": [
            {
                "text": "Go to next space",
                "action": {
                    "type": "script",
                    "script": "C:/Users/robert.bram/AppData/Roaming/Code/User/test_button.js"
                }
            }
        ]
    }

In the status bar I now see four "Go to next space" buttons!

vsCodeButtons

In the referenced test_button.js file I have:

exports.execute = async (args) => {
   const vscode  = args.require('vscode');

   goToNextSpace(args);

   vscode.window.showInformationMessage(
       await getClipboardText(args)
   );
}


// go to next space
function goToNextSpace(args) {
   const vscode = args.require('vscode');
   const regEx = /\s/;
   const ACTIVE_EDITOR = vscode.window.activeTextEditor;
   const text = ACTIVE_EDITOR.document.getText();
   const match = regEx.exec(text);
   const nextPos = ACTIVE_EDITOR.document.positionAt(match.index);

   return ACTIVE_EDITOR.document.getText(new vscode.Range(
      nextPos
   ));
}

When I press one of the buttons I get:

Could not execute button: [Error] 'Invalid arguments'

Any ideas?

Rob
:)

Run command as variable

I see the use of these custom commands and I would like to use it in my launch.json as a variable like so "cd ${command:ego.power-tools.commands.my_command}"

With a command that actually has a return statement:

// my_command.js
exports.execute = async (args) => {
    return "hello"
};

Would something like that be possible with these power tools?

Changelog View

Just want to start by saying this could be one of the best ideas for an outside the box extension that exists, I have a million ideas already.

But... could you please make the changelog view logic configurable to be able to be turned off. It's such a small thing and I'm really not trying to nit-pick dumb little things but it probably happened to me 3 or 4 times in the last day as I synced it to my home and work and you pushed an update or whatever. I use an all black theme for VScode and when it was the middle of the night in a dark room it really kind of felt like one of those videos online where you are watching it and the face pops up out of nowhere and screams loudly. That's a complete exaggeration really, but either way even if you ignore this and close it I'll still use your extension and tell everyone I know it's sweet. Just don't update it at night with the lights off.

Commands and buttons no longer working

The following configuration was previously working, but it seems like recent updates to VSCode have introduced problems for powertool commands and buttons.

Repro steps:
Follow the instructions on the powertools wiki to create a button.

Expected:
A button appears on the toolbar.

Actual:
No button appears (even after a reload).

VSCode:

Version: 1.33.1 (user setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17763

Powertools:

Name: Power Tools
Id: ego-digital.vscode-powertools
Description: A set of useful and handy tools for Visual Studio Code.
Version: 0.40.0
Publisher: e.GO Digital GmbH
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ego-digital.vscode-powertools

Note that I originally discovered the problem when attempting to executed a command that had worked in earlier versions of VSCode and Powertools.

How to use VS-Commands for a button?

I see buttons can launch external .js or execute shell-commands, but how about buttons as shortcuts to internal commands, such as workbench.action.toggleZenMode)?

where to find the ego_log message?

These days I'm try to handle the usage of power-tools.
It's so great!

I try to create an app, and debug using vscode.window.showInformationMessage().
I wonder other effective debug method.

In this doc
https://github.com/egodigital/vscode-powertools/wiki/Apps#scripting
said ego_log().

  • But where to see the log message ?

  • Could you give me some advise ? thx!

  • I saw the script generated by Power Tools: Scripts - new script command, finding $helpers.GET() api within.
    could it be invoked in App ?

Cannot save to globalStore

I am trying to save some state variable from a script, but this is not working:

exports.execute = async (args) => {
    await args.globalStore.set("current_platform", "test");
    var platform = args.globalStore.get("current_platform", "test failed");
    log(platform)
}

The platform variable always reports "test failed"; am I misinterpreting how this works?

It does not work with workspaces

I know the title is a bit confusing, but I think it is VSCode fault to use workspaces to refer to two different things. You can understand workspace as the current working directory, and that is fine, but also I can refer to a combination of several directories added to the same workspace that it is then saved to a xxx.workspace file. In this last scenario, it is not possible to define commands for the current workspace, or at least it is not documented how to do.
Even if the workspace is a subset of an actual bigger folder that contains a .vscode folder the extension will not be able to find the defined commands.

Not sure if this can be fixed, but I think it was worth mentioning.
Regards

Can't create files?

Hello, I'm trying to add a custom command to setup new projects for me (since they all require some initial setup).

The problem is that if I try to create a file or whatnot it doesn't, or at least it doesn't where I expected it to.

You can fine the gist with the code here.

Maybe it's because I'm not actually changing working directories correctly? If so, how can I do that?

onEvent on.close not working

I put this lines of code inside given my_app.js

        case 'on.shown':
            // web view has went to the foreground
            vscode.window.showInformationMessage(
                'From WebView: Going to Shown'
            );
            break;

        case 'on.close':
            // the web view is going to be closed
            vscode.window.showInformationMessage(
                'From WebView: Going to Close'
            );
            break;

1. Found Behavior
I was expecting some information Message by clicking X button in file tabs. But I did not see any of it.

Conversely, when I open another Editor and reopen previous Webview, I can see information Message.

2. Significant use Case
Later, I will use this mechanicsm to prevent closing Webview conditionally.

3. Assumptions
But most likely, event onclose cannot be captured in current API.

Is there any workaround ?

I also tried to use this code, but also didnt work

window.onbeforeunload = function(){
    console.log('closing shared worker port...');
    return 'Take care now, bye-bye then.';
  };

toolbar is shown in 1st instance only

Occasionally I run 2 instances of VSC. The pt-toolbar isn't shown in the 2nd instance. I got so used to it that I really miss the added functionality it provides! ;) Is there any chance to always show it?

`document.opened`-event seems to be not handled (or not triggered)

I'm trying to write some code that would be executed when a file was opened. So I took a slow start and tried your sample that responds to file.changed. Once I had that working, I simply went ahead and changed the type-param to document.opened - and nothing happens when I open a file of the specified type (which previously responded fine to file.changed.)

lodash not found

I am getting an error with the extension. Am I required to install npm and such to install lodash?

[2020-01-28 09:40:28.770] [exthost] [error] Activating extension ego-digital.vscode-powertools failed due to an error:
[2020-01-28 09:40:28.772] [exthost] [error] Error: Cannot find module 'lodash'
Require stack:
- c:\Users\mjvk\.vscode\extensions\ego-digital.vscode-powertools-0.56.2\out\commands.js
- c:\Users\mjvk\.vscode\extensions\ego-digital.vscode-powertools-0.56.2\out\extension.js
- c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-fork.js
	at Function.Module._resolveFilename (internal/modules/cjs/loader.js:627:15)
	at Function.Module._load (internal/modules/cjs/loader.js:531:27)
	at Function.t._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:818:851)
	at Function.n._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:789:164)
	at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:785:618)
	at Module.require (internal/modules/cjs/loader.js:685:19)
	at n (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:15:524)
	at Object.<anonymous> (c:\Users\mjvk\.vscode\extensions\ego-digital.vscode-powertools-0.56.2\out\commands.js:19:11)
	at Module.o._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:15:749)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
	at Module.load (internal/modules/cjs/loader.js:645:32)
	at Function.Module._load (internal/modules/cjs/loader.js:560:12)
	at Function.t._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:818:851)
	at Function.n._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:789:164)
	at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:785:618)
	at Module.require (internal/modules/cjs/loader.js:685:19)
	at n (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:15:524)
	at Object.<anonymous> (c:\Users\mjvk\.vscode\extensions\ego-digital.vscode-powertools-0.56.2\out\extension.js:21:22)
	at Module.o._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:15:749)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
	at Module.load (internal/modules/cjs/loader.js:645:32)
	at Function.Module._load (internal/modules/cjs/loader.js:560:12)
	at Function.t._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:818:851)
	at Function.n._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:789:164)
	at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:785:618)
	at Module.require (internal/modules/cjs/loader.js:685:19)
	at require (internal/modules/cjs/helpers.js:16:16)
	at Function.s [as __$__nodeRequire] (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:32:963)
	at d._loadCommonJSModule (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:790:289)
	at d._doActivateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:694:547)
	at d._activateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:693:582)
	at Object.actualActivateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:691:534)
	at d._activateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:517:21)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:516:632
	at Array.map (<anonymous>)
	at d._activateExtensions (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:516:620)
	at d.activateById (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:514:709)
	at d._activateById (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:692:345)
	at d.$activate (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:700:721)

Button not working

I created a button with the following configuration (in the Workspace settings):

"ego.power-tools": {
			
		"commands": 
		{
			"select_platform":
			{
				"script": "commands\\ns-commands.js",
				"button": {
					"text": "Change platform",
					"tooltip": "Change build and deploy platform",
				}
			},
		}
}

But when I click on it, I get this error:
button_error
If I lauch the command from the command palette, though, the command executes correctly.
Am I missing something?

User, workspace and folder settings override each other

Currently you can set "ego.power-tools" settings at the user preferences, workspace and folder levels, which is great. Folder takes precedence over workspace which takes precedence over user preferences, however, your settings are completed overridden on that order, even if they are not conflicting.

For instance:

  • user preferences:
{
    "ego.power-tools": {
        "buttons": [
            {
                "text": "Button 1",
                "action": {
                    "type": "script",
                    "script": "my_button1.js"
                }
            }
        ]
    }
}
  • workspace:
{
    "ego.power-tools": {
        "buttons": [
            {
                "text": "Button 2",
                "action": {
                    "type": "script",
                    "script": "my_button2.js"
                }
            }
        ]
    }
}
  • folder:
{
    "ego.power-tools": {
        "buttons": [
            {
                "text": "Button 3",
                "action": {
                    "type": "script",
                    "script": "my_button3.js"
                }
            }
        ]
    }
}

Only "Button 3" is rendered.

I'd even argue that it would be totally fine to just show buttons with the same name when they're defined in different levels.

File explorer and context menus - context menu item name

Hello,

For a custom command related to the file explorer, I've followed this example : https://github.com/egodigital/vscode-powertools/wiki/Commands#file-explorer-and-context-menus

I would like to know if it could be possible to use the name (« Open external » in my example) of the command instead of the too generic label « Execute Power Command » ?

Here the comand config :

    "ego.power-tools": {
        "commands": {
            "papsou.open-external": {
                "name": "Open external",
                "script": "~/open-in-app.js",
                "forFile": true,
            }
        }
    },
// open-in-app.js
exports.execute = function(args) {
    const { exec } = require('child_process')

    if (args.file !== undefined) {
        exec('xdg-open "' + args.file.fsPath + '"')
    }

    return 42
}

20191009-104243

Support button icons?

Hi, what a great extension! I'm trying to use the Buttons feature and it would be great if I could specify an icon. The Commands extension uses something like this:

"text": "$(terminal) Show terminal"

Any icon from Octicons can be used there. Do you think this could be supported in Power Tools as well?

"IF" condition not working

The cron job is supposed to run every minute and see if the file.txt is present or not. But for some reason, it's not working at all. Please can anyone help? File name is correct

{
"ego.power-tools": {
"jobs": [
{
"name": "Form job",
"description": "Form Bot Runs Every 60 seconds.",
"time": "1 * * * * *",
"autoStart": false,
"action": {
"type": "script",
"script": "indeeeeex.js",
"if": " !$fs.existsSync( $v['workspaceRoot'] + '/file.txt' ) "
}
}
]
}
}

Run command as variable with arguments

I've looked over this issue #27 , but I still could not figured out how to pass argument to command.

I've tried this:

"inputs": [
        {
            "id": "blaze_test_target",
            "type": "command",
            "command": "getBlazeTestTarget",
            "args": {
                "baz": "baz1",
                "yoo": "foo",
            }
        },
    ],

and I've tried to access the args by

exports.execute = async (args) => {
    return "hello" + args.arguments['baz'];
};

I've tried args.baz, args['baz'], args.arguments['baz'], args.arguments.baz... None of them works.

Using a single .js script for use with multiple commands

Is it possible to have a single .js script containing multiple commands?

For example, I have one script called 'coolCommands.js' with the following commands:
coolCommand.show and
coolCommand.hide

Is it possible to integrate these commands into buttons ('Show Cool Command' and 'Hide Cool Command') and/or use the commands from VS Code commands?

-Rolf

Adopt VS Code's 'asWebviewUri' API

Hi, I maintain VS Code's Webview API

Issue

Our telemetry suggests that your extension uses webviews and may be loading resources in these webviews using hardcoded vscode-resource: URIs. These URIs have some important limitations and don't work properly when VS Code is run in a browser. We are also making changes in the desktop version of VS Code that may cause these URIs to not work properly in future versions of VS Code.

While we are making our best effort to continue support existing webview extensions that use vscode-resource: URIs on desktop versions of VS Code, we will not able to fully support all uses cases.

Fix

To ensure that your extension continues to work in as many environments as possible—including on web and remotely—please:

These APIs shipped around 2 years ago so they should be available in all modern versions of VS Code. You can find additional information about the issue here: microsoft/vscode#97962

Let me know if you have any questions about this change

Possible to "remap"/"conditionalize" close tab - to make files "pinned"/unclosable?

Would it be possible somehow to use the vscode-powertools to "pin" certain files, so that they won't close with cmd+w (on mac)?

I'm thinking to remap cmd+w to a powertool somehow, and make it call the vscode default close action, but first compare the file path with a simple list of files (".vscode-pinned-files") to see if the files are there. I can make a safe-to-close.sh shell script myself, returning zero if the file passed shall be closed and non-zero if not, but I wouldn't know how to get the actual file name within js/vscode/powertools, and code the logic to handle the shell script return status.

Sorry to put this in the issues section - is there a better place?

This feature is a long standing feature-request in the official vscode forum; implementing it and posting a solution there would make a lot of people happy :)

(I have a huge Home Assistant configuration split to a lot of files, and I'm having a hard time configuring vscode the way I want the config - which files in which split pane, if I close a file I didn't mean to close, upon reopen it opens in the wrong pane, etc. Trying to learn some powertools to mitiagate this! Thanks for a great plugin for vs code.)

Buttons are duplicated

Version: 1.33.1 (system setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17763
using V0.40.0

Today I noticed that the buttons that I defined appear twice:
image

And the settings for these:

  "ego.power-tools": {
          "buttons": [
              {
                  "text": "$(file) DyaEdit",
                  "ifFile": "(.dyalog|.mipage)$",
                  "priority": 1000,
                  "tooltip": "Opens the Dyalog Editor from 17.1 on current file",
                  "action": {
                      "type": "shell",
                      "command": "\"C:/Program Files/Dyalog/Dyalog APL-64 17.1 Unicode/dyaedit.exe\" ${activeFile}"
                  },
                  "onEditorChanged": " $v['button'].update() "
              },
              {
                "text": "$(device-desktop) Zen",
                "priority": 1001,
                "action": {
                    "type": "command",
                    "command": "workbench.action.toggleZenMode"
                }
            },{
                "text": "$(arrow-up) Split up",
                "priority": 1002,
                "action": {
                    "type": "command",
                    "command": "workbench.action.splitEditorUp"
                }
            },{
                "text": "$(primitive-square) Single",
                "priority": 1003,
                "action": {
                    "type": "command",
                    "command": "workbench.action.editorLayoutSingle"
                }
            },
              {
                "text": "$(markdown) Preview",
                "priority": 1004,
                "action": {
                   "type":"command",
                   "command": "markdown.showPreviewToSide"
                },
                "tooltip": "Open markdown preview",
                "ifFile": "(.md)$",
                "onEditorChanged": " $v['button'].update() "
            },{
                "text": "$(arrow-left) ",
                "priority": 1007,
                "tooltip": "Goto previous edit",
                "isRight": true,
                "action": {
                    "type": "command",
                    "command": "editsHistory.moveCursorToPreviousEditInSameFile"
                }
            },
            {
                "text": "$(arrow-right) ",
                "priority": 1006,
                "tooltip": "Goto next edit",
                "isRight": true,
                "action": {
                    "type": "command",
                    "command": "editsHistory.moveCursorToNextEditInSameFile"
                }
            }            
          ]          
      }

require custom modules

In a custom command, can I "require" my own modules?

I tried something like this in my command script:

exports.execute = function (args) {
	console.log(require('./foo'));
};

and this in foo.js, in the same directory:

exports = {
	foo: true
};

But it logs an empty object when I run the command.

It does seem to be loading the module, since if I change it to an invalid module name, I get a "cannot find module" error instead.

Sequence of buttons changes

I defined the following btns:

"buttons": 
[
              {
                  "text": "$(file) DyaEdit",
                  "ifFile": "(.dyalog|.mipage)$",
                  "tooltip": "Opens the Dyalog Editor from 17.1 on current file",
                  "action": {
                      "type": "shell",
                      "command": "\"C:/Program Files/Dyalog/Dyalog APL-64 17.1 Unicode/dyaedit.exe\" ${activeFile}"
                  },
                  "onEditorChanged": " $v['button'].update() "
              },
              {
                "text": "$(device-desktop) Zen",
                "action": {
                    "type": "command",
                    "command": "workbench.action.toggleZenMode"
                }
            },{
                "text": "$(arrow-up) Split up",
                "action": {
                    "type": "command",
                    "command": "workbench.action.splitEditorUp"
                }
            },{
                "text": "$(primitive-square) Single",
                "action": {
                    "type": "command",
                    "command": "workbench.action.editorLayoutSingle"
                }
            },
              {
                "text": "$(markdown) Preview",
               "action": {
                   "type":"command",
                   "command": "markdown.showPreviewToSide"
                },
                "tooltip": "Open markdown preview",
                "ifFile": "(.md)$",
                "onEditorChanged": " $v['button'].update() "
            }
          ]

wich looks like this:

image

However, after clicking "Up", the toolbar gets rearranged and the icon from another extension gets in between them:

image

I don't know if you have control over that - but obviously it would be nice if all PT-icons would be grouped together...and not change their positions.

Set cwd for button shell command?

On windows, currently all shell commands are executed in the C:\Users\me\.vscode-powertools folder.

How do I force executing a command in the folder of current VSCode session?

{
"buttons": [   
    {
        "text": "$(pulse)",
        "action": {
            "type": "shell",          
            "command": "\"powershell.exe\" \"dir\"",
            "silent": false,
            "cwd": "${workspaceRoot}"
        }
    }
]
}

returns me

Running shell command '"powershell.exe" "dir"' ... [FAILED: '[Error] 'spawn C:\WINDOWS\system32\cmd.exe ENOENT'']

Re-using modules consumed by PowerTools || "cannot find module"

What

Hi friends,

I'm running into module inclusion issues, as if a module previously imported by PowerTools does not exist or is otherwise not accessible from the current context within a script.

Example in the meat of the post.

Why

I'm looking to create a command to basically "beautify selection" so that I have a quick command to run Beautify against selected javascript text embedded within languages that do not have embedded-language formatting support ( e.g., Haml )

I may simply be going about this the wrong way, but my presumption was along the lines of:

  • PowerTools already includes the beautify module to provide utilities such as $beautify,
  • These scripts are run in the context of PowerTools itself
  • I should be able to include/require the module in-kind and utilize the functionality without requiring additional dependencies to be installed, nice!

Narrator: He could not.

How

Given the following command:

"commands": {
  "beautify-selection": {
    "name": "Beautify Selection",
    "description": "Formats the selection using beautify",
    "script": "scripts/format-as-js.js",
    "forFile": true
  }
}

And the following script:

// import * as beautify from 'js-beautify'; // "cannot find module 'js-beautify'"

exports.execute = async (args) => {
  const vscode = args.require('vscode');
  const beautify = require('js-beautify').js; // "cannot find module 'js-beautify'"
  const ACTIVE_EDITOR = vscode.window.activeTextEditor;

  activeSelection = ACTIVE_EDITOR.document.getText(ACTIVE_EDITOR.selection.active);

  beautifiedSelection = beautify(activeSelection);

  ACTIVE_EDITOR.edit(builder => {
    builder.insert(
      ACTIVE_EDITOR.selection.active, beautifiedSelection
    );
  });
}

The following error is produced:

[Error] 'Cannot find module 'js-beautify'
Require stack:
- /Users/fire/projects/.vscode/scripts/format-as-js.js
- /Users/fire/.vscode/extensions/ego-digital.vscode-powertools-0.59.0/out/helpers.js
- /Users/fire/.vscode/extensions/ego-digital.vscode-powertools-0.59.0/out/data.js
- /Users/fire/.vscode/extensions/ego-digital.vscode-powertools-0.59.0/out/commands.js
- /Users/fire/.vscode/extensions/ego-digital.vscode-powertools-0.59.0/out/extension.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js'

Then

If raw dependency reuse actually isn't expected, it would be nice to see beautify exposed from PowerTools directly, akin to the other utility libraries noted at the bottom of the tools page

NOTE: I did look at $beautify, but it opens a new editor window and has no configurable settings, which is undesirable for this use case. It is actually what gave me the idea to try and re-use the existing imports, however.

Do commands need to run on saved files/folders?

If I have an editor open for an untitled file, and I run "Power Tools: Execute Power Command", it shows me an error like '/Untitled-1' does not exist!.

Is it possible to run a command on an un-saved file? My use case is that I want to make some text-processing commands that just operate on the selected text, regardless of whether it's saved in a file.

Text manipulation within document?

I couldn't see any obvious answer to this within the wiki, but can I use this tool to create macros that can manipulate text with the document such as:

  • go to start/end of file
  • move cursor within file
  • regex find/replace up/down from cursor
  • regex find/replace within text in the clipboard or some other buffer (not the file itself)
  • paste text within the file

Is there a value/placeholder for current active file path?

For Example, how can I make a button to open current editing file in notepad.exe?

{
    "ego.power-tools": {
        "buttons": [
            {
                "text": "open in notepad'",
                "action": {
                    "type": "shell",
                    "command": "/path/to/notepad.exe ${activeFile}"
                }
            }
        ]
    }
}```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.