A command line application that provides an interactive shell for the etcd server.
Aug 13th, 2014: This is still a work in progress, and right now only supports the commands cd, ls, get, and set.
Using etcdsh you can browse your etcd "filesystem" like an ordinary filesystem, using familar commands line "cd" and "ls". For example:
Connecting to http://127.0.0.1:4001
Interactive etcd shell started.
Type 'help' for a list of commands.
Type 'exit' or 'q' to quit.
joe@etcd:/$ ls -l
total 4
0 0 0 k: .
0 0 0 k: ..
3 3 300 k: go
1 1 0 k: apps
joe@etcd:/$ cd apps
joe@etcd:/apps$ ls -l
total 4
0 0 0 k: .
0 0 0 k: ..
6 6 0 o: mobile
15 15 0 o: website
joe@etcd:/apps$ get website
http://example.com
joe@etcd:/apps$ set -t 300 website http://example.net
http://example.net
joe@etcd:/apps cd ..
joe@etcd:/$ exit
Go version 1.3 is required. See this page for Go installation instructions.
The readline development libraries are required.
apt-get install libreadline-dev
Clone the repo and install using go install
.
git clone git@github.com:headzoo/etcdsh.git
cd etcdsh
go get
go install
Use etcdsh -help
for a list of command line arguments. Once in the shell type "help" for a list of commands.
There are three ways to configure etcdsh:
- Using command line arguments.
- Using environment variables.
- Using a JSON file saved at
$HOME/.etcdsh
.
The following is the list of configuration options.
- "machine" The etcd server to connect to.
- "colors" Whether to use colors in output. Only applicable to Linux. The LS_COLORS environment variable is used to determine which colors to use.
- "ps1" The first custom prompt.
- "ps2" The second custom prompt.
When used at the command line, prefix the option with "-", eg -machine
. When defined as an environment variable, prefix the option with "ETCDSH_", eg ETCDSH_MACHINE
.
An example configuration file.
{
"machine": "http://127.0.0.1:4001",
"colors": true
}
The terminal prompt may be customized using the environmental variables ETCDSH_PS1 and ETCDSH_PS2. The prompt format is nearly identital to the format used by bash. See How to: Change / Setup bash custom prompt (PS1) for a complete list of escape codes.
Example:
# This is the default etcdsh prompt. The prompt will look like 'sean@etcd:domains$ '.
export ETCDSH_PS1="\u@etcd:\w\$ "
You can even embed color codes.
export ETCDSH_PS1="\e[36m\u@\h\e[0m:\e[32m\w\e[0m"
Escape sequences not currently supported by etcdsh: \D, \V, \!, \#, \j, \nnn, \[, and \]. Additionally bash commands cannot be embedded in the prompt. For example you can't use \u@$(hostname):
.
- Write the command history to a file, eg
$HOME/.etcdsh_history
. - Find or write a replacement for the readline bindings (won't work on Windows).
- Auto complete needs some polishing.
- LS short output needs to be spaced better.
- Handle pipes and redirection.
This was the first app I've written using Go. The code is probably sloppy, and breaks some Go conventions. Use the issue system to report bugs and broken conventions.