Skip to content
/ sofa Public

A command execution engine powered by rofi.

License

Notifications You must be signed in to change notification settings

f4z3r/sofa

Repository files navigation

sofa

GitHub License GitHub Release LuaRocks

A command execution engine powered by rofi.


Table of Contents:


Examples

For Snippets Management

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$' .

Shell

For Dynamic Bookmarks

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 project

Bookmarks Launcher

Features Preview

Pick a command based on its name, description, and tags:

Select a command

Pick arguments based on pre-defined choices. The default choice is shown in the command preview:

Select a dependency

Pick arguments based on some command output. In this case we filter for rockspec files:

Select a Rockspec


My personal sofa configuration can be found in my Nix setup.

Installation

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 sofa

If 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.

Integration

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.

Bash

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'

Zsh

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_widget

Fish

Add 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_sofa

Configuration

See docs/configuration.md.

Development

You can setup a dev environment with the needed Lua version:

# launch shell with some lua version and the dependencies installed:
nix develop .#lua52

Testing

Testing is performed with busted:

busted .

Roadmap

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

About

A command execution engine powered by rofi.

Resources

License

Stars

Watchers

Forks

Packages

No packages published