Skip to content

Commit

Permalink
phone: shortcuts gcp command
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwhiting committed Dec 29, 2023
1 parent cc9a708 commit d638df7
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .obsidian/command-palette.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"pinned": [
"switcher:open",
"obsidian-linter:lint-file",
"custom-sort:enable-custom-sorting",
"insert-template",
"omnisearch:show-modal",
"omnisearch:show-modal-infile"
]
}
3 changes: 2 additions & 1 deletion .obsidian/community-plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"custom-sort",
"templater-obsidian",
"omnisearch",
"darlal-switcher-plus"
"darlal-switcher-plus",
"logstravaganza"
]
6 changes: 6 additions & 0 deletions .obsidian/plugins/cmdr/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"icon": "lucide-search",
"name": "Omnisearch: Vault search",
"mode": "any"
},
{
"id": "command-palette:open",
"icon": "lucide-terminal-square",
"name": "Command palette: Open command palette",
"mode": "any"
}
],
"macros": [],
Expand Down
199 changes: 199 additions & 0 deletions .obsidian/plugins/logstravaganza/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/main.ts
var main_exports = {};
__export(main_exports, {
default: () => LoggingNote
});
module.exports = __toCommonJS(main_exports);
var import_obsidian2 = require("obsidian");

// src/console-proxy.ts
var WINDOW_CONSOLE = window.console;
var ConsoleProxy = class {
constructor(options) {
const { app, logger } = options;
this.app = app;
this.logger = logger;
}
// Installing the console proxy object and the listener for uncaught errors
setup() {
const { logger } = this;
const consoleProxy = new Proxy(
window.console,
{
get: function(target, prop) {
const property = target[prop];
if (typeof property === "function") {
return function(...args) {
var _a, _b;
const sender = (_b = (_a = new Error().stack) == null ? void 0 : _a.split("\n").at(2)) == null ? void 0 : _b.replace(/^.+\((.+?)\).*$/, "$1").replace("app://obsidian.md/", "");
logger.log(prop, sender, ...args);
return property.apply(target, args);
};
}
return property;
}
}
);
window.console = consoleProxy;
window.addEventListener("error", this.onWindowError);
}
// Removing the console proxy object and the listener for uncaught errors
teardown() {
window.console = WINDOW_CONSOLE;
window.removeEventListener("error", this.onWindowError);
console.info(this.logger.prefixMsg("Proxy removed"));
}
/**
* Event handler for window errors. Adds a "fatal"-level log event to the log
* event queue.
*
* @param event - The error event object.
*/
onWindowError(event) {
const { message, colno, lineno, filename } = event;
const logMessage = `${message} (${filename}:${lineno}:${colno})`;
this.logger.log("fatal", logMessage);
}
};

// src/note-logger.ts
var import_obsidian = require("obsidian");

// src/device-helper.ts
function getDeviceName(app) {
var _a, _b;
const syncPlugin = (_b = (_a = app.internalPlugins) == null ? void 0 : _a.plugins["sync"]) == null ? void 0 : _b.instance;
if (!syncPlugin) {
return "Unknown device";
}
return syncPlugin.deviceName ? syncPlugin.deviceName : syncPlugin.getDefaultDeviceName();
}

// src/note-logger.ts
var NoteLogger = class {
constructor(app) {
this.PLUGIN_LOGGING_PREFIX = "Logstravaganza";
this.logEventsQueue = [];
/**
* Debounced function that processes log events by appending them to the note
* file.
*/
this.processLogEvents = (0, import_obsidian.debounce)(
() => {
this.app.workspace.onLayoutReady(async () => {
const { vault } = this.app;
const note = await this.getNoteFile();
const newLines = [];
let logEvent;
while (logEvent = this.logEventsQueue.shift()) {
const { timestamp, level, sender, args } = logEvent;
if (level === "_tableheader") {
newLines.push(
"",
"",
"| Timestamp | Originator | Level | Message |",
"| --------- | ---------- | ----- | ------- |"
);
continue;
}
const logMsg = args.map((arg) => typeof arg === "string" ? arg : JSON.stringify(arg)).join(" ").replace("|", "\\|");
newLines.push(
`| ${timestamp.toISOString()} | ${sender} | ${level} | ${logMsg} |`
);
}
await vault.process(note, (currentNoteContent) => {
return currentNoteContent + newLines.join("\n") + "\n";
});
});
},
1e3
);
this.app = app;
this.OUTPUT_FILENAME = `LOGGING-NOTE (${getDeviceName(app)}).md`;
}
/**
* Adds log events with the specified level and arguments to the log event
* array. This function triggers the processing function to write the log events
* to the note file.
*
* @param level - The level of the log event.
* @param sender - The sender of the log event (e.g., "plugin:whatever").
* @param args - The arguments to be logged, optional.
*/
log(level, sender, ...args) {
const timestamp = new Date();
this.logEventsQueue.push({ timestamp, level, sender, args });
this.processLogEvents();
}
/**
* Prefixes a message with the plugin logging prefix.
* @param msg - The message to be prefixed.
* @returns The prefixed message.
*/
prefixMsg(msg) {
return `[${this.PLUGIN_LOGGING_PREFIX}] ${msg}`;
}
/**
* Retrieves the note file with the specified path or creates a new one if it
* doesn't exist.
*
* @returns A `Promise` that resolves to a `TFile` representing the note file.
*/
async getNoteFile() {
const { vault } = this.app;
const note = vault.getAbstractFileByPath(this.OUTPUT_FILENAME);
if (note instanceof import_obsidian.TFile) {
return note;
} else {
return await vault.create(this.OUTPUT_FILENAME, "");
}
}
};

