sofa is a small utility to enable easy execution of templated commands. It can be used to store
snippets that you often rely on, or fully template complex commands. It is meant to be used with a
shortcut manager to enable launching from anywhere, but can also inject commands into your current
shell session for commands that make more sense to run there (see Integration).
You can use sofa for standard snippets management. Use the integration described
below, and have configuration such as:
Configuration
namespaces:
lua:
commands:
install-local:
command: luarocks --local make --deps-mode {{ deps_mode }} {{ rockspec }}
description: Install rock locally
tags:
- local
- luarocks
interactive: true
parameters:
deps_mode:
default: none
exclusive: true
prompt: Install dependencies
choices:
- none
- one
- all
- order
rockspec:
prompt: Rockspec
choices: fd -tf -c never '.*\.rockspec$' .Or launch sofa without interactive mode from a shortcut manager such as sxhkd:
Configuration
namespaces:
bookmarks:
commands:
github:
command: xdg-open "https://github.com/{{ user }}/{{ project }}"
description: Open a GitHub project in the browser
tags:
- github
- coding
parameters:
user:
default: f4z3r
prompt: Choose user
project:
prompt: Choose projectPick a command based on its name, description, and tags:
Pick arguments based on pre-defined choices. The default choice is shown in the command preview:
Pick arguments based on some command output. In this case we filter for rockspec files:
My personal sofa configuration can be found
in my Nix setup.
Note
sofa will only work on Linux systems. It might work on MacOS, but I have not tested it.
Of course, this is dependent on rofi being installed on your system.
Install via luarocks:
luarocks install sofaIf you want, you can use sofa with fzf instead of rofi. In that case, you will need fzf
installed and should have a look at the configuration
section to set fzf as the picker.
This section shows how to integrate sofa with your favourite shell. The following examples
showcase how to bind sofa to Contrl + o. Update the snippets to bind to your
preferred keys.
Add the following lines to your bash configuration:
__interactive_sofa () {
tput rmkx
output="$(sofa -i)"
tput smkx
READLINE_LINE=${output}
READLINE_POINT=${#READLINE_LINE}
}
bind -x '"\C-o": __interactive_sofa'Add the following lines to your zsh configuration:
autoload -U add-zsh-hook
function _interactive_sofa() {
emulate -L zsh
zle -I
echoti rmkx
output=$(sofa -i)
echoti smkx
if [[ -n $output ]]; then
LBUFFER=$output
fi
zle reset-prompt
}
zle -N _interactive_sofa_widget _interactive_sofa
bindkey '^o' _interactive_sofa_widgetAdd the following lines to your fish configuration:
function __interactive_sofa
set output (sofa -i)
commandline -j $output
end
bind \co __interactive_sofa
# if you use vim mode and want to bind in insert mode
bind -M insert \co __interactive_sofaYou can setup a dev environment with the needed Lua version:
# launch shell with some lua version and the dependencies installed:
nix develop .#lua52Testing is performed with busted:
busted .This shows some items I want to support. The list is not in order of priority.
- add configuration validation
- better documentation and screenshots on the capabilities
- support dependent choices (i.e. when X chosen for parameter 1, then provides choice list Y for parameter 2)
- add support for more Lua versions
- support executing commands in the background
The license can be found under ./LICENSE.





