Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,52 @@
"version": "0.2.0",
"configurations": [
{
"name": "PSEdit: Launch with Example Theme",
"name": "PSEdit (Pwsh): Launch with Example Theme",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "pwsh",
"args": [
"-NoExit",
"-Command",
"& { Import-Module .\\psedit.psd1; Show-PSEditor -ConfigurationFile ..\\psedit.json }"
"& { Import-Module .\\psedit.psd1; Show-PSEditor -ConfigurationFile ${workspaceFolder}\\example.psedit.json }"
],
"cwd": "${workspaceFolder}\\bin\\Debug\\netstandard2.0\\publish",
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Launch with Example Theme",
"name": "PSEdit (PowerShell): Launch with Example Theme",
"type": "clr",
"request": "launch",
"preLaunchTask": "build",
"program": "powershell",
"args": [
"-NoExit",
"-Command",
"& { Import-Module .\\psedit.psd1; Show-PSEditor -ConfigurationFile ${workspaceFolder}\\example.psedit.json }"
],
"cwd": "${workspaceFolder}\\bin\\Debug\\netstandard2.0\\publish",
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": "PSEdit (Pwsh): Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "pwsh",
"args": [
"-NoExit",
"-Command",
"& { Import-Module .\\psedit.psd1; Show-PSEditor -ConfigurationFile ${workspaceFolder}\\example.psedit.json }"
"& { Import-Module .\\psedit.psd1; Show-PSEditor}"
],
"cwd": "${workspaceFolder}\\bin\\Debug\\netstandard2.0\\publish",
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Launch (console)",
"name": "PSEdit (PowerShell): Launch (console)",
"type": "clr",
"request": "launch",
"preLaunchTask": "build",
Expand Down
59 changes: 42 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
## PSEdit
## PSEdit

Edit PowerShell scripts directly in your terminal.
Edit PowerShell scripts & JSON/YAML files directly in your terminal.

![](./screenshot.png)
![](./psedit_demo.gif)

- IntelliSense
- Syntax Higlighting
- Format on Save
- Script Execution
- Error View
- Syntax Error View

## Installation

Expand All @@ -18,7 +12,6 @@ This module is available on the [PowerShell Gallery](https://www.powershellgalle
```powershell
Install-Module psedit
```

## Editing

To start the editor, you can simply call `Show-PSEditor` in a terminal.
Expand All @@ -33,21 +26,53 @@ You can open a file by using the `-Path` parameter.
Show-PSEditor -Path .\file.path
```

### Syntax Errors
You can also use the `psedit` alias.
```powershell
psedit
```

Syntax errors will be shown in the editor by a red highlight. To view the text of the syntax error, click View \ Syntax Errors.

### Formatting
## Features

- IntelliSense
- Syntax Higlighting
- Format on Save
- Script Execution
- Error View
- Syntax Error View

## Language support

You can format your code in the editor if you have `PSScriptAnalyzer` installed. To format a script, either press `Ctrl+Shift+R` or click Edit \ Format. If you don't have `PSScriptAnalyzer` installed, you can do so with the command below.
| Language | IntelliSense | Syntax Highlighting | Formatting | Run Code |
| ------------- | ------------ | ------------------- | ---------- | -------- |
| PowerShell | ✔ | ✔ | ✔* | ✔ |
| JSON | ✖️ | ✔ | ✔ | |
| YAML | ✖️ | ✔ | ✔ | |

All other text based files are supported, and will be treated as plain text files.

(* Requires `PSScriptAnalyzer` to be installed)

You can only format your PowerShell code in the editor if you have `PSScriptAnalyzer` installed. To format a script, either press `Ctrl+Shift+R` or click Edit \ Format. If you don't have `PSScriptAnalyzer` installed, you can do so with the command below.

```powershell
Install-Module PSScriptAnalyzer
```

## Theme Support
### Syntax Errors

Syntax errors will be shown in the editor by a red highlight. To view the text of the syntax error, click View \ Syntax Errors.

### Theme Support

PSEdit supports customizable themes via a `psedit.json` file in My Documents folder, or in the working directory.

You can also provide a ConfigurationFile parameter to `psedit` to specify a custom location for the theme file.
```powershell
psedit -ConfigurationFile ".\mytheme.json"
```

PSEdit supports customizable themes via a `psedit.json` file in the working directory. If the file is not present, a default theme is used. The theme file allows you to override editor colors for backgrounds, text, errors, and more.
If the file is not present, a default theme is used. The theme file allows you to override editor colors for backgrounds, text, errors, and more.

### Example psedit.json

Expand All @@ -71,7 +96,7 @@ PSEdit supports customizable themes via a `psedit.json` file in the working dire

If a color key is missing, the default value will be used. Changes to the theme file are loaded automatically when the editor starts.

## Execution
## Running code

To execute your script, press `F5` to run the entire script. If you want to execute a select, you can press `F8`. You can also execute the script in the terminal and exit the editor by pressing `Ctrl+Shift+F5`.

Expand Down
33 changes: 26 additions & 7 deletions ShowEditorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,34 @@ public class ShowEditorCommand : PSCmdlet
public SwitchParameter DisableFormatOnSave { get; set; }

protected override void BeginProcessing()
{
// Load theme from specified config file or default location
string configPath = ConfigurationFile;
if (string.IsNullOrEmpty(configPath))
{
string configPath = "";
if (!string.IsNullOrEmpty(ConfigurationFile))
{
// evaluate provided config path
configPath = GetUnresolvedProviderPathFromPSPath(ConfigurationFile);
if (!File.Exists(configPath))
{
throw new ArgumentException("Invalid filepath provided for Configuration File");
}
}
else
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
configPath = System.IO.Path.Combine(documents, "psedit.json");
// evaluate if theme exists in My Documents
var myDocumentsThemePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "psedit.json");
if (File.Exists(myDocumentsThemePath))
{
configPath = myDocumentsThemePath;
}
// evaluate if theme exists in working directory
var workingDirectoryThemePath = GetUnresolvedProviderPathFromPSPath("psedit.json");
if (File.Exists(workingDirectoryThemePath))
{
configPath = workingDirectoryThemePath;
}
}
if (File.Exists(configPath))
// Load theme from specified config file or default location
if (!String.IsNullOrEmpty(configPath))
{
ThemeService.Instance.LoadTheme(configPath);
}
Expand Down
Binary file added psedit_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshot.png
Binary file not shown.