Giter Club home page Giter Club logo

frgm's Introduction

frgm Build Status

frgm is a meta snippet (fragment) manager.


frgm

Key features of frgm are:

Usage

Initialize frgm ( frgm init )

Initialize frgm.

  • Create or update config.toml
  • Set and create global.snippets_path ( create file or make directory )
$ frgm init

Write snippets ( frgm edit )

Write snippets.

The format of the frgm snippet is the following,

---
# Default group name of snippets
# Default is snippets file name
group: my-group
snippets:
  # Unique identifier of snippet
  # Default is automatically generated
- uid: frgm-1ca779b751a5
  # Group name of snippet
  # Default is default group name of snippets
  group: command
  # Name of snippet
  name: Delete branch already merged
  # Content (command) of snippet
  content: git branch --merged | grep -v master | xargs git branch -d
  # Description of snippet
  desc: |
    1. lists the merged branches
    2. delete all merged branches except the master branch
    ref: https://example.com/path/to/link
  # Labels
  labels:
  - git
  - cleanup
- name: ping
  content: ping 8.8.8.8
[...]

You can use the frgm edit command to edit snippets of global.snippets_path using the editor specified in $EDITOR.

$ EDITOR=emacs frgm edit

Export frgm snippets as * snippets ( frgm export )

Export snippets as Alfred snippets

$ frgm export --to ~/Library/Application Support/Alfred/Alfred.alfredpreferences/snippets --format alfred

Export snippets as pet snippets

$ frgm export --to /path/to/pet.toml --format pet

Export snippets as Markdown document.

$ frgm export --to /path/to/snippets.md --format md

Key Mapping:

frgm snippet key Default / Required Alfred pet Markdown
uid: Default is automatically generated uid - use as link.hash
group: Default is default group name of snippets or file name directory - use
name: required name description: use
desc: - - use
content: required snippet command: use
output: - output: use
labels: keyword tag: use

Fill uid, group ( frgm fill )

Fill and freeze uid: and group:.

$ frgm fill

before:

# my-group.yml
snippets:
- name: ping
  content: ping 8.8.8.8

after:

# my-group.yml
snippets:
- uid: frgm-6aa9d75f9d83
  group: my-group
  name: ping
  content: ping 8.8.8.8

Add snippets repository ( frgm repo add )

Add frgm snippets repository.

$ frgm repo add https://github.com/k1LoW/sample-frgm-snippets.git

Execute git pull in all snippets repositories ( frgm repo pull )

Execute git pull in all snippets repositories.

$ frgm repo pull

Import * snippets ( frgm import )

Import Alfred snippets

$ frgm import --from ~/Library/Application Support/Alfred/Alfred.alfredpreferences/snippets --format alfred

Convert * snippets ( frgm convert )

Convert history output into frgm snippets

$ history | tail -1
21344  frgm convert --format history --group from-history # Delete merged branch
$ history | tail -1 | frgm convert --format history --group from-history
snippets:
- uid: history-8cc0c8477ec0
  group: from-history
  name: Delete merged branch
  content: git branch --merged | grep -v master | xargs git branch -d

Convert Alfred snippet file into frgm snippet

$ cat /path/to/alfredsnippet.json | frgm convert --format alfred --group search
snippets:
- uid: frgm-46c29e119523
  group: search
  name: Search log file
  content: lsof -c nginx | grep -v .so | grep .log | awk '{print $9}' | sort | uniq
  labels:
  - log

Convert pet snippets file into frgm snippets

$ cat /path/to/pet-snippets.toml. | frgm convert --format pet --group pet
snippets:
- uid: pet-df7bb29f9681
  group: pet
  name: ping
  content: ping 8.8.8.8
  labels:
  - network
  - google
- uid: pet-584a331fd6b0
  group: pet
  name: hello
  content: echo hello
  output: hello
  labels:
  - sample

Use frgm snippets ( frgm list )

$ frgm list

zsh auto-complete from snippets using fzf (Ctrl+j)

function fzf-select-snippets() {
    BUFFER=$(frgm list --format ':content # :name [:group :labels] :uid' | fzf --reverse --border --preview "echo {} | rev | cut -f 1 -d ' ' | rev | frgm man")
    CURSOR=$#BUFFER
    zle clear-screen
}
zle -N fzf-select-snippets
bindkey '^j' fzf-select-snippets

zsh auto-complete from snippets using peco (Ctrl+j)

function peco-select-snippets() {
    BUFFER=$(frgm list | peco --query "$LBUFFER")
    CURSOR=$#BUFFER
    zle clear-screen
}
zle -N peco-select-snippets
bindkey '^j' peco-select-snippets

zsh auto-complete from history and snippets using peco (Ctrl+r)

function peco-select-history-and-snippets() {
    BUFFER=$((history -r -n 1 & frgm list) | peco --query "$LBUFFER")
    CURSOR=$#BUFFER
    zle clear-screen
}
zle -N peco-select-history-and-snippets
bindkey '^R' peco-select-history-and-snippets

Install

homebrew tap:

$ brew install k1LoW/tap/frgm

manually:

Download binany from releases page

go get:

$ go get github.com/k1LoW/frgm

frgm's People

Contributors

github-actions[bot] avatar k1low avatar kenchan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.