elvish_config/aliases/dig.elv

99 lines
2.0 KiB
Plaintext
Raw Permalink Normal View History

2024-06-16 10:18:51 +00:00
edit:add-var dig-all~ {|@argv|
use re
2020-07-22 09:24:43 +00:00
use str
use framagit.org/benjamin.vaudour/elv-lib/mods/common
use framagit.org/benjamin.vaudour/elv-lib/mods/format
use framagit.org/benjamin.vaudour/elv-lib/mods/list
2020-07-22 09:24:43 +00:00
var default_records = [
2020-07-22 09:24:43 +00:00
A
AAAA
CNAME
PTR
TXT
MX
SRV
NAPTR
NS
SOA
]
var records servers = [] []
2021-10-13 18:43:40 +00:00
var flags = [
2020-07-22 09:24:43 +00:00
+noall
+answer
]
var domains use_dig = [] $true
fn init {
if (and (list:is-not-empty $argv) (eq $argv[0] -d)) {
set use_dig argv = $false $argv[1..]
}
2021-12-11 21:09:02 +00:00
each {|e|
if (eq $e[0] +) {
set @flags = $@flags $e
} elif (eq $e[0] @) {
set @servers = $@servers $e
} elif (list:contains $e $default_records) {
set @records = $@records $e
2020-07-22 09:24:43 +00:00
} else {
set @domains = $@domains $e
2020-07-22 09:24:43 +00:00
}
} $argv
if (list:is-empty $records) {
2021-10-13 18:43:40 +00:00
set records = $default_records
2020-07-22 09:24:43 +00:00
}
}
2021-12-11 21:09:02 +00:00
fn format {|results|
re:awk {|_ @args|
put [ $args[0] (all $args[2..]) ]
2021-12-11 21:09:02 +00:00
} $results | list:remove-duplicate | list:sort {|l1 l2|
var c = (compare $l1[0] $l2[0])
if (== $c 0) {
set c = (compare $l1[2] $l2[2])
}
put $c
} | each {|e| str:join ' ' $e} | format:tabulate
}
2021-12-11 21:09:02 +00:00
fn drillr {|d @args|
var @results = (peach {|r|
2021-12-11 21:09:02 +00:00
e:drill $@args $r $d | list:filter {|e|
and (> (count $e) 2) (not-eq $e[..2] ';;')
}
} $records)
format $results
}
2020-07-22 09:24:43 +00:00
2021-12-11 21:09:02 +00:00
fn digr {|d @args|
var @results = (peach {|r|
2020-07-22 09:24:43 +00:00
e:dig $@args $r $d $@flags
} $records)
format $results
2020-07-22 09:24:43 +00:00
}
2021-12-11 21:09:02 +00:00
fn req {|d @args|
common:cexec $use_dig { digr $d $@args } { drillr $d $@args }
}
2021-12-11 21:09:02 +00:00
fn digs {|s d|
put (echo (styled $s bright-yellow))
req $d $s
2020-07-22 09:24:43 +00:00
}
2021-12-11 21:09:02 +00:00
fn digd {|d|
var @results = (echo (styled 'Domaine: '$d bright-green))
if (list:is-not-empty $servers) {
2021-12-11 21:09:02 +00:00
each {|s|
2021-10-13 18:43:40 +00:00
set @results = $@results (digs $s $d)
2020-07-22 09:24:43 +00:00
} $servers
} else {
2021-10-13 18:43:40 +00:00
set @results = $@results (req $d)
2020-07-22 09:24:43 +00:00
}
echo (str:join "\n" $results)
2020-07-22 09:24:43 +00:00
}
init
peach $digd~ $domains
2020-07-22 09:24:43 +00:00
}