Skip to content

Commit

Permalink
Merge branch 'main' into command-utils-issue-107
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoffens authored May 15, 2024
2 parents 552c77c + 27435c4 commit 2c1a987
Show file tree
Hide file tree
Showing 37 changed files with 1,496 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: [daretodave,dhoffens]
github: [mterm-io,daretodave,dhoffens]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand All @@ -10,5 +10,5 @@ liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: mterm
buy_me_a_coffee: #mterm
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [1.0.33-beta](https://github.com/mterm-io/mterm/compare/v1.0.32-beta...v1.0.33-beta) (2024-05-10)


### Bug Fixes

* add `:cmd` and `commands` to real time edit command file ([24c5e84](https://github.com/mterm-io/mterm/commit/24c5e84d5278357e6b1eab82729953a8e3cf2e11)), closes [#100](https://github.com/mterm-io/mterm/issues/100)
* added `:restart` command and made `:cmd` error handling better ([3c2ef2d](https://github.com/mterm-io/mterm/commit/3c2ef2d41c98cc062a7aa4e30b5165ef9ea93959)), closes [#103](https://github.com/mterm-io/mterm/issues/103)
* commander cleanup ([4d3f199](https://github.com/mterm-io/mterm/commit/4d3f1991b7795550b4643cc58e9806b743f29840))
* content api for frontend events from backend, ui updates and reset command ([#101](https://github.com/mterm-io/mterm/issues/101)) ([d8fbce5](https://github.com/mterm-io/mterm/commit/d8fbce56a8cff22e9e163eb282e8313dda350b63))
* custom commands now push to the history stack ([940b5d2](https://github.com/mterm-io/mterm/commit/940b5d23ac852371a4b5867318e0bc5466c5f826))
* developers rejoice! hmr for backend ([6349046](https://github.com/mterm-io/mterm/commit/6349046f6c51b2cfd917bf18610d25ba998b87b3))
* edit to use new prompt value ([235575d](https://github.com/mterm-io/mterm/commit/235575dd8f48131d69030604ef26ecc7d8ef0c91))
* history scroll ([#111](https://github.com/mterm-io/mterm/issues/111)) ([f38a80f](https://github.com/mterm-io/mterm/commit/f38a80f0d8d7a6edb80d46f0f353beab9770fcfb)), closes [#12](https://github.com/mterm-io/mterm/issues/12)
* prompt transformers and operators 🥇 ([533c5be](https://github.com/mterm-io/mterm/commit/533c5be18ecc4bc00c2c907e3ce4c9ba2db27e5b))

## [1.0.32-beta](https://github.com/mterm-io/mterm/compare/v1.0.31-beta...v1.0.32-beta) (2024-05-07)


Expand Down
172 changes: 170 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

![image](https://github.com/mterm-io/mterm/assets/7341502/6eb47f43-1ab5-41c5-9c0e-5eb61ce575bf)
![image](https://github.com/mterm-io/mterm/assets/7341502/27bcad62-6891-4b49-80b5-e5a17e0562ab)
![image](https://github.com/mterm-io/mterm/assets/7341502/ab7b3a97-98c0-4dda-aa39-af3d6a33d0f7)

**mterm** is a cross-platform command-line terminal that proxies the underlying command-line interpreters, such as [powershell](https://learn.microsoft.com/en-us/powershell/), [sh](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html) or [wsl](https://ubuntu.com/desktop/wsl). commands are executed in the background and results streamed to the foreground.

Expand All @@ -24,6 +25,13 @@ this means commands such as `ls`, `cd` or program commands such as `node -v` or

Head over to the [release page](https://github.com/mterm-io/mterm/releases/latest) to find the binary for your system type. mterm is evergreen and updates are automatically installed on your system as hey get released. Run `:v` to see your current mterm version.

### Autocomplete

Start typing, mterm will pick up your available: programs, [system commands](#system), [custom commands](#commands) and history

Finally, hit tab to finish the completion -
![image](./docs/assets/autocomplete.gif)

### Command Mode

By default, **mterm** opens in command mode (you can change this in [settings](#settings)). A couple of notes about command mode -
Expand Down Expand Up @@ -74,7 +82,8 @@ in this folder, there are a couple of important files to help configure mterm -

- `commands.ts`, used to attach commands to the terminal. see [commands](#commands)
- `package.json`, an npm package declaration for use by [commands](#commands)
- `settings`, general runtime settings [settings](#settings)
- `theme.css`, default theme used by the terminal, change this path/file with the `theme` property for profiles
- `settings.json`, general runtime settings [settings](#settings)

### Settings

Expand Down Expand Up @@ -147,6 +156,7 @@ mterm provided a few system commands to help control the terminal and settings.
| `:vault` | | Open the secret management tool, the mterm vault |
| `:version` | `:v` | Print the current mterm version |
| `:workspace` | | Open the mterm workspace folder on disk: `~/mterm` |
| `:theme` | `:css` | Edit the terminal theme real time |
| `:settings` | | Open the mterm settings gui to manage `~/mterm/settings.json` |
| `:settings edit` | | Open the `~/mterm/settings.json` in the terminal editor with hot reloading |
| `:settings reload` | | Reload `~/mterm/settings.json` and all ui etc associated with the settings |
Expand Down Expand Up @@ -191,7 +201,7 @@ export async function query(): Promise<{

> Note the return type is optional, just added above to highlight the typescript engine provided
Utilities
### Utilities

Shell (https://www.electronjs.org/docs/latest/api/shell) is provided within the command context, use shell like this:

Expand All @@ -204,6 +214,164 @@ to open URL:
to open editor
`await shell.openPath(`${editorCommand} ${filePath}`)`

### Transformers
Sometimes we need to change variables, execution results or perform an operation on strings.

MTERM helps solve this by providing `transformers` as terminal operators. These transformers abstract away somewhat tedious actions in the terminal, they also provide common utilities within the scope of a prompt

<img src="https://github.com/mterm-io/mterm/assets/7341502/d7a0cb6c-6c75-4183-9596-8b1295789d64" alt="drawing" width="250"/>

For the prompt of
```bash
":snake(this is some text)"
```

We get the result
```bash
this_is_some_text
```

`snake` is a mterm transformer that takes a string and converts it to [snake case](https://en.wikipedia.org/wiki/Snake_case)


Transformers can be used anywhere including from within transformers -

```bash
":upper(hmm) :lower(WOW) :snake(:lower(HMM WOW))"
```

Prints out -
```bash
HMM wow hmm_wow
```

#### Transformer Arguments

Some transformers accept arguments. Arguments for transformers are seperated by `:` colon characters

Here is the split transformer on a string -

```bash
":split(1,2,3,4:1:,)"
```
- `1,2,3,4` is the first argument, the split text
- `1` is the index to return (a [split operation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) is an array, so return a value from this array)
- `,` the final argument is the [delimiter](https://en.wikipedia.org/wiki/Delimiter)

> one way to view this operation is `"1,2,3,4".split(',')[1]`
Note you can use `"` quotes to wrap transformer arguments if there is a colon within the argument

#### Transformers Provided

Here are the provided transformers for use -

##### echo
> print out the argument, proxies the argument to the `echo` on the terminal
`:echo` examples -
```bash
:echo(HELLO) -> "HELLO"
:echo(:upper(hello)) -> "HELLO"
```

##### get
> gets the argument from the [vault](#secrets), if not available gets the argument from the [environment variables](https://en.wikipedia.org/wiki/Environment_variable) from the host machine, if not available returns the fallback
`:get` examples -
```bash
# e.g: Basic find
#
# assuming:
## there is a env variable called PATH=PATH_FROM_SYSTEM
:get(PATH) -> "PATH_FROM_SYSTEM"

# e.g: Fallback keys
#
# assuming:
## there is NOT a env variable called NOT_FOUND_A
## there is NOT a env variable called NOT_FOUND_B
## there is a env variable called FOUND_C=VALUE_OF_C
:get(NOT_FOUND_A,NOT_FOUND_B,FOUND_C) -> "VALUE_OF_C"

# e.g: Fallback variable
#
# assuming:
## there is NOT a env variable called NOT_FOUND_A
## there is a env variable called FOUND_C=VALUE_OF_C
:get(NOT_FOUND_A:im the fallback) -> "im the fallback"
:get(FOUND_C:im the fallback) -> "VALUE_OF_C"
```

##### lower
> transforms the argument to lowercase
`:lower` examples -
```bash
":lower(HELLO)" -> "hello"
:echo(:lower(HELLO)) -> "hello"
```

##### run
> runs the argument against the terminal and proxies the result
`:run` examples -
```bash

# e.g: Run command
#
# assuming:
# there is a `hello` function in `commands.ts`
# the `hello` function is declared as const hello = (arg = 'fallback') => `Hello, ${arg}!`
":run(hello)" -> "Hello, fallback!"
":run(hello argument)" -> "Hello, argument!"

# e.g: Run command within transformer
#
# assuming:
# there is a `hello` function in `commands.ts`
# the `hello` function is declared as const hello = (arg = 'fallback') => `Hello, ${arg}!`
":lower(:run(hello))" -> "hello, fallback!"
":lower(:run(hello)) :upper(:run(hello))" -> "hello, fallback! HELLO, FALLBACK!"
```

##### snake
> transforms the argument to snakecase
`:snake` examples -
```bash
":snake(HELLO WORLD)" -> "hello_world"
```

##### title
> transforms the argument to [titlecase](https://en.wikipedia.org/wiki/Title_case)
`:title` examples -
```bash
":title(hello world)" -> "Hello World"
":title(hello_world)" -> "Hello World"
```

##### split
> splits the provided argument, accepts the index or uses `0`, accepts the [delimiter](https://en.wikipedia.org/wiki/Delimiter) or uses `,`
`:split` examples -
```bash
":split(hello,world)" -> "hello"
":split(hello,world:1)" -> "world"
":split(hello@world:1:@)" -> "world"

:echo(":split(":get(xx,PATH)":0:;)") -> "FIRST_RESULT_IN_PATH"
```

##### upper
> transforms the argument to uppercase
`:title` examples -
```bash
":uppercase(hello world)" -> "HELLO WORLD"
```

### Secrets

Environment variables are a bit unsafe. You set these and leave the host machine all the ability to read and share these. Wonderful for services and backends, not the safest for personal usage.
Expand Down
Binary file added docs/assets/autocomplete.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mterm",
"version": "1.0.32-beta",
"version": "1.0.33-beta",
"description": "An Electron application with React and TypeScript",
"main": "./out/main/index.js",
"author": "mterm.io",
Expand All @@ -14,7 +14,7 @@
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
"typecheck": "npm run typecheck:node && npm run typecheck:web",
"start": "electron-vite preview",
"dev": "electron-vite dev",
"dev": "electron-vite dev -w",
"build": "npm run typecheck && electron-vite build",
"postinstall": "electron-builder install-app-deps",
"build:unpack": "npm run build && electron-builder --dir",
Expand Down
129 changes: 129 additions & 0 deletions resources/theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* Override themes for your terminal here
* See default here: https://github.com/mterm-io/mterm/blob/main/src/renderer/src/assets/runner.css
*/

/*
* prepend .runner-container__commander_mode
* to apply styles only for commander mode
*/
.runner-container {
background: rgba(27, 27, 31, 0.89);
color: white;
}
.runner-container__commander_mode .runner-result {
}

.runner-input-container {
}

.runner-input {
}

.runner-input-field {
}

.runner-input-field {
}
.runner-input-field:focus {
}

.runner-container {
}

.runner-tabs {
}

.runner-tabs-title {
}

.runner-tabs-title-active {
}
.runner-spacer {
}

.runner-context {
}

.runner-main {
}

.runner-editor {
}


.runner-editor-header {
}

.runner-editor-header-result {
}
.runner-editor-header-result::-webkit-scrollbar {
}
.runner-editor-header-result::-webkit-scrollbar-corner {
}
.runner-editor-header-result::-webkit-scrollbar-thumb {
}
.runner-editor-header-result pre {
}
.runner-context-folder {
}

.runner-history {
}

.runner-history::-webkit-scrollbar {
}
.runner-history::-webkit-scrollbar-corner {
}
.runner-history::-webkit-scrollbar-thumb {
}
.runner-history-item {
}
.runner-history-item:hover {
}
.runner-history-selected {
}
.runner-history-running {
}
.runner-history-complete {
}
.runner-history-aborted {
}
.runner-history-error {
}

.runner-history::-webkit-scrollbar-track {
}

.runner-result-error {
}
.runner-result {
}

.space {
}
.runner-info {
}
.toggle-button-slider {
}
.toggle-button-circle {
}
.toggle-button {
}
.toggle-button-spacer {
}
.toggle-button.toggle-button-on .toggle-button-slider {
}

.runner-result::-webkit-scrollbar {
}
.runner-result::-webkit-scrollbar-corner {
}
.runner-result::-webkit-scrollbar-thumb {
}
.contextmenu.tab-context-menu {
}
.tab-context-menu > .contextmenu__item {
}
.tab-context-menu > .contextmenu__item:hover {
}
Loading

0 comments on commit 2c1a987

Please sign in to comment.