Skip to content

Commit

Permalink
Public release
Browse files Browse the repository at this point in the history
  • Loading branch information
Tero Karvinen committed Nov 4, 2022
1 parent c26ce29 commit 05d80b6
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 2 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# palettero
Command palette - Ctrl-P to fuzzy search & run commands, textfilters and descriptions - Micro editor plugin
# Palettero - command palette / menu for Micro editor

Command palette for Micro editor - fuzzy search commands and textfilters

The first and original command paletter for Micro.

![Screenshot](palettero-command-palette-menu-for-micro-editor.png)

# Usage

Press **Ctrl-P** to open Palettero. Type to fuzzy search commands and their descriptions. Use up and down arrows to move. Press enter to select, or Esc to cancel.

Command is pre-filled to command bar. Edit the command, then press enter to execute.

Tab completes file names in some commands, such as "tab" and "open".

# Requirements

Requires: fzf, bash

Only tested on Linux.

# Adding your own commands

You can add your own commands to $HOME/.config/micro/palettero.cfg

# Adminstrivia

https://TeroKarvinen.com/micro
79 changes: 79 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
-- Copyright 2022 Tero Karvinen http://TeroKarvinen.com
-- Command palette - fuzzy search commands and textfilters
-- A Micro editor plugin

local micro = import("micro")
local config = import("micro/config")
local shell = import("micro/shell")
local menufile = config.ConfigDir.."/plug/palettero/palettero-defaults.cfg"
local userfile = config.ConfigDir.."/palettero.cfg"

function init()
-- runs once when micro starts
config.MakeCommand("palettero", paletteroCommand, config.NoComplete)
config.TryBindKey("CtrlP", "command:palettero", false)
shell.ExecCommand("touch", userfile)
end

-- ## Prompt ##

function commandBar(command)
-- open ctrl-E command bar, fill it with start of command, allow user to fill the rest
micro.InfoBar():Prompt("T> ", command, "Command", nil, promptDoneCallback)
end

function promptDoneCallback(resp, cancelled)
-- called by prompt() when user is done with ctrl-E command bar
if cancelled then
micro.InfoBar():Message("Command cancelled.")
end
micro.InfoBar():Message("Running: ", resp)

local bp = micro.CurPane()
bp:HandleCommand(resp)
end

-- ## palette command ##

function paletteroCommand(bp)
-- ctrl-E palettero
micro.InfoBar():Message("Palettero command palette activated!")

n local showMenuCmd = string.format("bash -c \"cat '%s' '%s'|fzf --layout=reverse\"", menufile, userfile)
micro.Log("Requesting user input with: ", showMenuCmd) -- run 'micro --debug tero' to create log.txt
local choice = shell.RunInteractiveShell(showMenuCmd, false, true)
micro.Log("User chose: ", choice)
local cmd = getCommand(choice)
micro.Log("Command: ", cmd)
if nil == cmd then
micro.InfoBar():Message("Empty choice, not running.")
return
end
micro.InfoBar():Message("Running: ", cmd)
-- bp:HandleCommand(cmd)
commandBar(cmd)
end

-- ## Menu item collection ##

function getCommand(s)
-- return command part of string, or empty if string starts with comment char
-- "command # comment" -> "command"
-- "# command # comment" -> ""
-- "command # comment # comment" -> "command"

if string.len(s) == 0 then
return
end

if "#" == s:sub(1,1) then
return "" -- string starts with comment character
end

local cmd = string.match(s, "([^#]*) ?#")
if nil ~= cmd and string.len(cmd) > 0 then
return cmd -- string had a comment char, return what was before it
end

