obaraelijah / kv

Easy CLI key-value storage with bash hooks. Use kv to auto-configure your system on key-value updates. Project to help master rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KV: The simple CLI key-value storage, with hooks.

The Key Value(KV) CLI tool

Easy CLI key-value storage with bash hooks. Use kv to auto-configure your system on key-value updates. All material is stored in a simple JSON file. Written in rust to learn the language.

➜  kv git:(master) kv --help
kv 0.2
elijah samson (elijahobara357@gmail.com)
Key-Value Storage with bash command hooks. Add hooks to run commands on variable update.

USAGE:
    kv <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    cmd     Add, and Run bash commands. Add hooks to run commands on variable update.
    del     Delete key and value from storage
    get     Get key from storage
    help    Prints this message or the help of the given subcommand(s)
    list    List keys, cmds, or hooks.
    set     set key to value in storage

Example

I currently use it to help manage i3 configuration changes. Below is an example of using kv to update your desktop background.

Steps:

  1. Setup a command which will grab the image from the value of background-img-loc
  2. Add a hook to run the command above when background-img-loc is set to a new value
  3. Set the value of background-img-loc, which triggers the hook, which runs the bash command to update the background.
~ kv cmd add update-bg-cmd 'feh --bg-scale $(kv get background-img-loc)'~ kv cmd add-hook update-bg-hook update-bg-cmd background-img-loc
 ➜  ~ kv set background-img-loc ~/Pictures/bg1.png
*background is updated to ~/Pictures/bg1.png*~ kv set background-img-loc ~/Pictures/bg2.png
*background is updated to ~/Pictures/bg2..png*

Install

To install, first clone the project:

git clone [](https://github.com/obaraelijah/kv)

Then install it with cargo:

cargo install --force --path kv

If you haven’t already, you will need to add the the $HOME/.cargo/bin folder to your path. Simply copy the below into .profile or .bashrc or .zshrc:

export PATH="$PATH:$HOME/.cargo/bin"

And verify it’s installed:

➜  ~ kv          
kv 0.2
Elijah Samson (elijahobara357@gmail.com)
Key-Value Storage with bash command hooks. Add hooks to run commands on variable update.
...truncated...

Usage

Storage file

By default kv uses the following path:

$CONFIG_DIR/kv/kv.json

On linux this is usually:

~/.config/kv/kv.json

I usually make a kv.json in my backup folder, and make a symlink for that file:

mkdir -p ~/.config/kv
ln -s ~/backup/kv.json ~/.config/kv/kv.json

Key-Value storage

Simply set keys to values, get the values for a key, and delete keys and values.

For usage, either you can just put --help or -h at the end of any statement.

USAGE:
    kv set <key> <val>  -- sets <key> to <val>
    kv get <key>        -- prints value of <key> to stdout. Newline on missing key.
    kv del <key>        -- deletes <key> and returns it value to stdout.

Here’s an example:

~ kv set hi david
➜  ~ kv get hi      
david
➜  ~ kv del hi      
david
➜  ~ kv get hi      

Commands

Commands are a key-value storage for bash commands. You can run them directly with kv cmd run.

USAGE:
    kv cmd add <cmd-name> <cmd-value>
    kv cmd run <cmd-name>

Example:

➜  ~ kv cmd add my-cmd 'echo hi'
➜  ~ kv cmd run my-cmd
hi

Hooks

Hooks are used to run Commands when Keys are updated (set, get, or del).

USAGE
    kv cmd add-hook <hook-name> <cmd-name> <trigger> <key>
    kv cmd del-hook <hook-name>

Example (same as the i3 one):

~ kv cmd add update-bg-cmd 'feh --bg-scale $(kv get background-img-loc)'~ kv cmd add-hook update-bg-hook update-bg-cmd background-img-loc
 ➜  ~ kv set background-img-loc ~/Pictures/bg1.png
*background is updated to ~/Pictures/bg1.png*~ kv set background-img-loc ~/Pictures/bg2.png
*background is updated to ~/Pictures/bg2..png*

About

Easy CLI key-value storage with bash hooks. Use kv to auto-configure your system on key-value updates. Project to help master rust.


Languages

Language:Rust 100.0%