Code Monkey home page Code Monkey logo

gh-md's Introduction

gh-md: markdown link and issue reference generation

This GitHub CLI extension generates markdown links from input URLs or references.

This isn't particularly useful by itself, but combine it with tools like Alfred snippet triggers, Raycast scripts, or Obsidian templates, you can automate these links for insertion into your markdown documents.

Installation

gh extension install zerowidth/gh-md

Usage

gh md --help for full details.

gh md link

Generates a markdown link from an input URL or issue/pr/discussion reference.

Basic example:

$ gh md link https://github.com/cli/cli/pull/123
[cli/cli#123: Tweak flags language](https://github.com/cli/cli/pull/123)

Skip title lookup:

$ gh md link --simple https://github.com/cli/cli/pull/123
[cli/cli#123](https://github.com/cli/cli/pull/123)

Create a link from an issue reference:

$ gh md link cli/cli#123
[cli/cli#123: Tweak flags language](https://github.com/cli/cli/pull/123)

gh md ref

Generates an issue/pr/discussion reference from an input URL or reference.

$ gh md ref https://github.com/cli/cli/pull/123
cli/cli#123

gh md title

Looks up the title of the given URL or reference:

$ gh md title cli/cli#123
Tweak flags language

The title can be sanitized for use as a path, stripping :, /, and a few other characters.

gh md url

Generates the URL from the given issue reference or markdown link.

$ gh md url cli/cli#123
https://github.com/cli/cli/pull/123

Using gh-md in Obsidian

gh-md was built in part to be used in user-defined functions in the Templater plugin.

Markdown links

  • define a markdownLink user function as /path/to/gh md link -n "$input"
  • copy a GitHub URL to your clipboard
  • use it in a template: <% tp.user.markdownLink({input: (await tp.system.clipboard())}) %>

Sanitized titles

The sanitized issue title can be used for filenames. In a templater template for creating a document for an issue from the clipboard:

  • Define a markdownTitle user function as /path/to/gh md title -n --sanitize "$input".

  • Use the title to rename a new file from that template:

    <%- await tp.file.rename("Issue - " + tp.date.now("YYYY-MM") + " - " + (await tp.user.markdownTitle({input: (await tp.system.clipboard())}))) -%>
    

Auth issues

If you're using a recent version of the GitHub CLI that uses the system keychain to store credentials, these helper functions may not work. If so, you can configure the PATH in the user functions. This assumes you've installed the GH CLI with homebrew:

  • PATH=$PATH:/opt/homebrew/bin /opt/homebrew/bin/gh md link -n "$input"
  • PATH=$PATH:/opt/homebrew/bin /opt/homebrew/bin/gh md title -n --sanitize "$input"

Using gh-md with Espanso

An espanso config for generating links and references from the clipboard:

matches:
  - trigger: "//md"
    replace: "{{output}}"
    vars:
      - name: clipboard
        type: clipboard
      - name: output
        type: shell
        params:
          cmd: "gh md link {{clipboard}}"
  - trigger: "//ml"
    replace: "{{output}}"
    vars:
      - name: clipboard
        type: clipboard
      - name: output
        type: shell
        params:
          cmd: "gh md link --simple {{clipboard}}"
  - trigger: "//ir"
    replace: "{{output}}"
    vars:
      - name: clipboard
        type: clipboard
      - name: output
        type: shell
        params:
          cmd: "gh md ref {{clipboard}}"

gh-md's People

Contributors

zerowidth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.