// src/plugin-info.ts
var PLUGIN_INFO = {
"pluginVersion": "1.2.0",
"pluginReleasedAt": "2023-07-23T19:58:08+0200"
};

// src/main.ts
var LoggingNote = class extends import_obsidian2.Plugin {
onload() {
const name = "plugin:logstravaganza";
this.logger = new NoteLogger(this.app);
this.logger.log("_tableheader", name);
this.cProxy = new ConsoleProxy({ app: this.app, logger: this.logger });
this.cProxy.setup();
this.logger.log(
"info",
name,
this.logger.prefixMsg(`Proxy set up (v${PLUGIN_INFO.pluginVersion})`)
);
}
onunload() {
this.cProxy.teardown();
}
};
10 changes: 10 additions & 0 deletions .obsidian/plugins/logstravaganza/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "logstravaganza",
"name": "Logstravaganza",
"version": "1.2.0",
"minAppVersion": "1.2.0",
"description": "A simple proxy for `console.*()` calls which copies log messages and uncaught exceptions to a note.",
"author": "Carlo Zottmann",
"authorUrl": "https://github.com/czottmann",
"isDesktopOnly": false
}
19 changes: 9 additions & 10 deletions .obsidian/workspace-mobile.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"state": {
"type": "markdown",
"state": {
"file": "Reading list.md",
"file": "book-review/how-to-decide-simple-tools-for-making-better-choices.md",
"mode": "source",
"source": true
}
Expand Down Expand Up @@ -98,7 +98,7 @@
"state": {
"type": "backlink",
"state": {
"file": "Reading list.md",
"file": "book-review/how-to-decide-simple-tools-for-making-better-choices.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -115,7 +115,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "Reading list.md",
"file": "book-review/how-to-decide-simple-tools-for-making-better-choices.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
Expand All @@ -127,7 +127,7 @@
"state": {
"type": "outline",
"state": {
"file": "Reading list.md"
"file": "book-review/how-to-decide-simple-tools-for-making-better-choices.md"
}
}
}
Expand All @@ -144,13 +144,14 @@
"command-palette:Open command palette": false,
"custom-sort:Toggle custom sorting": false,
"templater-obsidian:Templater": false,
"omnisearch:Omnisearch": false,
"darlal-switcher-plus:Open in Headings Mode": false,
"darlal-switcher-plus:Open Symbols for the active editor": false
"omnisearch:Omnisearch": false
}
},
"active": "ba4750059d7c4841",
"lastOpenFiles": [
"LOGGING-NOTE (iPhone).md",
"_templates/link-to-file.md",
"Reading list.md",
"posts/leaving-my-startup-was-the-right-decision.md",
"docs/book-review/how-to-decide-simple-tools-for-making-better-choices.md.html",
"img/walking-away.png",
Expand All @@ -160,10 +161,9 @@
"Untitled 1.md",
"Untitled.md",
"posts/decisions-are-rivers.md",
"book-review/img/how-to-decide.jpg",
"docs/img/how-to-decide.jpg",
"book-review/img",
"book-review/2023-12-22-the-killers-of-the-flower-moon/index.md",
"Reading list.md",
"book-review/2023-12-23-the-best-of-edgar-allen-poe/photo.jpeg",
"book-review/how-to-decide-simple-tools-for-making-better-choices.md.md",
"resume.pdf",
Expand Down Expand Up @@ -194,7 +194,6 @@
"christianity/inconvenient-god/photo.jpeg",
"christianity/inconvenient-god/PNG image.png",
"christianity/Test/index.md",
"christianity/inconvenient-god/index.md",
"christianity/christmas-empty-tomb/photo.jpeg"
]
}
35 changes: 35 additions & 0 deletions _templates/link-to-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%*
// Function to extract title from file's YAML frontmatter
async function extractTitle(file) {
let fileContent = await app.vault.read(file);
let frontMatter = app.metadataCache.getFileCache(file)?.frontmatter;
return frontMatter?.title || file.basename;
}

// Function to handle file selection and insert markdown
async function handleFileSelection(file) {
let title = await extractTitle(file);
let relPath = app.fileManager.generateMarkdownLink(file, app.workspace.getActiveFile().path);

if (file.extension === 'jpg' || file.extension === 'png' || file.extension === 'jpeg') {
let caption = await tp.system.prompt("Enter caption for the image:");
return `![${caption}](${relPath})`;
} else {
return `[${title}](${relPath})`;
}
}

// Main function to search and process files
async function main() {
let files = app.vault.getMarkdownFiles();
let fileNames = files.map(file => file.basename);

let selectedFile = await tp.system.suggester(fileNames, files);
if (selectedFile) {
return await handleFileSelection(selectedFile);
}
return "";
}

tp.editor.insertText(await main());
%>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ categories:
draft: false
---

![how-to-decide](img/how-to-decide.jpg){.preview-image}
![how-to-decide](../docs/img/how-to-decide.jpg){.preview-image}


What is my best decision? Worst?
Expand All @@ -25,3 +25,4 @@ Decision process:
- where do you want to go?
- What are all the ways to get there?
- By taking X choice, what are other ways it could go? What's the probability?

File renamed without changes

0 comments on commit d638df7

Please sign in to comment.