mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Base: Add some default completions to shellrc
This commit is contained in:
parent
1699ddc186
commit
302a0c54f0
Notes:
sideshowbarker
2024-07-17 18:08:55 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/302a0c54f0 Pull-request: https://github.com/SerenityOS/serenity/pull/13686
@ -43,3 +43,5 @@ export HISTORY_AUTOSAVE_TIME_MS=10000
|
||||
export TMPDIR=/tmp
|
||||
|
||||
PROGRAMS_ALLOWED_TO_MODIFY_DEFAULT_TERMIOS=(stty)
|
||||
|
||||
for /usr/share/shell/completion/*.sh { source $it }
|
||||
|
76
Base/usr/share/shell/completion/builtin.sh
Normal file
76
Base/usr/share/shell/completion/builtin.sh
Normal file
@ -0,0 +1,76 @@
|
||||
#!/bin/Shell
|
||||
|
||||
_complete_unalias() {
|
||||
shift 2
|
||||
argsparser_parse \
|
||||
--add-positional-argument names --help-string _ --value-name _ --short-name '' --min 0 --max 9999 \
|
||||
-- $*
|
||||
name=''
|
||||
if test ${length $names} -ne 0 {
|
||||
name="$names[-1]"
|
||||
}
|
||||
invariant="${length $name}"
|
||||
for $(alias | grep "^$name") {
|
||||
n=${regex_replace '"' '\"' ${regex_replace '\\([^\\])' '\1' ${regex_replace '=.*' '' "$it"}}}
|
||||
v=${regex_replace '"' '\"' ${regex_replace '\\([^\\])' '\1' ${regex_replace '[^=]*=' '' "$it"}}}
|
||||
echo '{"kind":"plain","completion":"'"$n"'", "trailing_trivia":" ", "display_trivia":"'"$v"'", "invariant_offset": '$invariant'}'
|
||||
}
|
||||
}
|
||||
|
||||
__complete_job_spec() {
|
||||
match $1 as hint {
|
||||
%?* as (name) {
|
||||
for $(jobs | grep "$name") {
|
||||
id=''
|
||||
match $it {
|
||||
[*]\ * as (i _) { id=$i }
|
||||
* { continue }
|
||||
}
|
||||
echo '{"kind":"plain","static_offset":'"${length "?$name"}"',"invariant_offset":0,"completion":"'"$id"'"}'
|
||||
}
|
||||
}
|
||||
%* as (id) {
|
||||
invariant=${length $id}
|
||||
for $(jobs | grep "^\\[$id\\d+\\]") {
|
||||
id=''
|
||||
match $it {
|
||||
[*]\ * as (i _) { id=$i }
|
||||
* { continue }
|
||||
}
|
||||
echo '{"kind":"plain","static_offset":0,"invariant_offset":'"$invariant"',"completion":"'"$id"'"}'
|
||||
}
|
||||
}
|
||||
(?<pid>^\d+$) {
|
||||
invariant=${length $pid}
|
||||
for $(ps -e | grep "^ *$pid") {
|
||||
id=''
|
||||
description=''
|
||||
match $it {
|
||||
"*$pid* *" as (_ i rest) { id="$pid$i" description="$rest" }
|
||||
* { continue }
|
||||
}
|
||||
echo '{"kind":"plain","static_offset":0,"invariant_offset":'"$invariant"',"completion":"'"$id"'","display_trivia":"'"$description"'"}'
|
||||
}
|
||||
}
|
||||
* as (name) {
|
||||
static="${length $name}"
|
||||
for $(ps -e | grep "$name") {
|
||||
id=''
|
||||
description=''
|
||||
match $it {
|
||||
(?: *(?<pid>\d+) (?<rest>.*)) { id="$pid" description="$rest" }
|
||||
* { continue }
|
||||
}
|
||||
echo '{"kind":"plain","static_offset":'"$static"',"invariant_offset":0,"completion":"'"$id"'","display_trivia":"'"$description"'","allow_commit_without_listing":false}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_complete_kill() {
|
||||
if test $*[-1] = '--' {
|
||||
__complete_job_spec ''
|
||||
} else {
|
||||
__complete_job_spec $*[-1]
|
||||
}
|
||||
}
|
30
Base/usr/share/shell/completion/proxy.sh
Normal file
30
Base/usr/share/shell/completion/proxy.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/bin/Shell
|
||||
|
||||
__proxy() {
|
||||
echo '{"kind":"proxy","argv":"'"${regex_replace '"' '\"' "$*"}"'"}'
|
||||
}
|
||||
|
||||
# Builtins
|
||||
_complete_time() {
|
||||
shift 2
|
||||
argsparser_parse \
|
||||
--add-option _ --help-string "Number of iterations" \
|
||||
--long-name iterations --short-name n --value-name iterations --type u32 \
|
||||
--add-positional-argument argv --help-string _ \
|
||||
--value-name _ --min 0 --max 9999999 \
|
||||
--stop-on-first-non-option \
|
||||
-- $*
|
||||
__proxy $argv
|
||||
}
|
||||
|
||||
# Utilities
|
||||
_complete_pls() {
|
||||
shift 2
|
||||
argsparser_parse \
|
||||
--add-option _ --help-string "User to execute as" --short-name u --value-name UID \
|
||||
--add-positional-argument argv --help-string "Command to run at elevated privilege level" \
|
||||
--value-name command --min 0 --max 999999 \
|
||||
--stop-on-first-non-option \
|
||||
-- $*
|
||||
__proxy $argv
|
||||
}
|
@ -12,7 +12,9 @@ if [ "$#" -eq "0" ]; then
|
||||
':!:Ports' \
|
||||
':!:Userland/Shell/Tests' \
|
||||
':!:Base/home/anon/Tests' \
|
||||
':!:Base/root/generate_manpages.sh'
|
||||
':!:Base/root/generate_manpages.sh' \
|
||||
':!:Base/usr/share/shell' \
|
||||
':!:Base/etc/shellrc' \
|
||||
)
|
||||
else
|
||||
files=()
|
||||
|
Loading…
Reference in New Issue
Block a user