Commit initial
This commit is contained in:
commit
df4f2c07c1
67 changed files with 1781 additions and 0 deletions
48
lib/moi/completion/arc.elv
Normal file
48
lib/moi/completion/arc.elv
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
use moi/util/condition
|
||||
use moi/util/file
|
||||
|
||||
commands = [
|
||||
help
|
||||
archive
|
||||
unarchive
|
||||
extract
|
||||
ls
|
||||
]
|
||||
|
||||
extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
||||
|
||||
fn -comp-commands { explode $commands }
|
||||
|
||||
fn -comp-archive-files [m]{
|
||||
local:type = (condition:set (eq $m '') prefix deep-prefix)
|
||||
file:match-extensions &type=$type $m $@extensions
|
||||
}
|
||||
|
||||
fn -comp-inline-files [archive]{
|
||||
try {
|
||||
e:arc ls $archive | eawk [_ @argv]{ put $argv[-1] }
|
||||
} except e {
|
||||
nop
|
||||
}
|
||||
}
|
||||
|
||||
fn complete [@argv]{
|
||||
local:c = (count $argv)
|
||||
local:cmd = $argv[1]
|
||||
if (== $c 2) {
|
||||
-comp-commands
|
||||
} elif (== $c 3) {
|
||||
if (not (has-value [help archive] $cmd)) {
|
||||
-comp-archive-files $argv[-1]
|
||||
}
|
||||
} else {
|
||||
if (eq $cmd archive) {
|
||||
edit:complete-filename $@argv
|
||||
} elif (eq $cmd extract) {
|
||||
local:archive = $argv[2]
|
||||
-comp-inline-files $archive
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[arc] = $complete~
|
||||
29
lib/moi/completion/archiver.elv
Normal file
29
lib/moi/completion/archiver.elv
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
options = [
|
||||
z
|
||||
l
|
||||
x
|
||||
b
|
||||
g
|
||||
h
|
||||
]
|
||||
|
||||
description = [
|
||||
&z='zst compression (default)'
|
||||
&l='lz4 compression'
|
||||
&x='xz compression'
|
||||
&b='bz2 compression'
|
||||
&g='gzip compression'
|
||||
&h='display help'
|
||||
]
|
||||
|
||||
fn -options {
|
||||
each [o]{
|
||||
put [&short=$o &desc=$description[$o]]
|
||||
} $options
|
||||
}
|
||||
|
||||
fn complete [@argv]{
|
||||
edit:complete-getopt $argv [(-options)] [ $edit:complete-filename~ ...]
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[archiver] = $complete~
|
||||
12
lib/moi/completion/desarchiver.elv
Normal file
12
lib/moi/completion/desarchiver.elv
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use moi/util/condition
|
||||
use moi/util/file
|
||||
|
||||
extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
||||
|
||||
fn complete [@argv]{
|
||||
local:m = $argv[-1]
|
||||
local:type = (condition:set (eq $m '') prefix deep-prefix)
|
||||
file:match-extensions &type=$type $m $@extensions
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[desarchiver] = $complete~
|
||||
41
lib/moi/completion/kcp.elv
Normal file
41
lib/moi/completion/kcp.elv
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
fn -remotes-packages { kcp -lN }
|
||||
|
||||
options = [
|
||||
-h
|
||||
-v
|
||||
-i
|
||||
-di
|
||||
-u
|
||||
-l
|
||||
-lN
|
||||
-lS
|
||||
-lI
|
||||
-lO
|
||||
-lx
|
||||
-lxS
|
||||
-lxI
|
||||
-lxO
|
||||
-lf
|
||||
-s
|
||||
-g
|
||||
-V
|
||||
]
|
||||
|
||||
np = [
|
||||
-i
|
||||
-di
|
||||
-s
|
||||
-g
|
||||
-V
|
||||
]
|
||||
|
||||
fn complete [@argv]{
|
||||
local:c = (count $argv)
|
||||
if (== $c 2) {
|
||||
explode $options
|
||||
} elif (and (== $c 3) (has-value $np $argv[-2])) {
|
||||
-remotes-packages
|
||||
}
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[kcp] = $complete~
|
||||
59
lib/moi/completion/mpv.elv
Normal file
59
lib/moi/completion/mpv.elv
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
use moi/util/condition
|
||||
use moi/util/file
|
||||
|
||||
extensions = [
|
||||
aac
|
||||
ape
|
||||
avi
|
||||
divx
|
||||
flac
|
||||
flv
|
||||
m3u
|
||||
m4a
|
||||
m4v
|
||||
mp3
|
||||
mp4
|
||||
mpeg
|
||||
mpg
|
||||
mkv
|
||||
mng
|
||||
mov
|
||||
qt
|
||||
oga
|
||||
ogg
|
||||
ogm
|
||||
ogv
|
||||
opus
|
||||
ra
|
||||
rv
|
||||
ts
|
||||
vob
|
||||
wav
|
||||
webm
|
||||
wmv
|
||||
wma
|
||||
wmx
|
||||
]
|
||||
|
||||
fn -files [m]{
|
||||
local:type = (condition:set (eq $m '') prefix deep-prefix)
|
||||
file:match-extensions &type=$type $m $@extensions
|
||||
}
|
||||
|
||||
fn complete [@argv]{
|
||||
c = (count $argv)
|
||||
if (== $c 2) {
|
||||
put --speed
|
||||
-files $argv[-1]
|
||||
} elif (== $c 3) {
|
||||
if (eq $argv[-2] --speed) {
|
||||
put 0.8 0.9 1.0 1.1 1.2
|
||||
} else {
|
||||
-files $argv[-1]
|
||||
}
|
||||
} else {
|
||||
-files $argv[-1]
|
||||
}
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[mpv] = $complete~
|
||||
104
lib/moi/completion/pacman.elv
Normal file
104
lib/moi/completion/pacman.elv
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
use moi/util/condition
|
||||
use moi/util/file
|
||||
use moi/util/list
|
||||
|
||||
fn -local-packages { pacman -Q | eawk [_ p @_]{ put $p } }
|
||||
|
||||
fn -repo-packages {
|
||||
local:packages = [(pacman -Ss | list:ploop &step=2 [_ v]{
|
||||
put $v
|
||||
} | eawk [_ p @_]{
|
||||
put $p
|
||||
})]
|
||||
local:spackages = [&]
|
||||
peach [p]{
|
||||
splits '/' $p
|
||||
} $packages | peach [e]{
|
||||
spackages[$e] = $nil
|
||||
}
|
||||
keys $spackages
|
||||
explode $packages
|
||||
}
|
||||
|
||||
fn -downloaded-packages [m]{
|
||||
local:type = (condition:set (eq $m '') prefix deep-prefix)
|
||||
file:match-extensions &type=$type $m tar.zst tar.xz tar.gz tar.bz2
|
||||
}
|
||||
|
||||
fn -local-file [m]{ edit:complete-filename $m }
|
||||
|
||||
options = [
|
||||
-h
|
||||
-V
|
||||
-Q
|
||||
-Qs
|
||||
-Ql
|
||||
-Qi
|
||||
-Qm
|
||||
-Qdt
|
||||
-Qo
|
||||
-R
|
||||
-Rsn
|
||||
-S
|
||||
-Ss
|
||||
-Si
|
||||
-Sii
|
||||
-Syu
|
||||
-Syyu
|
||||
-U
|
||||
-D
|
||||
]
|
||||
|
||||
asdeps = [
|
||||
-S
|
||||
-U
|
||||
-D
|
||||
]
|
||||
|
||||
lpack = [
|
||||
-Q
|
||||
-Qs
|
||||
-Ql
|
||||
-Qi
|
||||
-D
|
||||
-R
|
||||
-Rsn
|
||||
]
|
||||
|
||||
rpack = [
|
||||
-S
|
||||
-Ss
|
||||
-Si
|
||||
-Sii
|
||||
]
|
||||
|
||||
dpack = [
|
||||
-U
|
||||
]
|
||||
|
||||
fpack = [
|
||||
-Qo
|
||||
]
|
||||
|
||||
fn complete [@argv]{
|
||||
local:c = (count $argv)
|
||||
if (< $c 3) {
|
||||
explode $options
|
||||
} else {
|
||||
local:cmd = $argv[1]
|
||||
if (and (== $c 3) (has-value $asdeps $cmd)) {
|
||||
put --asdeps --asexplicit
|
||||
}
|
||||
if (has-value $lpack $cmd) {
|
||||
-local-packages
|
||||
} elif (has-value $rpack $cmd) {
|
||||
-repo-packages
|
||||
} elif (has-value $dpack $cmd) {
|
||||
-downloaded-packages $argv[-1]
|
||||
} elif (has-value $fpack $cmd) {
|
||||
-local-file $argv[-1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[pacman] = $complete~
|
||||
251
lib/moi/completion/ssh.elv
Normal file
251
lib/moi/completion/ssh.elv
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
use re
|
||||
use str
|
||||
use moi/util/condition
|
||||
use moi/util/file
|
||||
use moi/util/ip
|
||||
use moi/util/list
|
||||
use moi/util/map
|
||||
use moi/util/option
|
||||
|
||||
options-ssh = [ 1 2 4 6 A D f g I i L l m o v a b C c e F k N n p q R s T t X x ]
|
||||
options-scp = [ 3 4 6 B C p q r v c F i l o P S ]
|
||||
|
||||
fn -init-hosts {
|
||||
local:result = [&]
|
||||
cat /etc/hosts | peach $str:trim-space~ | peach [l]{
|
||||
local:l = $l
|
||||
if (and (not-eq $l '') (not-eq $l[0] '#')) {
|
||||
put $l
|
||||
}
|
||||
} | eawk [_ ip @domains]{
|
||||
if (ip:is-ip $ip) {
|
||||
put [$ip $domains]
|
||||
}
|
||||
} | peach [e]{
|
||||
local:ip local:domains = $@e
|
||||
if (ip:is-ipv6 $ip) {
|
||||
ip = (ip:short6 $ip)
|
||||
}
|
||||
each [d]{
|
||||
if (eq $d[0] '#') {
|
||||
break
|
||||
}
|
||||
put [$ip $d]
|
||||
} $domains
|
||||
} | each [e]{
|
||||
local:ip local:d = $@e
|
||||
local:ipd = (map:value-of $result $ip &default=[&])
|
||||
ipd[$d] = $nil
|
||||
result[$ip] = $ipd
|
||||
}
|
||||
put $result
|
||||
}
|
||||
|
||||
fn -init-known-hosts {
|
||||
local:khosts = [&22=[&]]
|
||||
cat ~/.ssh/known_hosts | peach [l]{
|
||||
put [(splits ' ' $l)]
|
||||
} | peach [e]{
|
||||
local:domains @local:id = $@e
|
||||
id = (joins ' ' $id)
|
||||
splits ',' $domains | peach [d]{
|
||||
local:d = $d
|
||||
local:port = 22
|
||||
if (eq $d[0] '[') {
|
||||
local:i = (str:index $d ']')
|
||||
port = $d[(+ $i 2):]
|
||||
d = $d[1:$i]
|
||||
}
|
||||
put [$id $d $port]
|
||||
}
|
||||
} | each [e]{
|
||||
local:id local:d local:port = $@e
|
||||
local:pdomains = (map:value-of $khosts $port &default=[&])
|
||||
local:idomains = (map:value-of $pdomains $id &default=[&])
|
||||
idomains[$d] = $nil
|
||||
pdomains[$id] = $idomains
|
||||
khosts[$port] = $pdomains
|
||||
}
|
||||
local:result = [&22=[&]]
|
||||
keys $khosts | each [port]{
|
||||
local:pdomains = (map:value-of $result $port &default=[&])
|
||||
keys $khosts[$port] | peach [id]{
|
||||
local:id = $id
|
||||
local:domains = [(keys $khosts[$port][$id])]
|
||||
if (list:contains-not $ip:is-ip~ $domains) {
|
||||
list:filter-not $ip:is-ip~ $domains | peach [d]{ pdomains[$d] = $nil }
|
||||
} else {
|
||||
peach [d]{ pdomains[$d] = $nil } $domains
|
||||
}
|
||||
}
|
||||
result[$port] = $pdomains
|
||||
}
|
||||
put $result
|
||||
}
|
||||
|
||||
|
||||
fn -init-history {
|
||||
local:history = [&]
|
||||
edit:command-history | peach [e]{
|
||||
put $e[cmd]
|
||||
} | peach [h]{
|
||||
if (re:match '^(ssh|scp)\ .+' $h) {
|
||||
history[$h] = $nil
|
||||
}
|
||||
}
|
||||
local:result = [&22=[&]]
|
||||
keys $history | peach [h]{
|
||||
local:h = $h
|
||||
put [(re:split '[ \t]+' $h)]
|
||||
} | peach [e]{
|
||||
local:cmd @local:argv = $@e
|
||||
local:port local:name local:domain = 22 '' ''
|
||||
local:c = (- (count $argv) 1)
|
||||
list:loop [i arg]{
|
||||
if (and (< $i $c) (or (and (eq $cmd ssh) (eq $arg -p)) (eq $arg -P))) {
|
||||
port = $argv[(+ $i 1)]
|
||||
} else {
|
||||
local:nd = [(splits '@' $arg)]
|
||||
if (== (count $nd) 2) {
|
||||
name = $nd[0]
|
||||
domain @_ = (splits ':' $nd[1])
|
||||
break
|
||||
}
|
||||
}
|
||||
} $argv
|
||||
if (and (not-eq $name '') (not-eq $domain '')) {
|
||||
put [$port $name $domain]
|
||||
}
|
||||
} | each [e]{
|
||||
local:port local:name local:domain = $@e
|
||||
local:pnames = (map:value-of $result $port &default=[&])
|
||||
local:domains = (map:value-of $pnames $name &default=[&])
|
||||
domains[$domain] = $nil
|
||||
pnames[$name] = $domains
|
||||
result[$port] = $pnames
|
||||
}
|
||||
put $result
|
||||
}
|
||||
|
||||
combinaisons = [&]
|
||||
|
||||
fn init {
|
||||
local:hosts local:known-hosts local:history = [] [] []
|
||||
peach [f]{ $f } [
|
||||
{ hosts = (-init-hosts) }
|
||||
{ known-hosts = (-init-known-hosts) }
|
||||
{ history = (-init-history) }
|
||||
]
|
||||
combinaisons = $history
|
||||
keys $known-hosts | peach [port]{
|
||||
local:port = $port
|
||||
local:pdomains = $known-hosts[$port]
|
||||
keys $pdomains | peach [domain]{
|
||||
local:domain = $domain
|
||||
if (and (ip:is-ip $domain) (has-key $hosts $domain)) {
|
||||
del pdomains[$domain]
|
||||
keys $hosts[$domain] | peach [d]{
|
||||
local:d = $d
|
||||
pdomains[$d] = $nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if (> (keys $pdomains | count) 0) {
|
||||
if (has-key $history $port) {
|
||||
local:phist = $history[$port]
|
||||
local:dhist = (keys $phist | peach [name]{ keys $phist[$name] } | map:to-set)
|
||||
local:dknown = [&]
|
||||
keys $pdomains | peach [domain]{
|
||||
local:domain = $domain
|
||||
if (not (has-key $dhist $domain)) {
|
||||
dknown[$domain] = $nil
|
||||
}
|
||||
}
|
||||
if (> (keys $dknown | count) 0) {
|
||||
combinaisons[$port] = (assoc $phist '' $dknown)
|
||||
} else {
|
||||
combinaisons[$port] = [&''=$dknown]
|
||||
}
|
||||
} else {
|
||||
combinaisons[$port] = [&''=$pdomains]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn -known-ports { keys $combinaisons }
|
||||
|
||||
fn -known-names [&port=22]{
|
||||
keys (map:value-of $combinaisons $port &default=[&]) | list:filter [n]{ not-eq $n '' }
|
||||
}
|
||||
|
||||
fn -known-hosts [&port=22 &name=$false]{
|
||||
local:phosts = (map:value-of $combinaisons $port &default=[&])
|
||||
if $name {
|
||||
keys (map:value-of $phosts $name &default=[&])
|
||||
} else {
|
||||
keys (keys $phosts | peach [name]{
|
||||
local:name = $name
|
||||
keys $phosts[$name]
|
||||
} | map:to-set)
|
||||
}
|
||||
}
|
||||
|
||||
fn -port [&cmd=ssh @argv]{
|
||||
o = (condition:set (eq $cmd 'ssh') '-p' '-P')
|
||||
margs = (option:map $argv)
|
||||
map:value-of $margs $o &default=[]
|
||||
}
|
||||
|
||||
fn -complete-options [list @args]{ each [o]{ put -$o } $list }
|
||||
|
||||
fn -complete-args [cmd @argv]{
|
||||
local:port = (-port $cmd $@argv)
|
||||
if (list:empty $port) {
|
||||
port = 22
|
||||
} else {
|
||||
port = $port[-1]
|
||||
}
|
||||
local:larg = $argv[-1]
|
||||
local:name @local:host = (splits '@' $larg)
|
||||
if (list:empty $host) {
|
||||
-known-names &port=$port | each [n]{ put $n'@' }
|
||||
if (eq $cmd 'scp') {
|
||||
file:match-files $larg
|
||||
}
|
||||
} else {
|
||||
host @_ = (splits ':' $host[0])
|
||||
local:check = [h]{ has-prefix $h $host }
|
||||
local:khosts = [(-known-hosts &port=$port &name=$name)]
|
||||
if (not (list:contains $check $khosts)) {
|
||||
khosts = [(-known-hosts &port=$port)]
|
||||
if (not (list:contains $check $khosts)) {
|
||||
khosts = [(-known-hosts)]
|
||||
}
|
||||
}
|
||||
each [h]{ put $name'@'$h } $khosts
|
||||
explode $khosts
|
||||
}
|
||||
}
|
||||
|
||||
fn complete [@argv]{
|
||||
if (keys $combinaisons | list:empty) {
|
||||
init
|
||||
}
|
||||
local:cmd = $argv[0]
|
||||
local:is-ssh = (eq $cmd ssh)
|
||||
local:po = (condition:set $is-ssh -p -P)
|
||||
if (<= (count $argv) 2) {
|
||||
-complete-options (condition:set $is-ssh $options-ssh $options-scp)
|
||||
-complete-args $@argv
|
||||
} elif (eq $argv[-2] $po) {
|
||||
-known-ports
|
||||
} else {
|
||||
-complete-args $@argv
|
||||
}
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[scp] = $complete~
|
||||
edit:completion:arg-completer[ssh] = $complete~
|
||||
|
||||
init&
|
||||
10
lib/moi/completion/sudo.elv
Normal file
10
lib/moi/completion/sudo.elv
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fn complete [@argv]{
|
||||
if (and (> (count $argv) 2) (has-key $edit:completion:arg-completer $argv[1])) {
|
||||
$edit:completion:arg-completer[$argv[1]] (explode $argv[1:])
|
||||
} else {
|
||||
edit:complete-sudo $@argv
|
||||
}
|
||||
}
|
||||
|
||||
edit:completion:arg-completer[sudo] = $edit:complete-sudo~
|
||||
#edit:completion:arg-completer[sudo] = $-complete~
|
||||
Loading…
Add table
Add a link
Reference in a new issue