safir

Crates.iosafir
lib.rssafir
version0.10.3
sourcesrc
created_at2023-05-02 17:49:49.026178
updated_at2024-11-21 20:46:54.74715
descriptionKey/Value store to share values between different shell sessions
homepagehttps://github.com/Tyrannican/safir
repositoryhttps://github.com/Tyrannican/safir
max_upload_size
id854772
size100,665
Graham Keenan (Tyrannican)

documentation

README

Safir

Simple CLI key/value store.

Store key/value pairs in the terminal and retrieve them later for use like in different shell sessions.

Install

To install safir, run cargo install safir.

To build from source, clone the repository and run:

cargo build --release

Then move the binary to somewhere in your $PATH

Usage

When safir is run, it creates a store file in your $HOME directory ($HOME/.safirstore/safirstore.json).

Run safir --help for usage:

Key/Value store to share information between shell sessions

Usage: safir <COMMAND>

Commands:
  add     Add a value to the store with the given key
  get     Get values from the store
  rm      Remove values from the store
  alias   Output the alias command for  key / value pairs
  export  Output the export command for a key / value pairs
  mode    Sets the mode for Safir (active on the next run of Safir)
  list    List all values in the store
  clear   Clear all keys/values from the store
  purge   Purges the .safirstore directory, removing it and its contents
  use     Use / create an environment to store key / value pairs
  env     Display the current loaded environment
  help    Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

File Mode vs Database Mode

File mode is just like the old version of safir - all KV pairs are stored in a JSON value like before.

Database mode uses an SQLite database as storage instead which is technically more secure.

Switching between modes does not carry over any changes from the previous mode (i.e. KV pairs added in File mode are not present in Database mode unless you add them yourself).

This could change in a future release

Environments

Safir now supports storing KV pairs in specific environments which will declutter the list command and also keep all related KV pairs in one single place.

When Safir is loaded initially, it creates a new default environment (or loads an existing one) and uses that unlesss you switch environment.

Stores from older versions of Safir will automatically be ported over to this new format so there is no worry of lost data!

Examples

Adding a key and value to the store:

safir add api_key "api_key_value"

Retrieving a value from the store:

safir get api_key
# api_key="api_key_value"

Removing a value from the store:

safir rm api_key

List all values in the store:

safir list

# api_key="api_key_value"
# another_api_key="another_value"

Exporting a value:

safir export api_key
# export api_key="api_key_value"

eval $(safir export api_key) # <-- Will export the value to the current shell

Aliasing a value:

safir alias long_command
# alias long_command="cd build/ && make && sudo make install"

eval $(safir alias long_command) # <-- Will alias the command in the current shell

Clear the store:

safir clear
# Will remove all contents in the store

Purge the store (remove EVERYTHING safir related)

safir purge # Will remove the .safirstore directory

Setting an environment:

safir use [environment-name] # This will create an empty environment or load an existing one

Switching between file and database mode:

safir mode file # Switch to using a JSON file for storage

safir mode database # Switch to using an SQLite database for storage

Displaying the currently loaded environment:

safir env # Will display the currently loaded environment
Commit count: 120

cargo fmt