shane0 / shane0.github.io

shane null's github pages
https://shane0.github.io/
MIT License
1 stars 0 forks source link

vim #12

Open shane0 opened 1 year ago

shane0 commented 1 year ago

julian maps

nnoremap <leader>h i# day: <C-R>=strftime("%j")<CR> week: <C-R>=strftime("%U")<CR> <C-R>=strftime("%B")<CR> <C-R>=strftime("%F")<CR><CR><ESC>o
shane0 commented 1 year ago

vscode extension for bujo

const vscode = require('vscode');
const fs = require('fs');

function generateBulletJournalFile() {
  const currentDate = new Date();
  const julianDayNumber = Math.floor((currentDate - new Date(currentDate.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24);
  const weekNumber = Math.ceil((currentDate.getDate() + currentDate.getDay()) / 7);
  const isoDate = currentDate.toISOString().substring(0, 10);

  const fileContent = `# Bullet Journal - Day ${julianDayNumber} Week ${weekNumber} - ${isoDate}\n\n`;

  vscode.window.showSaveDialog({}).then((uri) => {
    if (uri && uri.fsPath) {
      fs.writeFile(uri.fsPath, fileContent, (err) => {
        if (err) {
          console.error(err);
          vscode.window.showErrorMessage(`Error creating file: ${err.message}`);
        } else {
          vscode.window.showInformationMessage(`Bullet journal file created: ${uri.fsPath}`);
        }
      });
    }
  });
}

function activate(context) {
  const disposable = vscode.commands.registerCommand('extension.generateBulletJournal', generateBulletJournalFile);
  context.subscriptions.push(disposable);
}

exports.activate = activate;
shane0 commented 1 year ago

To write a VSCode extension that generates bullet journal files, you will need to have a basic understanding of JavaScript and the VSCode Extension API. Here are the general steps you can follow:

Set up your development environment: Install Node.js and Visual Studio Code. Then, create a new folder for your extension and run npm init to create a new package.json file.

Install the necessary dependencies: To work with the VSCode Extension API, you will need to install the vscode package. You may also need to install additional packages depending on the functionality you want to implement in your extension.

Create a new command: Use the vscode.commands.registerCommand() method to create a new command that will generate a new bullet journal file when executed. In the callback function for this command, you can use the VSCode API to create a new file with the desired content.

Add a UI element for the command: You can add a new button or menu item to the VSCode UI that will trigger your command using the vscode.commands.registerCommand() method.

Test your extension: Use the vsce command-line tool to package your extension and install it in your local VSCode environment to test its functionality.

This code defines a new command called extension.generateBulletJournal that generates a new bullet journal file and saves it to disk. When the command is executed, it uses the current date to generate a file name and content. It then prompts the user to save the file to a location of their choosing. Finally, it displays a success or error message to the user.