frgm
is a meta snippet (fragment) manager.
Key features of frgm
are:
- Can export snippets in other snippet tool format.
- Can document snippets.
- Can use as command-line snippets.
Initialize frgm.
- Create or update config.toml
- Set and create
global.snippets_path
( create file or make directory )
$ frgm init
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 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
$ 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 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 frgm snippets repository.
$ frgm repo add https://github.com/k1LoW/sample-frgm-snippets.git
Execute git pull
in all snippets repositories.
$ frgm repo pull
Import Alfred snippets
$ frgm import --from ~/Library/Application Support/Alfred/Alfred.alfredpreferences/snippets --format alfred
$ 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
$ 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
homebrew tap:
$ brew install k1LoW/tap/frgm
manually:
Download binany from releases page
go get:
$ go get github.com/k1LoW/frgm