{"id":16118706,"url":"https://github.com/dpbriggs/kv","last_synced_at":"2025-04-14T12:03:26.578Z","repository":{"id":45094597,"uuid":"164353068","full_name":"dpbriggs/kv","owner":"dpbriggs","description":"Easy CLI key-value storage with bash hooks. Use kv to auto-configure your system on key-value updates. Project to help learn rust.","archived":false,"fork":false,"pushed_at":"2021-04-29T19:27:42.000Z","size":24,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T12:03:18.512Z","etag":null,"topics":["bash","cli","hooks","key-value"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpbriggs.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-06T23:02:35.000Z","updated_at":"2024-08-03T21:19:44.000Z","dependencies_parsed_at":"2022-09-22T17:02:36.331Z","dependency_job_id":null,"html_url":"https://github.com/dpbriggs/kv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpbriggs%2Fkv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpbriggs%2Fkv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpbriggs%2Fkv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpbriggs%2Fkv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpbriggs","download_url":"https://codeload.github.com/dpbriggs/kv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877987,"owners_count":21176243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","cli","hooks","key-value"],"created_at":"2024-10-09T20:50:22.389Z","updated_at":"2025-04-14T12:03:26.553Z","avatar_url":"https://github.com/dpbriggs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+TITLE: KV: The simple CLI key-value storage, with hooks.\n#+AUTHOR: dpbriggs\n#+EMAIL: email@dpbriggs.ca\n\n* The KV CLI tool\n\nEasy CLI key-value storage with bash hooks. Use kv to auto-configure your system on key-value updates.\nAll material is stored in a simple JSON file. Written in rust to learn the language.\n\n#+BEGIN_EXAMPLE\n➜  kv git:(master) kv --help\nkv 0.2\nDavid Briggs (dpbriggs@edu.uwaterloo.ca)\nKey-Value Storage with bash command hooks. Add hooks to run commands on variable update.\n\nUSAGE:\n    kv \u003cSUBCOMMAND\u003e\n\nFLAGS:\n    -h, --help       Prints help information\n    -V, --version    Prints version information\n\nSUBCOMMANDS:\n    cmd     Add, and Run bash commands. Add hooks to run commands on variable update.\n    del     Delete key and value from storage\n    get     Get key from storage\n    help    Prints this message or the help of the given subcommand(s)\n    list    List keys, cmds, or hooks.\n    set     set key to value in storage\n#+END_EXAMPLE\n\n** Example\nI currently use it to help manage i3 configuration changes. Below is an example of using kv to update your desktop background.\n\nSteps:\n1. Setup a command which will grab the image from the value of =background-img-loc=\n2. Add a hook to run the command above when =background-img-loc= is set to a new value\n3. Set the value of =background-img-loc=, which triggers the hook, which runs the bash command to update the background.\n\n#+BEGIN_SRC bash\n ➜  ~ kv cmd add update-bg-cmd 'feh --bg-scale $(kv get background-img-loc)'\n ➜  ~ kv cmd add-hook update-bg-hook update-bg-cmd background-img-loc\n ➜  ~ kv set background-img-loc ~/Pictures/bg1.png\n*background is updated to ~/Pictures/bg1.png*\n ➜  ~ kv set background-img-loc ~/Pictures/bg2.png\n*background is updated to ~/Pictures/bg2..png*\n#+END_SRC\n\n** Install\n\nTo install, first clone the project:\n: git clone git@github.com:dpbriggs/kv.git\n\nThen install it with cargo:\n: cargo install --force --path kv\n\nIf 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=:\n\n: export PATH=\"$PATH:$HOME/.cargo/bin\"\n\nAnd verify it's installed:\n\n#+BEGIN_EXAMPLE\n➜  ~ kv          \nkv 0.2\nDavid Briggs (dpbriggs@edu.uwaterloo.ca)\nKey-Value Storage with bash command hooks. Add hooks to run commands on variable update.\n...truncated...\n#+END_EXAMPLE\n\n** Usage\n\n*** Storage file\n\nBy default kv uses the following path:\n\n: $CONFIG_DIR/kv/kv.json\n\nOn linux this is usually:\n\n: ~/.config/kv/kv.json\n\nI usually make a =kv.json= in my backup folder, and make a symlink for that file:\n\n#+BEGIN_EXAMPLE\nmkdir -p ~/.config/kv\nln -s ~/backup/kv.json ~/.config/kv/kv.json\n#+END_EXAMPLE\n\n*** Key-Value storage\n\nSimply set keys to values, get the values for a key, and delete keys and values.\n\nFor usage, either you can just put =--help= or =-h= at the end of any statement.\n\n#+BEGIN_EXAMPLE\nUSAGE:\n    kv set \u003ckey\u003e \u003cval\u003e  -- sets \u003ckey\u003e to \u003cval\u003e\n    kv get \u003ckey\u003e        -- prints value of \u003ckey\u003e to stdout. Newline on missing key.\n    kv del \u003ckey\u003e        -- deletes \u003ckey\u003e and returns it value to stdout.\n#+END_EXAMPLE\n\nHere's an example:\n\n#+BEGIN_SRC bash\n➜  ~ kv set hi david\n➜  ~ kv get hi      \ndavid\n➜  ~ kv del hi      \ndavid\n➜  ~ kv get hi      \n#+END_SRC\n\n*** Commands\n\nCommands are a key-value storage for bash commands. You can run them directly with =kv cmd run=.\n\n#+BEGIN_SRC bash\nUSAGE:\n    kv cmd add \u003ccmd-name\u003e \u003ccmd-value\u003e\n    kv cmd run \u003ccmd-name\u003e\n#+END_SRC\n\nExample:\n\n#+BEGIN_EXAMPLE\n➜  ~ kv cmd add my-cmd 'echo hi'\n➜  ~ kv cmd run my-cmd\nhi\n#+END_EXAMPLE\n\n*** Hooks\n\nHooks are used to run Commands when Keys are updated (set, get, or del).\n\n#+BEGIN_EXAMPLE\nUSAGE\n    kv cmd add-hook \u003chook-name\u003e \u003ccmd-name\u003e \u003ctrigger\u003e \u003ckey\u003e\n    kv cmd del-hook \u003chook-name\u003e\n#+END_EXAMPLE\n\nExample (same as the i3 one):\n\n#+BEGIN_SRC bash\n ➜  ~ kv cmd add update-bg-cmd 'feh --bg-scale $(kv get background-img-loc)'\n ➜  ~ kv cmd add-hook update-bg-hook update-bg-cmd background-img-loc\n ➜  ~ kv set background-img-loc ~/Pictures/bg1.png\n*background is updated to ~/Pictures/bg1.png*\n ➜  ~ kv set background-img-loc ~/Pictures/bg2.png\n*background is updated to ~/Pictures/bg2..png*\n#+END_SRC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpbriggs%2Fkv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpbriggs%2Fkv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpbriggs%2Fkv/lists"}