From ff9cefd28febdf5539d47339f8462e71da793842 Mon Sep 17 00:00:00 2001 From: Benjamin VAUDOUR Date: Tue, 24 Aug 2021 20:44:01 +0200 Subject: [PATCH] =?UTF-8?q?Nouvelle=20config=20(passage=20=C3=A0=20elvish?= =?UTF-8?q?=200.16.1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aliases/add_badips.elv | 28 -- aliases/archiver.elv | 21 +- aliases/bat.elv | 16 - aliases/br.elv | 17 - aliases/cat.elv | 2 - aliases/clean_known_hosts.elv | 36 -- aliases/cp.elv | 2 - aliases/dcd.elv.tmp | 2 - aliases/desarchiver.elv | 6 +- aliases/df.elv | 2 - aliases/diff.elv | 2 - aliases/dig.elv | 2 - aliases/digall.elv | 13 +- aliases/du.elv | 2 - aliases/git.elv | 2 - aliases/grep.elv | 2 - aliases/history.elv | 34 -- aliases/ip-of.elv | 101 ----- aliases/la.elv | 2 - aliases/ll.elv | 2 - aliases/lla.elv | 2 - aliases/ls.elv | 16 +- aliases/mdig.elv | 29 -- aliases/meteo.elv | 7 +- aliases/midi.elv | 2 - aliases/mv.elv | 2 - aliases/pacmanhisto.elv | 5 +- aliases/pf.elv | 2 - aliases/publicip.elv | 7 +- aliases/rename.elv | 11 - aliases/rm.elv | 2 - aliases/timidity.elv | 2 - aliases/tree.elv | 2 - aliases/trsen.elv | 2 - aliases/trsfr.elv | 2 - aliases/upd.elv | 4 +- aliases/vb.elv | 2 - aliases/vc.elv | 2 - aliases/vf.elv | 2 - aliases/vi.elv | 12 +- aliases/vp.elv | 2 - aliases/vv.elv | 2 - aliases/vz.elv | 2 - aliases/xaa | 1 - aliases/youtube-dl.elv | 5 +- aliases/youtube_audio.elv | 2 - lib/github.com/href/elvish-gitstatus | 1 - lib/github.com/muesli/elvish-libs | 1 - lib/github.com/xiaq/edit.elv | 1 - lib/github.com/zzamboni/elvish-completions | 1 - lib/github.com/zzamboni/elvish-modules | 1 - lib/github.com/zzamboni/elvish-themes | 1 - lib/moi/aliases.elv | 56 --- lib/moi/completion.elv | 11 + lib/moi/completion/arc.elv | 5 +- lib/moi/completion/archiver.elv | 1 + lib/moi/completion/desarchiver.elv | 2 +- lib/moi/completion/mpv.elv | 2 +- lib/moi/completion/pacman.elv | 2 +- lib/moi/completion/ssh.elv | 273 +++-------- lib/moi/util.elv | 7 - lib/moi/util/.list.elv.kate-swp | Bin 332 -> 0 bytes lib/moi/util/condition.elv | 6 +- lib/moi/util/file.elv | 12 +- lib/moi/util/ip.elv | 11 +- lib/moi/util/list.elv | 504 ++++++++++----------- lib/moi/util/map.elv | 6 +- lib/moi/util/number.elv | 40 -- rc.elv | 74 +-- 69 files changed, 423 insertions(+), 1018 deletions(-) delete mode 100644 aliases/add_badips.elv delete mode 100644 aliases/bat.elv delete mode 100644 aliases/br.elv delete mode 100644 aliases/cat.elv delete mode 100644 aliases/clean_known_hosts.elv delete mode 100644 aliases/cp.elv delete mode 100644 aliases/dcd.elv.tmp delete mode 100644 aliases/df.elv delete mode 100644 aliases/diff.elv delete mode 100644 aliases/dig.elv delete mode 100644 aliases/du.elv delete mode 100644 aliases/git.elv delete mode 100644 aliases/grep.elv delete mode 100644 aliases/history.elv delete mode 100644 aliases/ip-of.elv delete mode 100644 aliases/la.elv delete mode 100644 aliases/ll.elv delete mode 100644 aliases/lla.elv delete mode 100644 aliases/mdig.elv delete mode 100644 aliases/midi.elv delete mode 100644 aliases/mv.elv delete mode 100644 aliases/pf.elv delete mode 100644 aliases/rename.elv delete mode 100644 aliases/rm.elv delete mode 100644 aliases/timidity.elv delete mode 100644 aliases/tree.elv delete mode 100644 aliases/trsen.elv delete mode 100644 aliases/trsfr.elv delete mode 100644 aliases/vb.elv delete mode 100644 aliases/vc.elv delete mode 100644 aliases/vf.elv delete mode 100644 aliases/vp.elv delete mode 100644 aliases/vv.elv delete mode 100644 aliases/vz.elv delete mode 100644 aliases/xaa delete mode 100644 aliases/youtube_audio.elv delete mode 160000 lib/github.com/href/elvish-gitstatus delete mode 160000 lib/github.com/muesli/elvish-libs delete mode 160000 lib/github.com/xiaq/edit.elv delete mode 160000 lib/github.com/zzamboni/elvish-completions delete mode 160000 lib/github.com/zzamboni/elvish-modules delete mode 160000 lib/github.com/zzamboni/elvish-themes delete mode 100644 lib/moi/aliases.elv delete mode 100644 lib/moi/util.elv delete mode 100644 lib/moi/util/.list.elv.kate-swp delete mode 100644 lib/moi/util/number.elv diff --git a/aliases/add_badips.elv b/aliases/add_badips.elv deleted file mode 100644 index a9d31f0..0000000 --- a/aliases/add_badips.elv +++ /dev/null @@ -1,28 +0,0 @@ -#alias:new add_badips e:echo -fn add_badips [@_args]{ - use moi/util/ip - use moi/util/list - use moi/util/map - use moi/util/number - use str - - local:f = ~/bad_ips.txt - local:ips = [ (cat $f) ] - local:m = (map:to-set $ips) - local:c = 0 - each [e]{ - local:cond = (and (not (has-key $m $e)) (ip:is-ipv4 $e)) - if $cond { - echo $e ajoutée - c = (number:++ $c) - m[$e] = $nil - ips = [ (all $ips) $e ] - } - } $_args - if (> $c 0) { - ips = [ (list:sort $ip:cmp4~ $ips) ] - } - local:result = (str:join "\n" $ips) - echo $result > $f - echo $c' IPs ajoutées ('(count $ips)' au total)' -} diff --git a/aliases/archiver.elv b/aliases/archiver.elv index 373bfa9..97af2e1 100644 --- a/aliases/archiver.elv +++ b/aliases/archiver.elv @@ -1,38 +1,39 @@ -#alias:new archiver e:archiver -fn archiver [@_args]{ +edit:add-var archiver~ [@argv]{ + use str help = { echo "Usage : archiver [(-zlxgb)] " return } - if (or (== (count $_args) 0) (eq $_args[0] -h)) { + if (or (== (count $argv) 0) (eq $argv[0] -h)) { $help } local:format = zst - local:o = $_args[0] - if (and (has-prefix $o -) (> (count $o) 1)) { + local:o = $argv[0] + if (and (str:has-prefix $o -) (> (count $o) 1)) { o = $o[1] local:m = [ &z=zst &l=lz4 &x=xz - &g=gzip + &g=gz &b=bz2 ] if (not (has-key $m $o)) { $help } format = $m[$o] - _args = $_args[1:] + argv = $argv[1..] } - if (== (count $_args) 0) { + if (== (count $argv) 0) { $help } peach [f]{ local:f = $f if (eq $f[-1] /) { - f = $f[:-1] + f = $f[..-1] } e:arc archive $f'.tar.'$format $f echo "'"$f"'" archivé - } $_args + } $argv } + diff --git a/aliases/bat.elv b/aliases/bat.elv deleted file mode 100644 index 7d000be..0000000 --- a/aliases/bat.elv +++ /dev/null @@ -1,16 +0,0 @@ -#alias:new bat e:bat -fn bat [@_args]{ - styles = [ --style -n --number -p --plain -pp ] - has_style = $false - for e $_args { - if (has-value $styles $e) { - has_style = true - break - } - } - @pargs = $@_args - if (not $has_style) { - @pargs = -p $@_args - } - e:bat $@pargs -} diff --git a/aliases/br.elv b/aliases/br.elv deleted file mode 100644 index d075ea8..0000000 --- a/aliases/br.elv +++ /dev/null @@ -1,17 +0,0 @@ -#alias:new br e:broot -dp -#fn br [@_args]{ e:broot -dp $@_args } -fn br [@_args]{ - f = (mktemp) - try { - e:broot --outcmd $f -dp $@_args - } except e { - rm -f $f - return - } - try { - -source $f - } except e { - } finally { - rm -f $f - } -} diff --git a/aliases/cat.elv b/aliases/cat.elv deleted file mode 100644 index 99606f3..0000000 --- a/aliases/cat.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new cat bat -pp -fn cat [@_args]{ bat -pp $@_args } diff --git a/aliases/clean_known_hosts.elv b/aliases/clean_known_hosts.elv deleted file mode 100644 index 7aaf64f..0000000 --- a/aliases/clean_known_hosts.elv +++ /dev/null @@ -1,36 +0,0 @@ -#alias:new clean_known_hosts e:cat -fn clean_known_hosts [@_args]{ - use str - use moi/util/condition - use moi/util/list - use moi/util/ip - fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 } - fn sort-host [e1 e2]{ - local:i1 = (condition:set (ip:is-ip $e1) 1 0) - local:i2 = (condition:set (ip:is-ip $e2) 1 0) - if (!= $i1 $i2) { - < $i1 $i2 - } elif (== $i1 0) { - ~/.ssh/known_hosts -} diff --git a/aliases/cp.elv b/aliases/cp.elv deleted file mode 100644 index 831ec27..0000000 --- a/aliases/cp.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new cp e:cp -iv -fn cp [@_args]{ e:cp -iv $@_args } diff --git a/aliases/dcd.elv.tmp b/aliases/dcd.elv.tmp deleted file mode 100644 index 3e15242..0000000 --- a/aliases/dcd.elv.tmp +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new dcd e:broot --only-folder --cmd -fn dcd [@_args]{ br --only-folders --cmd (joins ' ' $_args)' :cd' } diff --git a/aliases/desarchiver.elv b/aliases/desarchiver.elv index b28db42..a4c8191 100644 --- a/aliases/desarchiver.elv +++ b/aliases/desarchiver.elv @@ -1,8 +1,8 @@ -#alias:new desarchiver e:desarchiver -fn desarchiver [@_args]{ +edit:add-var desarchiver~ [@argv]{ peach [f]{ local:f = $f e:arc unarchive $f echo "'"$f"'" désarchivé - } $_args + } $argv } + diff --git a/aliases/df.elv b/aliases/df.elv deleted file mode 100644 index f63199f..0000000 --- a/aliases/df.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new df e:df -h -fn df [@_args]{ e:df -h $@_args } diff --git a/aliases/diff.elv b/aliases/diff.elv deleted file mode 100644 index d323703..0000000 --- a/aliases/diff.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new diff e:colordiff -fn diff [@_args]{ e:colordiff $@_args } diff --git a/aliases/dig.elv b/aliases/dig.elv deleted file mode 100644 index 497ddf6..0000000 --- a/aliases/dig.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new dig e:dig +noall +answer -fn dig [@_args]{ e:dig +noall +answer $@_args } diff --git a/aliases/digall.elv b/aliases/digall.elv index c7b7943..7c6fb43 100644 --- a/aliases/digall.elv +++ b/aliases/digall.elv @@ -1,7 +1,6 @@ -#alias:new digall e:dig ANY +noall +answer -fn digall [@_args]{ +edit:add-var digall~ [@argv]{ use moi/util/list - use moi/util/strutil + use moi/util/strutil use str local:default_records = [ @@ -31,9 +30,9 @@ fn digall [@_args]{ local:use_dig = $true fn init []{ - if (and (> (count $_args) 0) (is $_args[0] -d)) { + if (and (> (count $argv) 0) (is $argv[0] -d)) { use_dig = $false - _args = $_args[1:] + argv = $argv[1:] } each [e]{ if (is $e[0] '+') { @@ -45,7 +44,7 @@ fn digall [@_args]{ } else { domains = [ (all $domains) $e ] } - } $_args + } $argv if (== (count $records) 0) { records = $default_records } @@ -53,7 +52,7 @@ fn digall [@_args]{ fn format [results]{ eawk [_ @args]{ - put [ $args[0] (all $args[2:]) ] + put [ $args[0] (all $args[2..]) ] } $results | list:remove-duplicate | list:sort [l1 l2]{ local:c = (str:compare $l1[0] $l2[0]) if (== $c 0) { diff --git a/aliases/du.elv b/aliases/du.elv deleted file mode 100644 index 5b20796..0000000 --- a/aliases/du.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new du e:du -h -fn du [@_args]{ e:du -h $@_args } diff --git a/aliases/git.elv b/aliases/git.elv deleted file mode 100644 index 8e5b4d3..0000000 --- a/aliases/git.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new git e:hub -fn git [@_args]{ e:hub $@_args } diff --git a/aliases/grep.elv b/aliases/grep.elv deleted file mode 100644 index d5e1490..0000000 --- a/aliases/grep.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new grep e:grep --color=tty -d skip -fn grep [@_args]{ e:grep --color=tty -d skip $@_args } diff --git a/aliases/history.elv b/aliases/history.elv deleted file mode 100644 index 84307ff..0000000 --- a/aliases/history.elv +++ /dev/null @@ -1,34 +0,0 @@ -#alias:new history edit:command-history | each [h]{ put $h['cmd'] } -fn history [@_args]{ - use str - use moi/util/list - @history = (edit:command-history | each [h]{ put $h['cmd'] }) - @ch = (list:reverse $history | list:remove-duplicate | list:reverse) - if (list:empty $_args) { - each [h]{ echo $h } $ch - return - } - action @rest = $_args[0] (take 1 $_args) - has-rest = (list:not-empty $rest) - if (and (is $action --cmd) $has-rest) { - eawk [h cmd @_]{ - if (has-value $rest $cmd) { - echo $h - } - } $ch - } elif (and (is $action --search) $has-rest) { - each [h]{ - if (list:exists [_ m]{ str:contains $h $m } $rest) { - echo $h - } - } $ch - } elif (and (is $action --delete) $has-rest) { - each [h]{ - if (list:exists [_ m]{ str:contains $h $m } $rest) { - put $h - } - } $history - } else { - echo (styled 'Usage: history [(--search|--cmd|--delete) args...' bold red) - } -} diff --git a/aliases/ip-of.elv b/aliases/ip-of.elv deleted file mode 100644 index f08bc76..0000000 --- a/aliases/ip-of.elv +++ /dev/null @@ -1,101 +0,0 @@ -#alias:new ip-of e:is-ip -fn ip-of [@_args]{ - use str - use moi/util/condition - use moi/util/ip - - fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 } - - fn sort-ip [e1 e2]{ - local:i1 = (condition:set (ip:is-ipv4 $e1) 0 (condition:set (ip:is-ipv6 $e1) 1 2)) - local:i2 = (condition:set (ip:is-ipv4 $e2) 0 (condition:set (ip:is-ipv6 $e2) 1 2)) - if (!= $i1 $i2) { - < $i1 $i2 - } elif (== $i1 2) { - (keys $solve[ips] | count) 0) { - remote[$d] = $solve - } - } $_args - - each [d]{ - local:exists = $false - echo (styled 'Resolving '$d'…' bright-green) - echo - if (has-key $hosts $d) { - exists = $true - echo (styled ' local:' bright-yellow) - keys $hosts[$d] | order &less-than=$sort-ip~ | each [ip]{ - echo ' - '$ip - } - } - if (has-key $remote $d) { - exists = $true - local:info = $remote[$d] - echo (styled ' remote:' bright-yellow) - echo ' IPs:' - keys $info[ips] | order &less-than=$sort-ip~ | each [ip]{ - echo ' - '$ip - } - echo ' Resolvers: '$info[resolvers] - echo ' TXT records: '$info[txt] - } - if (not $exists) { - echo (styled 'No info found' bright-red) - } - echo - } $_args -} diff --git a/aliases/la.elv b/aliases/la.elv deleted file mode 100644 index c436fd1..0000000 --- a/aliases/la.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new la e:ls -a -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify -fn la [@_args]{ e:ls -a -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify $@_args } diff --git a/aliases/ll.elv b/aliases/ll.elv deleted file mode 100644 index 13da945..0000000 --- a/aliases/ll.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new ll e:ls -lh -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify -fn ll [@_args]{ e:ls -lh -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify $@_args } diff --git a/aliases/lla.elv b/aliases/lla.elv deleted file mode 100644 index 1f8d9c6..0000000 --- a/aliases/lla.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new lla e:ls -la -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify -fn lla [@_args]{ e:ls -la -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify $@_args } diff --git a/aliases/ls.elv b/aliases/ls.elv index f2896ac..29910d3 100644 --- a/aliases/ls.elv +++ b/aliases/ls.elv @@ -1,2 +1,14 @@ -#alias:new ls e:ls -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify -fn ls [@_args]{ e:ls -N --color=auto --group-directories-first --ignore=lost+found --time-style=+"%Y.%m.%d %H:%M" --indicator-style=classify $@_args } +fn -ls [@argv]{ + e:ls -N --color=auto --group-directories-first --ignore=lost+found '--time-style=+"%Y.%m.%d %H:%M"' --indicator-style=classify $@argv +} + +fn -go-ls [@argv]{ + e:go-ls --group-directories-first -T '+%Y.%m.%d %H:%M' --git $@argv +} + +local:cmd = $-go-ls~ + +edit:add-var ls~ [@argv]{ $cmd $@argv } +edit:add-var la~ [@argv]{ $cmd -a $@argv } +edit:add-var ll~ [@argv]{ $cmd -lh $@argv } +edit:add-var lla~ [@argv]{ $cmd -lha $@argv } diff --git a/aliases/mdig.elv b/aliases/mdig.elv deleted file mode 100644 index af7528a..0000000 --- a/aliases/mdig.elv +++ /dev/null @@ -1,29 +0,0 @@ -#alias:new mdig e:dig -fn mdig [@_args]{ - if (== (count $_args) 0) { - fail (styled "Veuillez saisir au moins un nom de domaine…" bold red) - } - ns = [] - @hosts = $@_args - if (has-prefix $_args[0] '@') { - ns = $_args[0] - @hosts = (drop 1 $hosts) - } - if (== (count $hosts) 0) { - fail (styled "Veuillez saisir au moins un nom de domaine…" bold red) - } - for h $hosts { - @ipv4 = (e:dig $ns $h A +short) - @ipv6 = (e:dig $ns $h AAAA +short) - if (== (count $ipv4) 0) { - @ipv4 = "" - } - if (== (count $ipv6) 0) { - @ipv6 = "" - } - echo (styled $h bold yellow) - echo (styled 'A ' bright-red)$@ipv4 - echo (styled 'AAAA ' bright-red)$@ipv6 - echo "----------------------" - } -} diff --git a/aliases/meteo.elv b/aliases/meteo.elv index 471025e..e5cd72e 100644 --- a/aliases/meteo.elv +++ b/aliases/meteo.elv @@ -1,4 +1,5 @@ -#alias:new meteo e:curl 'wttr.in/?lang=fr' -fn meteo [@_args]{ - curl --connect-timeout 2 "wttr.in/"(joins '' $_args)"?lang=fr" +edit:add-var meteo~ [@argv]{ + use str + #curl --connect-timeout 2 "wttr.in/"(joins '' $_args)"?lang=fr" + e:curlie -s --connect-timeout 2 "wttr.in/"(str:join '' $argv)"?lang=fr" } diff --git a/aliases/midi.elv b/aliases/midi.elv deleted file mode 100644 index 0c12c8b..0000000 --- a/aliases/midi.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new midi e:fluidsynth -a pulseaudio /usr/share/soundfonts/FluidR3_GM.sf2 -fn midi [@_args]{ e:fluidsynth -a pulseaudio /usr/share/soundfonts/FluidR3_GM.sf2 $@_args } diff --git a/aliases/mv.elv b/aliases/mv.elv deleted file mode 100644 index c8855e7..0000000 --- a/aliases/mv.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new mv e:mv -iv -fn mv [@_args]{ e:mv -iv $@_args } diff --git a/aliases/pacmanhisto.elv b/aliases/pacmanhisto.elv index 58b73bb..4a3f29b 100644 --- a/aliases/pacmanhisto.elv +++ b/aliases/pacmanhisto.elv @@ -1,4 +1 @@ -#alias:new pacmanhisto cat /var/log/pacman.log -fn pacmanhisto [@_args]{ - cat /var/log/pacman.log | grep "ALPM" | grep $@_args -} +edit:add-var pacmanhisto~ [@argv]{ e:cat /var/log/pacman.log | e:grep "ALPM" | e:grep $@argv } diff --git a/aliases/pf.elv b/aliases/pf.elv deleted file mode 100644 index 403f1ca..0000000 --- a/aliases/pf.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new pf e:pkgfile -vri -fn pf [@_args]{ e:pkgfile -vri $@_args } diff --git a/aliases/publicip.elv b/aliases/publicip.elv index ae4a9ed..deca906 100644 --- a/aliases/publicip.elv +++ b/aliases/publicip.elv @@ -1,9 +1,8 @@ -#alias:new publicip curl ifconfig.co/ip -fn publicip { +edit:add-var publicip~ [@argv]{ f = [t]{ use moi/util/condition - t = condition:set (eq $t -6) -6 -4 - l = condition:set (eq $t -6) 'IPv6: ' 'IPv4: ' + t = (condition:cset (eq $t -6) -6 -4) + l = (condition:cset (eq $t -6) 'IPv6: ' 'IPv4: ') curl $t ifconfig.co/ip 2> /dev/null | each [ip]{ echo (styled $l bold yellow) $ip } } $f -4 diff --git a/aliases/rename.elv b/aliases/rename.elv deleted file mode 100644 index 01bb336..0000000 --- a/aliases/rename.elv +++ /dev/null @@ -1,11 +0,0 @@ -#alias:new rename perl-rename -fn rename [@_args]{ - e:perl-rename -n $@_args - use github.com/zzamboni/elvish-modules/util - if (util:y-or-n &style=bright-yellow 'Renommer? ') { - e:perl-rename -v $@args - echo (styled 'Succès' bold green) - } else { - echo (styled 'Abandon' bold red) - } -} diff --git a/aliases/rm.elv b/aliases/rm.elv deleted file mode 100644 index d437099..0000000 --- a/aliases/rm.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new rm e:rm -Iv -fn rm [@_args]{ e:rm -Iv $@_args } diff --git a/aliases/timidity.elv b/aliases/timidity.elv deleted file mode 100644 index ba6a568..0000000 --- a/aliases/timidity.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new timidity e:timidity -a -K -1 -fn timidity [@_args]{ e:timidity -a -K -1 $@_args } diff --git a/aliases/tree.elv b/aliases/tree.elv deleted file mode 100644 index 8b014d7..0000000 --- a/aliases/tree.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new tree e:tree -puhC --dirsfirst --du -D -fn tree [@_args]{ e:tree -puhC --dirsfirst --du -D $@_args } diff --git a/aliases/trsen.elv b/aliases/trsen.elv deleted file mode 100644 index 08775a3..0000000 --- a/aliases/trsen.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new trsen e:rlwrap trans -b -t en -fn trsen [@_args]{ e:rlwrap trans -b -t en $@_args } diff --git a/aliases/trsfr.elv b/aliases/trsfr.elv deleted file mode 100644 index 6460d25..0000000 --- a/aliases/trsfr.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new trsfr e:rlwrap trans -b -t fr -fn trsfr [@_args]{ e:rlwrap trans -b -t fr $@_args } diff --git a/aliases/upd.elv b/aliases/upd.elv index 21917d8..8cdc85a 100644 --- a/aliases/upd.elv +++ b/aliases/upd.elv @@ -1,6 +1,6 @@ -#alias:new upd and ?(mirror-check --fast) (sudo pacman -Syu) -fn upd [@_args]{ +edit:add-var upd~ [@args]{ if ?(mirror-check --fast) { sudo pacman -Syu } } + diff --git a/aliases/vb.elv b/aliases/vb.elv deleted file mode 100644 index 895054a..0000000 --- a/aliases/vb.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new vb e:vim /home/benjamin/.bashrc -fn vb [@_args]{ e:vim /home/benjamin/.bashrc $@_args } diff --git a/aliases/vc.elv b/aliases/vc.elv deleted file mode 100644 index b8f7d1f..0000000 --- a/aliases/vc.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new vc e:vim /home/benjamin/.vimrc -fn vc [@_args]{ e:vim /home/benjamin/.vimrc $@_args } diff --git a/aliases/vf.elv b/aliases/vf.elv deleted file mode 100644 index 9953dcd..0000000 --- a/aliases/vf.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new vf e:vim /home/benjamin/.config/config.fish -fn vf [@_args]{ e:vim /home/benjamin/.config/config.fish $@_args } diff --git a/aliases/vi.elv b/aliases/vi.elv index 9364a86..638461f 100644 --- a/aliases/vi.elv +++ b/aliases/vi.elv @@ -1,2 +1,10 @@ -#alias:new vi e:vim -fn vi [@_args]{ e:vim $@_args } +local:cmd = $e:vim~ + +edit:add-var vi~ [@argv]{ $cmd $@argv } +edit:add-var vb~ [@argv]{ $cmd $@argv ~/.bashrc } +edit:add-var vc~ [@argv]{ $cmd $@argv ~/.vimrc } +edit:add-var ve~ [@argv]{ $cmd $@argv ~/.config/elvish/rc.elv } +edit:add-var vf~ [@argv]{ $cmd $@argv ~/.config/fish/config.fish } +edit:add-var vp~ [@argv]{ $cmd $@argv PKGBUILD } +edit:add-var vv~ [@argv]{ $cmd -R $@argv } +edit:add-var vz~ [@argv]{ $cmd $@argv ~/.zshrc } diff --git a/aliases/vp.elv b/aliases/vp.elv deleted file mode 100644 index f601eef..0000000 --- a/aliases/vp.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new vp e:vim PKGBUILD -fn vp [@_args]{ e:vim PKGBUILD $@_args } diff --git a/aliases/vv.elv b/aliases/vv.elv deleted file mode 100644 index 59db167..0000000 --- a/aliases/vv.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new vv e:vim -R -fn vv [@_args]{ e:vim -R $@_args } diff --git a/aliases/vz.elv b/aliases/vz.elv deleted file mode 100644 index e9855b7..0000000 --- a/aliases/vz.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new vz e:vim /home/benjamin/.zshrc -fn vz [@_args]{ e:vim /home/benjamin/.zshrc $@_args } diff --git a/aliases/xaa b/aliases/xaa deleted file mode 100644 index 8b13789..0000000 --- a/aliases/xaa +++ /dev/null @@ -1 +0,0 @@ - diff --git a/aliases/youtube-dl.elv b/aliases/youtube-dl.elv index e1a1950..bdfcb39 100644 --- a/aliases/youtube-dl.elv +++ b/aliases/youtube-dl.elv @@ -1,2 +1,3 @@ -#alias:new youtube-dl e:youtube-dl --no-check-certificate -fn youtube-dl [@_args]{ e:youtube-dl --no-check-certificate $@_args } +edit:add-var youtube-dl~ [@argv]{ e:youtube-dl --no-check-certificate $@argv } +edit:add-var youtube-audio~ [@argv]{ e:youtube-dl --no-check-certificate -x --audio-format best $@argv } + diff --git a/aliases/youtube_audio.elv b/aliases/youtube_audio.elv deleted file mode 100644 index 75bea7f..0000000 --- a/aliases/youtube_audio.elv +++ /dev/null @@ -1,2 +0,0 @@ -#alias:new youtube_audio youtube-dl -x --audio-format best -fn youtube_audio [@_args]{ youtube-dl -x --audio-format best $@_args } diff --git a/lib/github.com/href/elvish-gitstatus b/lib/github.com/href/elvish-gitstatus deleted file mode 160000 index 4933947..0000000 --- a/lib/github.com/href/elvish-gitstatus +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4933947f086421494cfb444b2d90ce0a51faa493 diff --git a/lib/github.com/muesli/elvish-libs b/lib/github.com/muesli/elvish-libs deleted file mode 160000 index 5a361ca..0000000 --- a/lib/github.com/muesli/elvish-libs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5a361ca5ce20a57e1f80a9ee893c2423e63e7ee1 diff --git a/lib/github.com/xiaq/edit.elv b/lib/github.com/xiaq/edit.elv deleted file mode 160000 index 97a5aa5..0000000 --- a/lib/github.com/xiaq/edit.elv +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 97a5aa575fa60be55e61800d885e6108ccca04ff diff --git a/lib/github.com/zzamboni/elvish-completions b/lib/github.com/zzamboni/elvish-completions deleted file mode 160000 index 21e048e..0000000 --- a/lib/github.com/zzamboni/elvish-completions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 21e048ee6dca73c27d61068e03a113c97cf0a278 diff --git a/lib/github.com/zzamboni/elvish-modules b/lib/github.com/zzamboni/elvish-modules deleted file mode 160000 index 3ff9fe8..0000000 --- a/lib/github.com/zzamboni/elvish-modules +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3ff9fe88bb40dff3591d7e40e3c7dfa06c584e60 diff --git a/lib/github.com/zzamboni/elvish-themes b/lib/github.com/zzamboni/elvish-themes deleted file mode 160000 index 1010ade..0000000 --- a/lib/github.com/zzamboni/elvish-themes +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1010ade24d1dee0a9b62506cfa86298158cac70f diff --git a/lib/moi/aliases.elv b/lib/moi/aliases.elv deleted file mode 100644 index 6e68e79..0000000 --- a/lib/moi/aliases.elv +++ /dev/null @@ -1,56 +0,0 @@ -use github.com/zzamboni/elvish-modules/alias - -#fn pacman [@_args]{ -# if (and (== (count $_args) 0) (has-value [-S -Sy -Syu -Syyu -Su -Suu] $_args[0])) { -# mirror-check --fast -# } -# e:pacman $@_args -#} - -alias:new cat bat -pp -alias:new midi e:fluidsynth -a pulseaudio /usr/share/soundfonts/FluidR3_GM.sf2 -alias:new timidity e:timidity -a -K -1 -alias:new git e:hub -alias:new dig e:dig +noall +answer - -#alias:new pacmanhisto cat /var/log/pacman.log | grep "ALPM" | grep -alias:new pf e:pkgfile -vri - -alias:new trsen e:rlwrap trans -b -t en -alias:new trsfr e:rlwrap trans -b -t fr - -alias:new youtube-dl e:youtube-dl --no-check-certificate -alias:new youtube_audio youtube-dl -x --audio-format best - -#alias:new history edit:command-history - -alias:new cp e:cp -iv -alias:new mv e:mv -iv -alias:new rm e:rm -Iv - -@argls = -N --color=auto --group-directories-first --ignore=lost+found '--time-style=+"%Y.%m.%d %H:%M"' --indicator-style=classify -#alias:new br e:broot -dp -alias:new tree e:tree -puhC --dirsfirst --du -D -alias:new ls e:ls $@argls -alias:new la e:ls -a $@argls -alias:new ll e:ls -lh $@argls -alias:new lla e:ls -la $@argls - -alias:new df e:df -h -alias:new du e:du -h - -alias:new diff e:colordiff -alias:new grep e:grep --color=tty -d skip - -alias:new vi e:vim -alias:new vv e:vim -R -alias:new vb e:vim ~/.bashrc -alias:new vf e:vim ~/.config/config.fish -alias:new vz e:vim ~/.zshrc -alias:new vc e:vim ~/.vimrc -alias:new vp e:vim PKGBUILD - -fn export []{ alias:export } - - - diff --git a/lib/moi/completion.elv b/lib/moi/completion.elv index a2012a4..eec40d8 100644 --- a/lib/moi/completion.elv +++ b/lib/moi/completion.elv @@ -1,3 +1,13 @@ +#use github.com/zzamboni/elvish-completions/builtins +use github.com/zzamboni/elvish-completions/cd +use github.com/zzamboni/elvish-completions/git +git:git-command = hub +git:git-completions[checkout] = [ { git:MODIFIED; git:BRANCHES &all } ... ] +git:init +#use github.com/zzamboni/elvish-completions/ssh + +use github.com/xiaq/edit.elv/compl/go + use ./completion/arc use ./completion/archiver use ./completion/desarchiver @@ -6,3 +16,4 @@ use ./completion/mpv use ./completion/pacman use ./completion/ssh use ./completion/sudo +use ./completion/use diff --git a/lib/moi/completion/arc.elv b/lib/moi/completion/arc.elv index 3b701b4..219ab4a 100644 --- a/lib/moi/completion/arc.elv +++ b/lib/moi/completion/arc.elv @@ -14,13 +14,13 @@ extensions = [ tar bz2 zip gz lz4 sz xz zst rar ] fn -comp-commands { all $commands } fn -comp-archive-files [m]{ - local:type = (condition:set (eq $m '') prefix deep-prefix) + local:type = (condition:cset (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] } + arc ls $archive | eawk [_ @argv]{ put $argv[-1] } } except e { nop } @@ -46,3 +46,4 @@ fn complete [@argv]{ } edit:completion:arg-completer[arc] = $complete~ + diff --git a/lib/moi/completion/archiver.elv b/lib/moi/completion/archiver.elv index 78bbd51..0962aeb 100644 --- a/lib/moi/completion/archiver.elv +++ b/lib/moi/completion/archiver.elv @@ -27,3 +27,4 @@ fn complete [@argv]{ } edit:completion:arg-completer[archiver] = $complete~ + diff --git a/lib/moi/completion/desarchiver.elv b/lib/moi/completion/desarchiver.elv index 73c68c1..317ff1f 100644 --- a/lib/moi/completion/desarchiver.elv +++ b/lib/moi/completion/desarchiver.elv @@ -5,7 +5,7 @@ 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) + local:type = (condition:cset (eq $m '') prefix deep-prefix) file:match-extensions &type=$type $m $@extensions } diff --git a/lib/moi/completion/mpv.elv b/lib/moi/completion/mpv.elv index ca18eb1..21020c8 100644 --- a/lib/moi/completion/mpv.elv +++ b/lib/moi/completion/mpv.elv @@ -36,7 +36,7 @@ extensions = [ ] fn -files [m]{ - local:type = (condition:set (eq $m '') prefix deep-prefix) + local:type = (condition:cset (eq $m '') prefix deep-prefix) file:match-extensions &type=$type $m $@extensions } diff --git a/lib/moi/completion/pacman.elv b/lib/moi/completion/pacman.elv index ee1a9bf..f82e041 100644 --- a/lib/moi/completion/pacman.elv +++ b/lib/moi/completion/pacman.elv @@ -22,7 +22,7 @@ fn -repo-packages { } fn -downloaded-packages [m]{ - local:type = (condition:set (eq $m '') prefix deep-prefix) + local:type = (condition:cset (eq $m '') prefix deep-prefix) file:match-extensions &type=$type $m tar.zst tar.xz tar.gz tar.bz2 } diff --git a/lib/moi/completion/ssh.elv b/lib/moi/completion/ssh.elv index 2f700b4..a0c7af5 100644 --- a/lib/moi/completion/ssh.elv +++ b/lib/moi/completion/ssh.elv @@ -6,246 +6,101 @@ 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 -} +names = [ + benjamin + luence +] -fn -init-known-hosts { - local:khosts = [&22=[&]] +fn -kh { cat ~/.ssh/known_hosts | peach [l]{ put [(str:split ' ' $l)] } | peach [e]{ - local:domains @local:id = $@e - id = (str:join ' ' $id) - str:split ',' $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:domains @_ = $@e + str:split ',' $domains } - 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 - } +fn -port [cmd @argv]{ + local:o = (condition:cset (eq $cmd 'ssh') '-p' '-P') + local:margs = (option:map $argv) + local:p = (map:value-of $margs $o &default=[]) + if (list:empty $p) { + put 22 + } else { + put $p[-1] } - 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 = [(str:split '@' $arg)] - if (== (count $nd) 2) { - name = $nd[0] - domain @_ = (str:split ':' $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 -complete-names []{ each [n]{ put $n'@' } $names } -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 - } - } +fn -complete-domains [name hosts]{ + each [h]{ + put $name@$h + } $hosts +} + +fn -complete-remote-dir [port address dir]{ + try { + ssh -p $port $address 'ls '$dir | each [f]{ + put $address':'$dir$f } - 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 + } except e { + } +} + +fn -complete-args [hosts cmd @argv]{ + local:arg = $argv[-1] + local:i = (str:index $arg @) + if (< $i 0) { + -complete-names + all $hosts + if (eq $cmd scp) { + edit:complete-filename $cmd $@argv + } + return + } + local:n local:h = $arg[..$i] $arg[(+ $i 1)..] + if (eq $cmd scp) { + i = (str:index $h :) + if (>= $i 0) { + local:d = $h[(+ $i 1)..] + h = $h[..$i] + if (list:includes $h $hosts) { + local:p = (-port $cmd @argv) + local:e = [ (str:split / $d) ] + if (not-eq $e[-1] '') { + d = (str:join / $e[..-1]) + if (eq $d '') { + d = / } } - if (> (keys $dknown | count) 0) { - combinaisons[$port] = (assoc $phist '' $dknown) - } else { - combinaisons[$port] = [&''=$dknown] - } - } else { - combinaisons[$port] = [&''=$pdomains] + -complete-remote-dir $p $n@$h $d } + return } } -} -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 = (str:split '@' $larg) - if (list:empty $host) { - -known-names &port=$port | each [n]{ put $n'@' } - if (eq $cmd 'scp') { - file:match-files $larg - } - } else { - host @_ = (str:split ':' $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 - all $khosts - } + -complete-domains $n $hosts } fn complete [@argv]{ - if (keys $combinaisons | list:empty) { - init - } + @hosts = (-kh) local:cmd = $argv[0] local:is-ssh = (eq $cmd ssh) - local:po = (condition:set $is-ssh -p -P) + local:po = (condition:cset $is-ssh -p -P) if (<= (count $argv) 2) { - -complete-options (condition:set $is-ssh $options-ssh $options-scp) - -complete-args $@argv + all (condition:cset $is-ssh $options-ssh $options-scp) + -complete-args $hosts $@argv } elif (eq $argv[-2] $po) { - -known-ports + put 22 } else { - -complete-args $@argv + -complete-args $hosts $@argv } } edit:completion:arg-completer[scp] = $complete~ edit:completion:arg-completer[ssh] = $complete~ - -init& diff --git a/lib/moi/util.elv b/lib/moi/util.elv deleted file mode 100644 index 2a2393d..0000000 --- a/lib/moi/util.elv +++ /dev/null @@ -1,7 +0,0 @@ -use moi/util/condition -use moi/util/file -use moi/util/ip -use moi/util/list -use moi/util/map -use moi/util/number -use moi/util/option diff --git a/lib/moi/util/.list.elv.kate-swp b/lib/moi/util/.list.elv.kate-swp deleted file mode 100644 index 6e7f85879a50904c10c8695b99e432acb8fa98b1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 332 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?VnS^Qsm`)9A6_D6Po3TpiN`mJ=v_R3&S zpv*NO<^y2`g@V!&g_Qi<#LT>6t8l243`os&AO-=Tn#7zO1r?|wkQ$H_A4ts&AO-=b zIYp_-`9&!Zb3jsHH8;U35avJ?fy@C(fz{kXr~$dBIJKxOwFqJkND8dxHbM>9Jy1m; ob3jsHHFuzDcp&~t%SlX!m;#dE0lD}tLIv0quo93NAPF8<0E4Vb?*IS* diff --git a/lib/moi/util/condition.elv b/lib/moi/util/condition.elv index f527ca0..433d3f0 100644 --- a/lib/moi/util/condition.elv +++ b/lib/moi/util/condition.elv @@ -1,4 +1,4 @@ -fn set [c t f]{ +fn cset [c t f]{ if $c { put $t } else { @@ -7,11 +7,11 @@ fn set [c t f]{ } fn mset [c t f]{ - all (set $c $t $f) + all (cset $c $t $f) } fn call [c t f @argv]{ - local:v = (set $c $t $f) + local:v = (cset $c $t $f) if (is (kind-of $v) fn) { $v $@argv } else { diff --git a/lib/moi/util/file.elv b/lib/moi/util/file.elv index 1394118..2f0a238 100644 --- a/lib/moi/util/file.elv +++ b/lib/moi/util/file.elv @@ -1,5 +1,9 @@ +use str +use ./list +use ./map + search-type = [ - &exact= [m]{ e:ls $m 2>/dev/null } + &exact= [m]{ ls $m 2>/dev/null } &match= [m]{ put *$m* } &prefix= [m]{ put $m* } &suffix= [m]{ put *$m } @@ -9,7 +13,6 @@ search-type = [ ] fn -less [f1 f2]{ - use str local:fl1 local:fl2 = (str:to-lower $f1) (str:to-lower $f2) local:c = (str:compare $fl1 $fl2) if (== $c 0) { @@ -27,11 +30,9 @@ fn -get-results [sort result]{ } fn -search [&sort=$false &type=exact @motive]{ - use ./list local:f = $search-type[$type] local:result = [&] if (list:empty $motive) { - use ./map result = (put * | map:to-set) } else { peach [m]{ @@ -50,11 +51,10 @@ fn -search [&sort=$false &type=exact @motive]{ fn match-files [&sort=$false &type=prefix @motive]{ -search &sort=$sort &type=$type $@motive } fn match-extensions [&sort=$false &type=deep-prefix motive @extensions]{ - use ./list result = [&] -search &type=$type $motive | peach [f]{ local:f = $f - if (list:contains [e]{ has-suffix $f .$e } $extensions) { + if (list:contains [e]{ str:has-suffix $f .$e } $extensions) { result[$f] = $nil } } diff --git a/lib/moi/util/ip.elv b/lib/moi/util/ip.elv index 655dce5..b965d98 100644 --- a/lib/moi/util/ip.elv +++ b/lib/moi/util/ip.elv @@ -40,14 +40,13 @@ fn -long-part6 [p]{ fn -middle-part6 [p]{ while (and (> (count $p) 1) (eq $p[0] 0)) { - p = $p[1:] + p = $p[1..] } put $p } fn -find-max0 [parts]{ use ./list - use ./condition local:idx local:s = -1 1 local:ci local:cs local:f = -1 0 $false list:loop [i p]{ @@ -78,7 +77,7 @@ fn long6 [ip]{ if (> $c 0) { local:i = (str:index $ip '::') local:z = (repeat $c ':' | str:join '') - ip = (str:join '' [$ip[:$i] $z $ip[{$i}:]]) + ip = (str:join '' [$ip[..$i] $z $ip[{$i}..]]) } str:split ':' $ip | each $-long-part6~ | str:join ':' } @@ -91,7 +90,7 @@ fn short6 [ip]{ local:parts = [(str:split ':' (middle6 $ip))] local:i local:s = (-find-max0 $parts) if (>= $i 0) { - local:left local:right = $parts[:$i] $parts[(+ $i $s):] + local:left local:right = $parts[..$i] $parts[(+ $i $s)..] if (== (count $left) 0) { left = [''] } @@ -111,7 +110,7 @@ fn -cmp [e1 e2]{ local:c = 0 list:loop [i p1]{ local:p2 = $e2[$i] - c = (condition:set (< $p1 $p2) -1 (condition:set (> $p1 $p2) 1 0)) + c = (condition:cset (< $p1 $p2) -1 (condition:cset (> $p1 $p2) 1 0)) if (!= $c 0) { break } @@ -149,6 +148,6 @@ fn cmp [ip1 ip2]{ put -1 } } else { - fali 'Not an IP: '$ip1' → '$ip2 + fail 'Not an IP: '$ip1' → '$ip2 } } diff --git a/lib/moi/util/list.elv b/lib/moi/util/list.elv index a3ff1bb..cc2e1af 100644 --- a/lib/moi/util/list.elv +++ b/lib/moi/util/list.elv @@ -1,230 +1,23 @@ -use ./condition - -fn -i [&reverse=false i c]{ - if (and (== $c 0) (or (== $i 0) ($i -1))) { - put 0 - return - } - if (< $i 0) { - i = (+ $c $i) - } - if (or (and (>= $i 0) (< $i $c)) (and (== $i -1) $reverse) (and (== $i $c) (not $reverse))) { - put $i - } else { - fail 'Index out of range' - } -} -fn -indexes [&from=$false &step=1 l]{ - if (== $step 0) { - fail 'Step must be ≠ 0' - } - local:c local:r = (count $l) (< $step 0) - if (not $from) { - if $r { - range &step=$step[1:] $c | each [i]{ - $c $i 1 } - } else { - range &step=$step $c - } - } else { - from = (-i &reverse=$r $from $c) - if $r { - c = (+ $from 1) - range &step=$step[1:] $c | each [i]{ - $c $i 1 } - } else { - range &step=$step $from $c - } - } -} - -fn -loop [&from=$false &step=1 &end=$false cb l]{ - if (not $end) { - -indexes &from=$from &step=$step $l | each [i]{ - put [$i $l[$i]] - } | each [e]{ - $cb $@e - } - } else { - -indexes &from=$from &step=$step $l | each [i]{ - put [$i $l[$i]] - } | each [e]{ - local:i local:v = $@e - if ($end $i $v) { - break - } - $cb $i $v - } - } -} -fn -ploop [&from=$false &step=1 cb l]{ - -indexes &from=$from &step=$step $l | peach [i]{ - put [$i $l[$i]] - } | peach [e]{ - $cb $@e - } -} - -fn -reverse [l]{ - -indexes &step=-1 $l | each [i]{ put $l[$i] } -} -fn -reach [cb l]{ - -reverse $l | each [v]{ $cb $v } -} - -fn -empty [l]{ eq (count $l) 0 } - -fn -filter [cb l]{ - each [v]{ - if ($cb $v) { - put $v - } - } $l -} -fn -first [&from=$false &reverse=$false cb l]{ - local:f = [v]{ - if ($cb $v) { - put $v - break - } - } - if $reverse { - if $from { - local:end = (-i $from (count $l)) - -reach $f $l[:(+ $end 1)] - } else { - -reach $f $l - } - } else { - if $from { - from = (-i $from (count $l)) - drop $from $l | each $f - } else { - each $f $l - } - } -} - -fn -filter-index [cb l]{ - -loop [i v]{ - if ($cb $v) { - put $i - } - } $l -} -fn -first-index [&from=$false &reverse=$false cb l]{ - local:idx = -1 - -loop &from=$from &step=(condition:set $reverse -1 1) [i v]{ - if ($cb $v) { - idx = $i - break - } - } $l - put $idx -} - -fn -search [cb l]{ - -loop [i v]{ - if ($cb $i $v) { - put $v - } - } $l -} -fn -search-first [&from=$false &reverse=$false cb l]{ - -loop &from=$from &step=(condition:set $reverse -1 1) [i v]{ - if ($cb $i $v) { - put $v - break - } - } $l -} - -fn -search-index [cb l]{ - -loop [i v]{ - if ($cb $i $v) { - put $i - } - } $l -} -fn -search-first-index [&from=$false &reverse=$false cb l]{ - local:idx = -1 - -loop &from=$from &step=(condition:set $reverse -1 1) [i v]{ - if ($cb $i $v) { - idx = $i - break - } - } - put $idx -} - -fn -contains [cb l]{ - local:e = $false - each [v]{ - if ($cb $v) { - e = $true - break - } - } $l - put $e -} -fn -exists [cb l]{ - local:e = $false - -loop [i v]{ - if ($cb $i $v) { - e = $true - break - } - } $l - put $e -} - -fn -remove-duplicate [l]{ - local:done = [&] - each [v]{ - put [&v=$v &e=(has-key $done $v)] - done[$v] = $nil - } $l | each [v]{ - assoc $v k (not $v[e]) - } | each [v]{ - if $v[k] { - put $v[v] - } - } -} - -fn -premove-duplicate [l]{ - local:done= [&] - peach [v]{ - local:v = $v - done[$v] = $nil - } - keys $done -} - -fn -swap [i j l]{ - local:c = (count $l) - i j = (-i $i $c) (-i $j $c) - if (or (eq $i $c) (eq $j $c)) { - fail 'Index out of range' - } - if (eq $i $j) { - all $l - } else { - i j = (condition:mset (< $i $j) [$i $j] [$j $i]) - take $i $l - put $l[j] - all $l[(+ $i 1):$j] - put $l[$i] - drop (+ $j 1) $l - } -} +use builtin +use str fn -p [@argv]{ local:c = (count $argv) - if (eq $c 0) { - put [(all)] - } elif (eq $c 1) { + if (== $c 0) { + put [ (all) ] + } elif (== $c 1) { put $argv[0] } else { - fail '0 or 1 argument needed' + fail '0 or 1 argument needed given '$c' arguments: ['(each [e]{ put '"'$e'"' } $argv | str:join ', ')']' + } +} + +fn -r [step begin end]{ + if (> $step 0) { + builtin:range &step=$step $begin (+ $end 1) + } else { + local:d = (+ $begin $end) + builtin:range &step=(* $step -1) $end (+ $begin 1) | each [e]{ - $d $e } } } @@ -236,38 +29,214 @@ fn to-list [@argv]{ } } -fn indexes [&from=$false &step=1 @argv]{ -indexes &from=$from &step=1 (-p $@argv) } +fn range [&step=1 b @r]{ + if (== $step 0) { + fail 'bad value: step must be positive, but is 0' + } + local:c = (count $r) + if (> $c 1) { + fail 'usage: list:range &step=1 begin? end' + } + local:e = 0 + if (== $c 0) { + if (> $step 0) { + b e = $e $b + } + } else { + e = $r[0] + } + -r $step $b $e +} -fn loop [&from=$false &step=1 &end=$false cb @argv]{ -loop &from=$from &step=$step &end=$end $cb (-p $@argv) } -fn rloop [&end=$false cb @argv]{ loop &step=-1 &end=$end $cb $@argv } -fn ploop [&from=$false &step=1 cb @argv]{ -ploop &from=$from &step=$step $cb (-p $@argv) } +fn indexes [&from=$false &step=1 @argv]{ + if (== $step 0) { + fail 'bad value: step must be positive, but is 0' + } + local:l = (-p $@argv) + local:c = (count $l) + if (not $from) { + range &step=$step (- $c 1) + } else { + if (< $from 0) { + from = (+ $c $from) + } + if (> $step 0) { + if (< $from 0) { + from = 0 + } + range &step=$step $from (- $c 1) + } else { + if (>= $from $c) { + from = (- $c 1) + } + range &step=$step $from 0 + } + } +} -fn reverse [@argv]{ -reverse (-p $@argv) } -fn reach [cb @argv]{ -reach $cb (-p $@argv) } +fn -for [&from=$false &step=1 @argv]{ + local:l = (-p $@argv) + indexes &from=$from &step=$step $l | each [i]{ put [ $i $l[$i] ] } +} -fn empty [@argv]{ -empty (-p $@argv) } +fn loop [&from=$false &step=1 &end=$false cb @argv]{ + if (not $end) { + -for &from=$from &step=$step $@argv | each [e]{ $cb $@e } + } else { + -for &from=$from &step=$step $@argv | each [e]{ + local:i local:v = $@e + if ($end $i $v) { + break + } + $cb $i $v + } + } +} +fn ploop [&from=$false &step=1 cb @argv]{ + -for &from=$from &step=$step $@argv | peach [e]{ $cb $@e } +} +fn reverse [@argv]{ loop &step=-1 [_ e]{ put $e } $@argv } +fn reach [cb @argv]{ reverse $@argv | each [e]{ cb $e } } + +fn empty [@argv]{ == (count (-p $@argv)) 0 } fn not-empty [@argv]{ not (empty $@argv) } -fn filter [cb @argv]{ -filter $cb (-p $@argv) } +fn filter [cb @argv]{ + each [v]{ + if ($cb $v) { + put $v + } + } (-p $@argv) +} fn filter-not [cb @argv]{ filter [v]{ not ($cb $v) } $@argv } -fn first [&from=$false &reverse=$false cb @argv]{ -first &from=$from &reverse=$reverse $cb (-p $@argv) } +fn first [&from=$false &reverse=$false cb @argv]{ + local:f = [v]{ + if ($cb $v) { + put $v + break + } + } + local:l = (-p $@argv) + if (not $from) { + if $reverse { + reach $f $l + } else { + each $f $l + } + } else { + local:c = (count $l) + if (< $from 0) { + from = (+ $c $from) + } + if $reverse { + local:e = (+ $from 1) + if (> $e $c) { + e = $c + } elif (< $e 0) { + e = 0 + } + reach $f $l[..$e] + } else { + local:b = $from + if (> $b $c) { + b = $c + } elif (< $b 0) { + b = 0 + } + each $f $l[$b..] + } + } +} -fn filter-index [cb @argv]{ -filter-index $cb (-p $@argv) } +fn filter-index [cb @argv]{ + loop [i v]{ + if ($cb $v) { + put $i + } + } $@argv +} fn filter-index-not [cb @argv]{ filter-index [v]{ not ($cb $v) } $@argv } -fn first-index [&from=$false &reverse=$false cb @argv]{ -first-index &from=$from &reverse=$reverse $cb (-p $@argv) } +fn first-index [&from=$false &reverse=$false cb @argv]{ + local:idx = -1 + local:step = 1 + if $reverse { + step = -1 + } + loop &from=$from &step=$step [i v]{ + if ($cb $v) { + idx = $i + break + } + } $@argv + put $idx +} -fn search [cb @argv]{ -search $cb (-p $@argv) } +fn search [cb @argv]{ + loop [i v]{ + if ($cb $i $v) { + put $v + } + } $@argv +} fn search-not [cb @argv]{ search [i v]{ not ($cb $i $v) } $@argv } -fn search-first [&from=$false &reverse=$false cb @argv]{ -search-first &from=$from &reverse=$reverse $cb (-p $@argv) } +fn search-first [&from=$false &reverse=$false cb @argv]{ + local:step = 1 + if $reverse { + step = -1 + } + loop &from=$from &step=$step [i v]{ + if ($cb $i $v) { + put $v + break + } + } $@argv +} -fn search-index [cb @argv]{ -search-index $cb (-p $@argv) } +fn search-index [cb @argv]{ + loop [i v]{ + if ($cb $i $v) { + put $i + } + } $@argv +} fn search-index-not [cb @argv]{ search-index [i v]{ not ($cb $i $v) } $@argv } -fn search-first-index [&from=$false &reverse=$false cb @argv]{ -search-first-index &from=$from &reverse=$reverse $cb (-p $@argv) } +fn search-first-index [&from=$false &reverse=$false cb @argv]{ + local:idx = -1 + local:step = 1 + if $reverse { + step = -1 + } + loop &from=$from &step=$step [i v]{ + if ($cb $i $v) { + idx = $i + break + } + } $@argv + put $idx +} -fn contains [cb @argv]{ -contains $cb (-p $@argv) } +fn contains [cb @argv]{ + local:e = $false + each [v]{ + if ($cb $v) { + e = $true + break + } + } (-p $@argv) + put $e +} fn contains-not [cb @argv]{ contains [v]{ not ($cb $v) } $@argv } -fn exists [cb @argv]{ -exists $cb (-p $@argv) } +fn exists [cb @argv]{ + local:e = $false + loop [i v]{ + if ($cb $i $v) { + e = $true + break + } + } $@argv + put $e +} fn exists-not [cb @argv]{ exists [i v]{ $cb $i $v } $@argv } fn includes [v @argv]{ contains [e]{ is $v $e } $@argv } @@ -278,24 +247,46 @@ fn reduce [v cb @argv]{ put $v } -fn remove-duplicate [@argv]{ -remove-duplicate (-p $@argv) } -fn premove-duplicate [@argv]{ -premove-duplicate (-p $@argv) } +fn remove-duplicate [@argv]{ + local:done = [&] + each [v]{ + put [&v=$v &e=(has-key $done $v)] + done[$v] = $nil + } (-p $@argv) | each [v]{ + assoc $v k (not $v[e]) + } | each [v]{ + if $v[k] { + put $v[v] + } + } +} +fn premove-duplicate [@argv]{ + local:done= [&] + peach [v]{ + local:v = $v + done[$v] = $nil + } (-p $@argv) + keys $done +} -fn swap [i j @argv]{ -swap $i $j (-p $@argv) } - -fn -s1 [cb l e]{ +fn swap [i j @argv]{ + local:l = (-p $@argv) local:c = (count $l) - local:i = (first-index [v]{ $cb $e $v } $l) - if (eq $i 0) { - put $e + i j = (-i $i $c) (-i $j $c) + if (or (== $i $c) (== $j $c)) { + fail 'Index out of range' + } + if (== $i $j) { all $l - } elif (< $i 0) { - all $l - put $e } else { - all $l[:$i] - put $e - all $l[{$i}:] + if (> $i $j) { + i j = $j $i + } + take $i $l + put $l[j] + all $l[(+ $i 1)..$j] + put $l[$i] + drop (+ $j 1) $l } } @@ -303,9 +294,4 @@ fn less [cb]{ local:l = [a b]{ < ($cb $a $b) 0 } put $l } - -fn -sort [cb l]{ - order &less-than=(less $cb) $l -} - -fn sort [cb @argv]{ -sort $cb (-p $@argv) } +fn sort [cb @argv]{ order &less-than=(less $cb) (-p $@argv) } diff --git a/lib/moi/util/map.elv b/lib/moi/util/map.elv index 0536a48..6311c7c 100644 --- a/lib/moi/util/map.elv +++ b/lib/moi/util/map.elv @@ -21,9 +21,11 @@ fn unzip [container]{ } fn zip [lkeys lvalues]{ - use ./condition local:ck local:cv = (count $lkeys) (count $lvalues) - local:c = (condition:set (> $ck $cv) $cv $ck) + local:c = $ck + if (> $ck $cv) { + c = $cv + } local:result = [&] range $c | peach [i]{ put [&k=$lkeys[$i] &i=$i] diff --git a/lib/moi/util/number.elv b/lib/moi/util/number.elv deleted file mode 100644 index f922717..0000000 --- a/lib/moi/util/number.elv +++ /dev/null @@ -1,40 +0,0 @@ -fn sign [n]{ - if (> $n 0) { - put 1 - } elif (< $n 0) { - put -1 - } else { - put 0 - } -} - -fn negative [n]{ < $n 0 } -fn positive [n]{ >= $n 0 } - -fn ++ [n]{ to-string (+ $n 1) } -fn -- [n]{ to-string (+ $n 1) } - - -fn neg [n]{ to-string (* $n -1) } -fn abs [n]{ - use ./condition - condition:call (negative $n) $neg~ $put~ $n -} - -fn sum [@numbers]{ - use ./list - to-string (list:reduce 0 $+~ $numbers) -} - -fn -minmax [t numbers]{ - if (== (count $numbers) 0) { - return - } - use ./list - use ./condition - f = [c v]{ condition:set ($t $v $c) $v $c } - list:reduce $numbers[0] $f $numbers[1:] -} - -fn min [@numbers]{ -minmax $<~ $numbers } -fn max [@numbers]{ -minmax $>~ $numbers } diff --git a/rc.elv b/rc.elv index 52d50b3..44cda30 100644 --- a/rc.elv +++ b/rc.elv @@ -1,63 +1,31 @@ -use github.com/muesli/elvish-libs/theme/powerline -powerline:prompt-pwd-dir-length = 0 -powerline:timestamp-format = "%Y.%m.%d %H:%M" +set-env BAT_PAGER 'less -RF' +set-env EDITOR vim +set-env VIEW 'vim -R' +set-env CURRENT_SHELL 'elvish' +paths = [$@paths /home/benjamin/bin /home/benjamin/Go/bin ] -#edit:prompt={ -# put "┌─"(styled "["(date "+%d.%m.%Y %H:%M")"]" yellow bold); put " --- "(styled "["(pwd)"]" blue bold) -# #echo "\n" -# put "\n└─"(styled "["(whoami)"@"(hostname) green bold);put ' > ' -# #put "┌─";edit:styled "["(date "+%d.%m.%Y %H:%M")"]" [yellow bold]; put " --- ";edit:styled "["(pwd)"]" [blue bold] -# ##echo "\n" -# #put "\n└─";edit:styled "["(whoami)"@"(hostname) [green bold];put ' > ' -#} - -#use github.com/zzamboni/elvish-modules/alias -#-exports- = (alias:export) - -fn whichall [@a]{ - each [p]{ - each [f]{ - try { - ll $p/$f 2>/dev/null - } except e { - } - } $a - } $paths +{ + use moi/util/list + if (list:includes-not /usr/local/bin $paths) { + paths = [ $@paths /usr/local/bin ] + } } -fn ++ [n]{ to-string (+ $n 1) } -fn -- [n]{ to-string (- $n 1) } - notify-bg-job-success = $false -use moi/aliases +edit:insert:binding[Tab] = { edit:completion:smart-start; edit:navigation:trigger-filter } +edit:insert:binding[Ctrl-H] = $edit:histlist:start~ -use github.com/zzamboni/elvish-completions/builtins -use github.com/zzamboni/elvish-completions/git -git:git-command = hub -git:init -use github.com/zzamboni/elvish-completions/cd -use github.com/zzamboni/elvish-completions/ssh - -use github.com/xiaq/edit.elv/compl/go +edit:prompt = { go-prompt } +edit:rprompt = { nop } use moi/completion --source ~/.elvish/lib/moi/util.elv +use moi/alias +use moi/util/common -edit:insert:binding[Tab] = { edit:completion:smart-start } #; edit:navigation:trigger-filter } - -set-env GOPATH ~/Go -set-env PAGER 'bat -p' -set-env EDITOR vim -set-env VIEW 'vim -R' -paths = [$@paths ~/bin $E:GOPATH/bin ] - --exports- = (aliases:export) - -fn dcd [@_args]{ - use str - cmd = (aliases:export); $cmd[br~] --only-folders --cmd (str:join ' ' $_args)' :cd' +{ + use ./aliases/get-uid uid + if (not (uid:-is-root)) { + tache search -d 2w not del + } } - -tache search -d 2w not del -