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
6 changes: 6 additions & 0 deletions quick-commands/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.3.2 - 2026-10-06

- Placeholders can now ask the user for a value to substitute. This
makes it possible to quickly add larger pieces of text where some
parts are dynamic.

## 0.3.1 - 2026-10-04

- `\u`_XXXX_ will complete to the Unicode character whose code point is
Expand Down
46 changes: 24 additions & 22 deletions quick-commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,30 @@ smile smile\u263a\nand again

In the completions you can use a number of _placeholders_ to obtain substitutions for actual date and time values (table adapted from [QOwnNotes](https://www.qownnotes.org/scripting/methods-and-objects.html#formatting-dates-and-times):

| Placeholder | Meaning | Example |
| :----------- | :---------------------|:-------------- |
| `{yyyy}` | Year with four digits | 2026 |
| `{yy}` | Year with two digits | 26 |
| `{MM}` | Month with leading zero | 09 |
| `{M}` | Month without leading zero | 9 |
| `{MMM}` | Abbreviated localized month name | Sep |
| `{MMMM}` | Full localized month name | September |
| `{dd}` | Day with leading zero | 05 |
| `{d}` | Day without leading zero | 5 |
| `{ddd}` | Abbreviated localized day name | Tue |
| `{dddd}` | Full localized day name | Tuesday |
| `{HH}` | Hour (0-23) with leading zero | 07 |
| `{hh}` | Hour with leading zero (1-12 with AP) | 07 |
| `{mm}` | Minute with leading zero | 04 |
| `{ss}` | Second with leading zero | 09 |
| `{AP}` / `{ap}` | AM/PM or am/pm | AM |
| `{w}` | ISO week number without leadign zero | 5 |
| `{ww}` | ISO week number with leadign zero | 05 |
| `{LC:locale}` | Use the given locale | `{LC:nl_NL}`|
| `{+:offset}` | Offsets the date to the future | `{+:1D}` |
| `{-:offset}` | Offsets the date to the past | `{-:1D}` |
| Placeholder | Meaning | Example |
|:------------------|:--------------------------------------|:--------------------------|
| `{yyyy}` | Year with four digits | 2026 |
| `{yy}` | Year with two digits | 26 |
| `{MM}` | Month with leading zero | 09 |
| `{M}` | Month without leading zero | 9 |
| `{MMM}` | Abbreviated localized month name | Sep |
| `{MMMM}` | Full localized month name | September |
| `{dd}` | Day with leading zero | 05 |
| `{d}` | Day without leading zero | 5 |
| `{ddd}` | Abbreviated localized day name | Tue |
| `{dddd}` | Full localized day name | Tuesday |
| `{HH}` | Hour (0-23) with leading zero | 07 |
| `{hh}` | Hour with leading zero (1-12 with AP) | 07 |
| `{mm}` | Minute with leading zero | 04 |
| `{ss}` | Second with leading zero | 09 |
| `{AP}` / `{ap}` | AM/PM or am/pm | AM |
| `{w}` | ISO week number without leadign zero | 5 |
| `{ww}` | ISO week number with leadign zero | 05 |
| `{LC:locale}` | Use the given locale | `{LC:nl_NL}` |
| `{+:offset}` | Offsets the date to the future | `{+:1D}` |
| `{-:offset}` | Offsets the date to the past | `{-:1D}` |
| `{input:msg}` | Asks the user for an answer to _msg_. | `{input:What colour}` |
| `{input:msg:def}` | Same, but with a default value. | `{input:What colour:red}` |

The date offsets may be a number of days, as shown above, or a number of milliseconds. `1D` is equivalent to `86400000`.

Expand Down
2 changes: 1 addition & 1 deletion quick-commands/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"script": "quick-commands.qml",
"authors": ["@LockeBirdsey","@sciurius"],
"platforms": ["linux", "macos", "windows"],
"version": "0.3.1",
"version": "0.3.2",
"minAppVersion": "25.4.1",
"description": "Short commands to help with repetive and/or annoying things to write frequently such as timestamps.\n\nEach command starts with a backslash (\\) and a single word for the command. Select the autocomplete option you desire and the command text will be replace.\n\nDefault commands are: today, tomorrow, yesterday, now, week.\n\nCustom commands can also be specified. Each line starts with the command name followed by one or more replacement values separated by spaces. Enclose multi-word values in double quotes, for example: myname \"Firstname Lastname\". Date and time values can be substituted with {dd}, {MM} and so on.\n\nReplacement values may have escaped newlines \"\\n\" and Unicode characters in the form \"\\uXXXX\".",
"resources": ["command-parser.js"]
Expand Down
29 changes: 24 additions & 5 deletions quick-commands/quick-commands.qml
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ Script {
// script.log("x:" + x);

if ( x.length == 2 ) { // ctrl:value
let ctrl = x[0];
const ctrl = x[0].toLowerCase();
let value = x[1];

if ( ctrl.toLowerCase() == "lc" ) {
if ( ctrl == "lc" ) {
// Set a locale for substitutions.
locale = Qt.locale(value);
script.log("locale:" + locale);
Expand All @@ -186,19 +186,38 @@ Script {

if ( ctrl == "+" || ctrl == "-" ) {
// Date offset, millisecs or nnD.
let now = new Date().getTime();
const now = new Date().getTime();
if ( value.endsWith("D") ) {
value = parseInt(value) * 24*60*60*1000;
}
else {
value = parseInt(value);
}
date = new Date( now + value );
date = new Date( ctrl == "+" ? now + value : now - value );
//script.log("date " + date);
continue;
}

if ( ctrl == 'input' ) {
result +=
script.inputDialogGetText("Query", value, "" );
continue;
}
}
console.error("Invalid substitution control: " + m[0]);

else if ( x.length == 3 ) { // ctrl:value:arg
const ctrl = x[0].toLowerCase();
const value = x[1];
const arg = x[2];

if ( ctrl == 'input' ) {
result +=
script.inputDialogGetText("Query", value, arg );
continue;
}
}

console.error("Invalid substitution control: " + m[i]);
continue; // makes sense?
}
// Perform the substition.
Expand Down
Loading