Arturo Herrero

gvar

I used to have a problem when setting an environment variable; I couldn’t make the variable immediately available in a different shell or subshell without the need to source any file. As a result, I’ve created gvar to solve this problem.

gvar(1) – display, set, or remove global variables*.

* When I say global variable, I refer to a key-value pair that you can read/write at any time in any terminal session. You can think this is similar to the environment variables because it’s a set of dynamic-named values but they are not session-wide or system-wide related.

gvar is a pure Bash key-value store where each user has a different collection of data. The records are stored in the user’s home directory as ~/.gvar file.

By working on this project, I’ve used the following tools for the first time.

Bats

Bats: Bash Automated Testing System is a testing framework for Bash.

#!/usr/bin/env bats

@test "invoking gvar VARIABLE prints the value of the global variable" {
  run "$gvar" TEST
  [ "$status" -eq 0 ]
  [ "$output" = "test" ]
}

Bats with Travis CI

I usually test my open source projects with Travis CI, but in this case we have to install Bats, which is not included in the default environment. Here’s my .travis.yml file.

language: bash
before_install:
  - sudo add-apt-repository ppa:duggan/bats --yes
  - sudo apt-get update -qq
  - sudo apt-get install -qq bats
script:
  - bats test/gvar.bats

Ronn

I was building a command line tool, so I created a man page documenting it.

Ronn builds manuals. It converts simple, human readable (markdown-like) textfiles to roff for terminal display, and also to HTML for the web.

gvar man page

ShellCheck

ShellCheck is a static analysis tool for shell scripts. Since I like to use Code Climate with my projects, ShellCheck gives warnings and suggestions for bash/sh shell scripts.

Homebrew formulae

The last thing I did was my own Homebrew formulae for my packages. Now, I can install gvar on OS X without any pain.

$ brew tap arturoherrero/formulae
$ brew install gvar