Table of Contents
What
yaml-path
reads given yaml on stdin and output a sort of 'path' corresponding
to given line
and column
in the file.
Generated path is compilant with BOSH ops-file
syntax.
Why
Working with BOSH often require to writes
so-called ops-file
which are kind of patches for yaml files. Writing the path
of the object to modify is a real burden in large yaml files.
This tool is meant to be easily integrated in editor such as emacs.
Usage
USAGE:
yaml-path [global options] --line value
GLOBAL OPTIONS:
--col value cursor column, zero to disable (default: 0)
--path value set filepath, empty means stdin
--format value output format. "bosh" or "jsonpath" (default: "bosh")
--bosh.sep value set path separator for bosh format (default: "/")
--bosh.name value set attribut name for bosh format, empty to disable (default: "name")
--help, -h show help
--version, -v print the version
Example
Given the following yaml file:
top:
first:
- name: myname
attr1: val1
attr2: val2
# ^
- value2
- value3
second:
child1: value1
child2: value2
child3: value3
cat test.yaml | ./yaml-path --line 5 --col 14
Outputs:
/top/first/name=myname/attr2
Installation
go install github.com/gidoichi/yaml-path@latest
Integration
Emacs
Get a local copy of this repo :
git clone https://github.com/gidoichi/yaml-path.git
Load emacs yaml-path
package :
(load "/path/to/yaml-path/emacs/yaml-path.el")
Provided functions:
yaml-path-at-point
: (interactive) display in minibuffer and store to kill
ring yaml path for token under cursor
yaml-path-get-path-at-point(&optional line col)
: return yaml path for token
in current buffer at given line and column
yaml-path-which-func
: integrates yaml-path-get-path-at-point
with
which-function-mode
Demo:
Vim
Plugin manager
Manually
install -m 0644 -D yaml-path.vim ~/.vim/plugin/
Configuration
In your ~/.vimrc
:
g:yamlpath_sep
: change default separator (default: /
)
g:yamlpath_auto
: enable automatic call on cursor move on YAML files
(default: 0
)
- to call the tool with a keystroke such as F12, add to you
~/.vimrc
:
nnoremap <F12> :Yamlpath<CR>
Command
To call the tool with a custom separator once (in command mode): :Yamlpath "."
Demo:
Neovim
Packer
use({
"gidoichi/yaml-path.nvim",
run = { "go install" },
})
Intellij
- Go to preference -> tools -> external tools
- Add a new one with this configuration
Note
The current implementation relies on a very savage hack of golang
yaml library vendored in this project.