return s -- no comment char in string
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions palettero-defaults.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
textfilter grep -v ^\s*$ # remove empty lines
textfilter sort # alphabethical order
textfilter busybox awk '{print $2 " " $1}' # swap first and second word
textfilter busybox fold -s -w 79 # hard wrap
textfilter busybox nl # number lines
textfilter tr ' ' ',' # space to comma
textfilter tr '\n' ',' # newline to comma, join lines
textfilter py -x x.lower() # lower case, # apt-get install pythonpy
textfilter py -x x.title() # Title Case, # apt-get install pythonpy
goto 99999999 # jump to end of file
goto 0 # jump to start of file
set colorscheme simple # black on white, daytime color theme +sensiblesettings
set ftoptions false # allow indent with tabs in Python, also: set tabstospaces false +sensiblesettings
set tabstospaces false # indent with tab +sensiblesettings
retab # convert indentation to tabs/spaces, as you have chosen with 'set tabstospaces false'
set ruler true # show line numbers
set ruler false # hide line numbers
set softwrap true # wrap lines to fit screen, but don't really insert newlines. Also: set wordwrap true
set wordwrwap true # wrap at white space. Also: set softwrap true
set autoclose false # don't automatically add matching brackets (){}[]
textfilter base64 # ASCII armor so that binary can be copy-pasted as text
textfilter base64 --decode # convert ASCII armored text back to binary; base64 often ends with "="
textfilter busybox tr '[a-zA-Z]' '[n-za-mN-ZA-M]' # rot13, caesar encryption, a simple substitute cipher
textfilter py -x 'urllib.parse.unquote(x)' # URL decode # apt-get install pythonpy
textfilter busybox tr -s ' ' # squeeze space, convert multiple spaces to one
reset colorscheme # reset colorscheme setting to default. See also: 'set colorscheme simple'
plugin list # list installed plugins
plugin available # list plugins that could be installed with 'plugin install jump'
plugin install # install a plugin from the list shown by 'plugin available'
plugin search jump # search plugin names
set # set micro options, such as ruler, softwrap, tabstospaces...
reset # reset a setting to it's default value 'reset colorscheme'
setlocal # set an option just for this buffer (current document), 'setlocal readonly on'
show # show value of an option, 'show colorscheme'
showkey # shows action for a key binding, 'showkey Ctrl-P'
run # run a shell command in the background 'run touch /tmp/palettero-was-here', no output, only exit status
bind # bind a key to action, 'bind Ctrl-J command:palettero'
unbind # should bind key to its default action, but did not work in the tested version
help plugins # plugin developer help, Lua coding and accessing micro Go internals with Lua
quit # quit micro, typically Ctrl-Q
goto # jump to line, first line is 1. 'goto 88'
save # save current buffer (the document you're editing). Often Ctrl-S.
replace # interactively replace each "foo" with "BAR", ask for each, 'replace foo BAR'. Regexp support.
replaceall # immediately replace all "foo" with "BAR", 'replaceall foo BAR'. Regexp support.
vsplit # open new vertical split on right side, optionally open named file. 'vsplit right.md'
hsplit # open a new horizontal split on the bottom, optionally open file. 'hsplit bottom.md'
tab # open a new tab, optionally open a file 'tab tero.md'
help # open help in a new bottom hsplit, optionally at given document 'help plugins'
eval # unsupported - would evaluate a Lua expression, but is not implemented in the version tested
log # toggle log view. Mostly commands given with Ctrl-E command bar, can have other logs.
plugin # install, remove, update (plugins); list (installed), (show) available (but not installed), search
reload # reload all configuration files: syntax, colorschemes...
reopen # Load current buffer (the file you're editing) from disk
cd # change working directory
pwd # print working directory
open # open a new file for editing. Tab completes filenames.
tabmove # move the current tab to given index, 1 is the first.
tabswitch # select given tab, 1 is the first
term # open terminal in a new tab
memusage # show how much micro is taking RAM memory
raw # show escape sequences of keys you press, in a new tab
textfilter # run any command to edit selection, 'textfilter tr "a" "B"'

15 changes: 15 additions & 0 deletions repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[{
"Name": "palettero",
"Description": "Command palette Ctrl-P - fuzzy search commands and textfilters",
"Website": "https://terokarvinen.com/tags/micro-editor/",
"Tags": ["command palette", "fzf", "menu"],
"Versions": [
{
"Version": "0.0.2",
"Url": "https://github.com/terokarvinen/palettero/archive/v0.0.2.zip",
"Require": {
"micro": ">=2.0.0"
}
}
]
}]

0 comments on commit 05d80b6

Please sign in to comment.