Sunday 27 August 2023
π Hydra ΒΆ
a C implementation of Emacs Hydra package to be used in terminal.

What is π Hydra? ΒΆ
- An implementation of Emacs π Hydra functionality to be used in the terminal
- a terminal program that groups your commands and bind them to common key on your keyboard.
- Commands can also be grouped in a tree like structure each node in the tree has a name and key bound to it.
- It reads CSV files of
key,name,commandlines then shows Terminal UI similar to Emacs π Hydra and prints the command to stdout.
Spacemacs for example is an emacs configuration centered around π Hydra commands, with all user commands grouped as trees bound in a mnemonic way. for example:
- opening a file is bound to
space f f - deleting current file is bound to
space f D - Git status
space g s
Binding π Hydra to space key in your terminal means pressing space will make your terminal behave similar to spacemacs if you executed the output with eval. this repo has a bash script hydra-completion.bash which achieve this binding.
Other usages ΒΆ
hydradoesn’t execute the command by default.- The program prints the choosen command to standard output.
- What to do with this output is up to you. you can for example append it to a file. or open the browser with the output or whatever. just like
fzfanddmenu. - Which means you can use π Hydra as part of your scripts to allow the user to navigate a tree of choices and get the final choice piped to another program, GNU coreutils style.
Install ΒΆ
- Clone it from github to your machine
1git clone git@github.com:emad-elsaid/hydra.git
2cd hydra
- Build
1make
- Install
1sudo make install
- Export
HYDRAvariable to your.bashrc. it should have a list of hydras files. π Hydra example files are installed under/usr/share/hydra/hydras. - Loading
/usr/share/hydra-completion.bashwill bindhydratoSpacekey in your keyboard and will invokehydrawhen the line is empty. - For example to use the
gitπ Hydra:
1export HYDRA="/usr/share/hydra/hydras/git"
2source /usr/share/hydra/hydra-completion.bash
π Hydra file ΒΆ
- π Hydra files are simple CSV files that define the commands π hydra can load.
- The file has 3 columns without header. an example is under
hydrasdirectory in this repo.
a simple example can be as follow
g,Git,
gs,Status,git status
- It defines
Gitcommand that doesn’t execute a command under the keyg - and defines a command named
Statusunder keysinsidegthat will execute the commandgit status
Running ΒΆ
- You can run
hydrabinary with a list of π hydra files - π Hydra will load the files in the order passed.
- it will display the list of top level commands
- When the program reaches a choosen command that doesn’t have children it will print the command to standard output
1hydra hydras/git hydras/systemd hydras/github
Tests ΒΆ
To run tests execute
1make run-test
