GitXplorerGitXplorer
s

command-mode.xplr

public
18 stars
1 forks
1 issues

Commits

List of commits on branch main.
Verified
43d073bb7f3d5b701a3f254084b91a0911df41d2

Update README.md

ssayanarijit committed 2 years ago
Verified
0cbce006178d0d3c32f615a7c027d42e1e39b156

Update README.md

ssayanarijit committed 2 years ago
Verified
da9cb7b1f7ec45d830d4b9c6ed97ffab4156613f

Update README.md

ssayanarijit committed 2 years ago
Verified
f297e11232956a55c2d381773b0d78cddf4dd752

Remove src

ssayanarijit committed 2 years ago
Verified
b3500903eee3705932fb3b9b4ff546ccd22649dc

Use .bind() to bind commands to keys

ssayanarijit committed 3 years ago
Verified
6b9cc9371dc3403f64ecc6e37768983b883062a4

Update README.md

ssayanarijit committed 3 years ago

README

The README file for this repository.

https://user-images.githubusercontent.com/11632726/174449444-2e13c1d7-7c1b-4dea-a2a8-13f193d8df8d.mp4

command-mode.xplr

This plugin acts like a library to help you define custom commands to perform actions.

Why

xplr has no concept of commands. By default, it requires us to map keys directly to a list of messages. While for the most part this works just fine, sometimes it gets difficult to remember which action is mapped to which key inside which mode. Also, not every action needs to be bound to some key.

In short, sometimes, it's much more convenient to define and enter commands to perform certain actions than trying to remember key bindings.

Installation

Install manually

  • Add the following line in ~/.config/xplr/init.lua

    local home = os.getenv("HOME")
    package.path = home
    .. "/.config/xplr/plugins/?/init.lua;"
    .. home
    .. "/.config/xplr/plugins/?.lua;"
    .. package.path
  • Clone the plugin

    mkdir -p ~/.config/xplr/plugins
    
    git clone https://github.com/sayanarijit/command-mode.xplr ~/.config/xplr/plugins/command-mode
  • Require the module in ~/.config/xplr/init.lua

    require("command-mode").setup()
    
    -- Or
    
    require("command-mode").setup{
      mode = "default",
      key = ":",
      remap_action_mode_to = {
        mode = "default",
        key = ";",
      }
    }
    
    -- Type `:` to enter command mode

Usage

Examples are taken from here and here.

-- Assuming you have installed and setup the plugin

local m = require("command-mode")

-- Setup with default settings
m.setup()

-- Type `:hello-lua` and press enter to know your location
local hello_lua = m.cmd("hello-lua", "Enter name and know location")(function(app)
  print("What's your name?")

  local name = io.read()
  local greeting = "Hello " .. name .. "!"
  local message = greeting .. " You are inside " .. app.pwd

  return {
    { LogSuccess = message },
  }
end)

-- Type `:hello-bash` and press enter to know your location
local hello_bash = m.silent_cmd("hello-bash", "Enter name and know location")(
  m.BashExec [===[
    echo "What's your name?"

    read name
    greeting="Hello $name!"
    message="$greeting You are inside $PWD"

    "$XPLR" -m "LogSuccess: %q" "$message"
  ]===]
)

-- Bind `:hello-lua` to key `h`
hello_lua.bind("default", "h")
-- or xplr.config.modes.builtin.default.key_bindings.on_key.h = hello_lua.action

-- Bind `:hello-bash` to key `H`
hello_bash.bind(xplr.config.modes.builtin.default, "H")
-- or xplr.config.modes.builtin.default.key_bindings.on_key.H = hello_bash.action

NOTE: To define non-interactive commands, use silent_cmd to avoid the flickering of screen.

Features

  • Tab completion
  • Command history navigation
  • Press ? to list commands
  • Press ! to spawn shell
  • Easily map keys to commands
  • Shortcut for BashExec and BashExecSilently messages.
  • Interactive UI