The selective interface here is an Anything-like tool in Emacs. It will be easier to understand this point by looking at the image.
Such tools have a variety of applications.
The selective interface allows you to select the output result by connecting it with a pipe. And the selected one will be finally output.
You can use this output to mediate various tools and get values.
percol
A selective interface tool written in python
.
https://github.com/mooz/percol
python
$ sudo pip install percol
Or
python
$ git clone https://github.com/mooz/percol
$ cd !$:t
$ sudo python setup.py install
python
$ ls | percol
Matches a specific string from the beginning.
python
$ ls ~ | percol --query="s"
Customize the left side of the prompt.
python
$ ls | percol --right-prompt=prompt1
With percol, you can also set key bindings by creating a configuration file.
python
$ mkdir ~/.percol.d
$ vim ~/.percol.d/rc.py
python:~/.percol.d/rc.py
# https://gist.github.com/mitukiii/4234173
import sys, commands
from percol.command import SelectorCommand
from percol.key import SPECIAL_KEYS
from percol.finder import FinderMultiQueryMigemo, FinderMultiQueryRegex
## prompt
# Case Insensitive /Prompt according to Match Method
def dynamic_prompt():
prompt = ur""
if percol.model.finder.__class__ == FinderMultiQueryMigemo:
prompt += "[Migemo]"
elif percol.model.finder.__class__ == FinderMultiQueryRegex:
prompt += "[Regexp]"
else:
prompt += "[String]"
if percol.model.finder.case_insensitive:
prompt += "[a]"
else:
prompt += "[A]"
prompt += "> %q"
return prompt
percol.view.__class__.PROMPT = property(lambda self: dynamic_prompt())
## migemo
#Change dictionary path on Mac and Ubuntu
if sys.platform == "darwin":
FinderMultiQueryMigemo.dictionary_path = "/usr/local/Cellar/cmigemo/20110227/share/migemo/utf-8/migemo-dict"
else:
FinderMultiQueryMigemo.dictionary_path = "/usr/local/share/migemo/utf-8/migemo-dict"
## kill
#Share kill (yank) with clipboard on Mac
if sys.platform == "darwin":
def copy_end_of_line_as_kill(self):
commands.getoutput("echo " + self.model.query[self.model.caret:] + " | pbcopy")
self.model.query = self.model.query[:self.model.caret]
def paste_as_yank(self):
self.model.insert_string(commands.getoutput("pbpaste"))
SelectorCommand.kill_end_of_line = copy_end_of_line_as_kill
SelectorCommand.yank = paste_as_yank
## keymap
#Make delete (backspace) work on Mac
SPECIAL_KEYS.update({
127: '<backspace>'
})
percol.import_keymap({
"C-a" : lambda percol: percol.command.beginning_of_line(),
"C-e" : lambda percol: percol.command.end_of_line(),
"C-b" : lambda percol: percol.command.backward_char(),
"C-f" : lambda percol: percol.command.forward_char(),
"C-d" : lambda percol: percol.command.delete_forward_char(),
"C-h" : lambda percol: percol.command.delete_backward_char(),
"C-k" : lambda percol: percol.command.kill_end_of_line(),
"C-y" : lambda percol: percol.command.yank(),
"C-n" : lambda percol: percol.command.select_next(),
"C-p" : lambda percol: percol.command.select_previous(),
"C-v" : lambda percol: percol.command.select_next_page(),
"M-v" : lambda percol: percol.command.select_previous_page(),
"M-<" : lambda percol: percol.command.select_top(),
"M->" : lambda percol: percol.command.select_bottom(),
"C-m" : lambda percol: percol.finish(),
"C-j" : lambda percol: percol.finish(),
"C-g" : lambda percol: percol.cancel(),
"M-c" : lambda percol: percol.command.toggle_case_sensitive(),
"M-m" : lambda percol: percol.command.toggle_finder(FinderMultiQueryMigemo),
"M-r" : lambda percol: percol.command.toggle_finder(FinderMultiQueryRegex)
})
reference: Super convenient if you put percol and combine it with zsh
I tried the terminal version of anything-like percol instead of zaw
To select multiple lines, use percol.command.toggle_mark_and_next ()
. By default, it seems to be set to C-S
.
python
$ ps ax | percol | awk '{ print $1 }' | xargs kill
In my case, I am writing the following configuration file. Multi-line mark and mark cancellation.
python:~/.percol.d/rc.py
"C-n" : lambda percol: percol.command.toggle_mark_and_next(),
"C-p" : lambda percol: percol.command.unmark_all(),
You can also set the delimiter with the following command.
python
$ ls | percol | tr '\n' ';'
When cloning from GitHub, it seems that it is prepared from the beginning.
https://github.com/mooz/percol/blob/master/tools/zsh/_percol
python
$ curl -o ~/.zsh/functions/_percol https://raw.githubusercontent.com/mooz/percol/master/tools/zsh/_percol
$ exec $SHELL
If cdr is created, it seems that you can easily move by the following method.
~/.zshrc
# http://piyopiyoducky.net/blog/2013/08/17/cdr-with-percol/
### search a destination from cdr list
function percol-get-destination-from-cdr() {
cdr -l | \
sed -e 's/^[[:digit:]]*[[:blank:]]*//' | \
percol --match-method migemo --query "$LBUFFER"
}
### search a destination from cdr list and cd the destination
function percol-cdr() {
local destination="$(percol-get-destination-from-cdr)"
if [ -n "$destination" ]; then
BUFFER="cd $destination"
zle accept-line
else
zle reset-prompt
fi
}
zle -N percol-cdr
bindkey '^xb' percol-cdr
Other than that, click here.
~/.zshrc
# https://github.com/shibayu36/config-file/blob/master/.zsh/percol-sources/cdr.zsh
function percol-cdr () {
local selected_dir=$(cdr -l | awk '{ print $2 }' | percol)
if [ -n "$selected_dir" ]; then
BUFFER="cd ${selected_dir}"
zle accept-line
fi
zle clear-screen
}
zle -N percol-cdr
bindkey '^@' percol-cdr
reference:
I wrote a cd to the directory I went to recently with percol
Move to Anything-like directory recently moved by Zsh cdr and percol --PiyoPiyoDucky
Migrate from autojump to percol-based directory jump | Web scratch
Makes your directory structure easier to use.
python
$ go get github.com/motemen/ghq
Details are introduced in the following articles.
Unified and efficient management of local repositories using ghq --delirious thoughts
The zsh completion file of the ghq command has been modified, so I will explain the process --Qiita
Percol is also very useful for making git commands easier to use.
Details are introduced in the following articles.
Settings that make it easier to branch redmine tickets using percol and git-issue | Technology-Gym
Use percol to copy the git commit hash value to the clipboard-Qiita
Git --auto-complete pull request and check out --Qiita
peco
A selective interface tool written in golang
based on percol
.
https://github.com/lestrrat/peco
The configuration file can be edited as follows.
golang:~/.peco/config.json
{
"Keymap": {
"C-p": "peco.SelectPrevious",
"C-n": "peco.SelectNext",
"C-c": "peco.Cancel"
}
}
Details are introduced in the following articles.
Command "peco" that makes the Windows command prompt 10 times more convenient
Introduced peco and used it for zsh history-Goodbye Internet
Recommended Posts