Change def -shell-params to def -params and take the counts as parameters
This commit is contained in:
parent
7335065d20
commit
550a95a3d7
|
@ -5,7 +5,7 @@ decl -hidden str-list clang_completions
|
||||||
decl -hidden line-flag-list clang_flags
|
decl -hidden line-flag-list clang_flags
|
||||||
decl -hidden str clang_errors
|
decl -hidden str clang_errors
|
||||||
|
|
||||||
def -shell-params clang-parse -docstring "Parse the contents of the current buffer with clang" %{
|
def clang-parse -docstring "Parse the contents of the current buffer with clang" %{
|
||||||
%sh{
|
%sh{
|
||||||
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
|
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
|
||||||
mkfifo ${dir}/fifo
|
mkfifo ${dir}/fifo
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
decl str-list ctagsfiles 'tags'
|
decl str-list ctagsfiles 'tags'
|
||||||
|
|
||||||
def -shell-params \
|
def -params 0..1 \
|
||||||
-shell-completion '
|
-shell-completion '
|
||||||
( for tags in $(echo "${kak_opt_ctagsfiles}" | tr \':\' \'\n\');
|
( for tags in $(echo "${kak_opt_ctagsfiles}" | tr \':\' \'\n\');
|
||||||
do readtags -t "${tags}" -p "$1"
|
do readtags -t "${tags}" -p "$1"
|
||||||
|
|
|
@ -25,7 +25,7 @@ decl line-flag-list git_diff_flags
|
||||||
|
|
||||||
face GitBlame default,magenta
|
face GitBlame default,magenta
|
||||||
|
|
||||||
def -shell-params \
|
def -params 1.. \
|
||||||
-docstring %sh{printf "%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}"} \
|
-docstring %sh{printf "%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}"} \
|
||||||
-shell-completion %{
|
-shell-completion %{
|
||||||
shift $(expr ${kak_token_to_complete})
|
shift $(expr ${kak_token_to_complete})
|
||||||
|
|
|
@ -2,7 +2,7 @@ decl str grepcmd 'grep -RHn'
|
||||||
decl str toolsclient
|
decl str toolsclient
|
||||||
decl -hidden int _grep_current_line 0
|
decl -hidden int _grep_current_line 0
|
||||||
|
|
||||||
def -shell-params -file-completion \
|
def -params .. -file-completion \
|
||||||
grep -docstring "Grep utility wrapper" %{ %sh{
|
grep -docstring "Grep utility wrapper" %{ %sh{
|
||||||
output=$(mktemp -d -t kak-grep.XXXXXXXX)/fifo
|
output=$(mktemp -d -t kak-grep.XXXXXXXX)/fifo
|
||||||
mkfifo ${output}
|
mkfifo ${output}
|
||||||
|
|
|
@ -2,7 +2,7 @@ decl str makecmd make
|
||||||
decl str toolsclient
|
decl str toolsclient
|
||||||
decl -hidden int _make_current_error_line
|
decl -hidden int _make_current_error_line
|
||||||
|
|
||||||
def -shell-params make -docstring "Make utility wrapper" %{ %sh{
|
def -params .. make -docstring "Make utility wrapper" %{ %sh{
|
||||||
output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo
|
output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo
|
||||||
mkfifo ${output}
|
mkfifo ${output}
|
||||||
( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
|
( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
|
||||||
|
|
|
@ -14,7 +14,7 @@ hook global WinSetOption filetype=(?!man).* %{
|
||||||
rmhooks window man-hooks
|
rmhooks window man-hooks
|
||||||
}
|
}
|
||||||
|
|
||||||
def -hidden -shell-params _man %{ %sh{
|
def -hidden -params .. _man %{ %sh{
|
||||||
manout=$(mktemp /tmp/kak-man-XXXXXX)
|
manout=$(mktemp /tmp/kak-man-XXXXXX)
|
||||||
colout=$(mktemp /tmp/kak-man-XXXXXX)
|
colout=$(mktemp /tmp/kak-man-XXXXXX)
|
||||||
MANWIDTH=${kak_window_width} man "$@" > $manout
|
MANWIDTH=${kak_window_width} man "$@" > $manout
|
||||||
|
@ -33,7 +33,7 @@ def -hidden -shell-params _man %{ %sh{
|
||||||
fi
|
fi
|
||||||
} }
|
} }
|
||||||
|
|
||||||
def -shell-params \
|
def -params .. \
|
||||||
-shell-completion %{
|
-shell-completion %{
|
||||||
prefix=${1:0:${kak_pos_in_token}}
|
prefix=${1:0:${kak_pos_in_token}}
|
||||||
for page in /usr/share/man/*/${prefix}*.[1-8]*; do
|
for page in /usr/share/man/*/${prefix}*.[1-8]*; do
|
||||||
|
|
10
rc/tmux.kak
10
rc/tmux.kak
|
@ -12,7 +12,7 @@ hook global KakBegin .* %{
|
||||||
}
|
}
|
||||||
|
|
||||||
## Temporarily override the default client creation command
|
## Temporarily override the default client creation command
|
||||||
def -hidden -shell-params tmux-new-impl %{
|
def -hidden -params 1.. tmux-new-impl %{
|
||||||
%sh{
|
%sh{
|
||||||
if [ -z "$TMUX" ]; then
|
if [ -z "$TMUX" ]; then
|
||||||
echo "echo -color Error This command is only available in a tmux session"
|
echo "echo -color Error This command is only available in a tmux session"
|
||||||
|
@ -25,20 +25,20 @@ def -hidden -shell-params tmux-new-impl %{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def tmux-new-vertical -shell-params -command-completion -docstring "Create a new vertical pane in tmux" %{
|
def tmux-new-vertical -params .. -command-completion -docstring "Create a new vertical pane in tmux" %{
|
||||||
%sh{ echo "tmux-new-impl 'split-window -v' $@" }
|
%sh{ echo "tmux-new-impl 'split-window -v' $@" }
|
||||||
}
|
}
|
||||||
|
|
||||||
def tmux-new-horizontal -shell-params -command-completion -docstring "Create a new horizontal pane in tmux" %{
|
def tmux-new-horizontal -params .. -command-completion -docstring "Create a new horizontal pane in tmux" %{
|
||||||
%sh{ echo "tmux-new-impl 'split-window -h' $@" }
|
%sh{ echo "tmux-new-impl 'split-window -h' $@" }
|
||||||
}
|
}
|
||||||
|
|
||||||
def tmux-new-window -shell-params -command-completion -docstring "Create a new horizontal pane in tmux" %{
|
def tmux-new-window -params .. -command-completion -docstring "Create a new horizontal pane in tmux" %{
|
||||||
%sh{ echo "tmux-new-impl 'new-window' $@" }
|
%sh{ echo "tmux-new-impl 'new-window' $@" }
|
||||||
}
|
}
|
||||||
|
|
||||||
def -docstring "focus given client" \
|
def -docstring "focus given client" \
|
||||||
-shell-params -client-completion \
|
-params 0..1 -client-completion \
|
||||||
tmux-focus %{ %sh{
|
tmux-focus %{ %sh{
|
||||||
if [ $# -gt 1 ]; then
|
if [ $# -gt 1 ]; then
|
||||||
echo "echo -color Error 'too many arguments, use focus [client]'"
|
echo "echo -color Error 'too many arguments, use focus [client]'"
|
||||||
|
|
|
@ -19,7 +19,7 @@ decl str termcmd %sh{
|
||||||
}
|
}
|
||||||
|
|
||||||
def -docstring 'create a new kak client for current session' \
|
def -docstring 'create a new kak client for current session' \
|
||||||
-shell-params \
|
-params .. \
|
||||||
-command-completion \
|
-command-completion \
|
||||||
x11-new %{ %sh{
|
x11-new %{ %sh{
|
||||||
if [ -z "${kak_opt_termcmd}" ]; then
|
if [ -z "${kak_opt_termcmd}" ]; then
|
||||||
|
@ -31,7 +31,7 @@ def -docstring 'create a new kak client for current session' \
|
||||||
}}
|
}}
|
||||||
|
|
||||||
def -docstring 'focus given client\'s window' \
|
def -docstring 'focus given client\'s window' \
|
||||||
-shell-params -client-completion \
|
-params 0..1 -client-completion \
|
||||||
x11-focus %{ %sh{
|
x11-focus %{ %sh{
|
||||||
if [ $# -gt 1 ]; then
|
if [ $# -gt 1 ]; then
|
||||||
echo "echo -color Error 'too many arguments, use focus [client]'"
|
echo "echo -color Error 'too many arguments, use focus [client]'"
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
def -shell-params runtime %{ %sh{
|
def -params 1.. runtime %{ %sh{
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
echo "source '${kak_runtime}/$1'"
|
echo "source '${kak_runtime}/$1'"
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
}}
|
}}
|
||||||
|
|
||||||
def -shell-params -docstring "colorscheme <name>: enable named colorscheme" \
|
def -params 1 -docstring "colorscheme <name>: enable named colorscheme" \
|
||||||
-shell-completion %{
|
-shell-completion %{
|
||||||
prefix=${1:0:${kak_pos_in_token}}
|
prefix=${1:0:${kak_pos_in_token}}
|
||||||
(
|
(
|
||||||
|
|
|
@ -721,9 +721,23 @@ void define_command(const ParametersParser& parser, Context& context, const Shel
|
||||||
const String& commands = parser[1];
|
const String& commands = parser[1];
|
||||||
Command cmd;
|
Command cmd;
|
||||||
ParameterDesc desc;
|
ParameterDesc desc;
|
||||||
if (parser.get_switch("shell-params"))
|
if (auto params = parser.get_switch("params"))
|
||||||
{
|
{
|
||||||
desc = ParameterDesc{ {}, ParameterDesc::Flags::SwitchesAsPositional };
|
size_t min = 0, max = -1;
|
||||||
|
StringView counts = *params;
|
||||||
|
static const Regex re{R"((\d+)?..(\d+)?)"};
|
||||||
|
MatchResults<const char*> res;
|
||||||
|
if (regex_match(counts.begin(), counts.end(), res, re))
|
||||||
|
{
|
||||||
|
if (res[1].matched)
|
||||||
|
min = (size_t)str_to_int({res[1].first, res[1].second});
|
||||||
|
if (res[2].matched)
|
||||||
|
max = (size_t)str_to_int({res[2].first, res[2].second});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
min = max = (size_t)str_to_int(counts);
|
||||||
|
|
||||||
|
desc = ParameterDesc{ {}, ParameterDesc::Flags::SwitchesAsPositional, min, max };
|
||||||
cmd = [=](const ParametersParser& parser, Context& context, const ShellContext&) {
|
cmd = [=](const ParametersParser& parser, Context& context, const ShellContext&) {
|
||||||
CommandManager::instance().execute(commands, context, { params_to_shell(parser) });
|
CommandManager::instance().execute(commands, context, { params_to_shell(parser) });
|
||||||
};
|
};
|
||||||
|
@ -815,7 +829,8 @@ const CommandDesc define_command_cmd = {
|
||||||
nullptr,
|
nullptr,
|
||||||
"def <switches> <name> <cmds>: define a command <name> executing <cmds>",
|
"def <switches> <name> <cmds>: define a command <name> executing <cmds>",
|
||||||
ParameterDesc{
|
ParameterDesc{
|
||||||
{ { "shell-params", { false, "pass parameters to each shell escape as $0..$N" } },
|
{ { "params", { true, "take parameters, accessible to each shell escape as $0..$N\n"
|
||||||
|
"parameter should take the form <count> or <min>..<max> (both omittable)" } },
|
||||||
{ "allow-override", { false, "allow overriding an existing command" } },
|
{ "allow-override", { false, "allow overriding an existing command" } },
|
||||||
{ "hidden", { false, "do not display the command in completion candidates" } },
|
{ "hidden", { false, "do not display the command in completion candidates" } },
|
||||||
{ "docstring", { true, "define the documentation string for command" } },
|
{ "docstring", { true, "define the documentation string for command" } },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user