Utilisation de kak comme éditeur par défaut + réecriture du script de nettoyage du known_hosts

This commit is contained in:
Benjamin VAUDOUR 2022-02-19 09:56:19 +00:00
parent f94229ddd0
commit 4f516d7cbe
2 changed files with 68 additions and 25 deletions

View File

@ -4,32 +4,73 @@ edit:add-var cleankh~ {|@argv|
use framagit.org/benjamin.vaudour/elv-lib/mods/ip use framagit.org/benjamin.vaudour/elv-lib/mods/ip
use framagit.org/benjamin.vaudour/elv-lib/mods/list use framagit.org/benjamin.vaudour/elv-lib/mods/list
fn sort-host {|e1 e2| var hosts = [&]
var i1 = (common:cond (ip:is-ip $e1) 1 0) var ips = [&]
var i2 = (common:cond (ip:is-ip $e2) 1 0) var ids = [&]
if (!= $i1 $i2) { var file = $E:HOME/.ssh/known_hosts
- $i1 $i2
} elif (== $i1 0) { fn readfile {
compare $e1 $e2 cat $file | each {|l|
if (not (str:has-prefix $l '#')) {
put $l
}
} | eawk {|_ host @rest|
var id = (str:join ' ' $rest)
var ihosts = []
str:split ',' $host | each {|h|
set @ihosts = $@ihosts $h
if (ip:is-ip $h) {
if (not (has-key $ips $h)) {
set ips[$h] = [ $id ]
} else {
set ips[$h] = [ (all $ips[$h]) $id ]
}
} else {
if (not (has-key $hosts $h)) {
set hosts[$h] = [ $id ]
} else {
set hosts[$h] = [ (all $hosts[$h]) $id ]
}
}
}
}
}
fn searchips {|id|
if (has-key $ids $id) {
each {|h|
if (ip:is-ip $h) {
put $h
}
} $ids[$id]
}
}
fn hashost {|id|
if (has-key $ids $id) {
list:contains {|h| not (ip:is-ip $h) } $ids[$id]
} else { } else {
ip:comp $e1 $e2 put $false
} }
} }
var khosts = [&] fn formatlines {
cat ~/.ssh/known_hosts | eawk {|_ hosts @rest| keys $hosts | order | each {|h|
var key = (str:join ' ' $rest) order $hosts[$h] | each {|id|
if (not (has-key $khosts $key)) { var hid = (str:join ',' [ $h (searchips $id) ])
set khosts[$key] = [&] put $hid $id | str:join ' '
}
} }
str:split , $hosts | each {|h| keys $ips | list:sort $ip:comp~ | each {|ip|
set khosts[$key][$h] = $nil order $ips[$ip] | each {|id|
if (not (hashost $id)) {
put $ip $id | str:join ' '
}
}
} }
} }
var lines = [(keys $khosts | each {|key| readfile
var hosts = (keys $khosts[$key] | list:sort $sort-host~ | str:join ,) var @lines = (formatlines)
put $hosts $key | str:join ' ' echo (str:join "\n" $lines) > $file
})]
echo (str:join "\n" $lines) > ~/.ssh/known_hosts
} }

View File

@ -1,4 +1,5 @@
var cmd = $e:nvim~ #var cmd = $e:nvim~
var cmd = $e:kak~
edit:add-var vi~ {|@argv| $cmd $@argv } edit:add-var vi~ {|@argv| $cmd $@argv }
edit:add-var vb~ {|@argv| $cmd $@argv ~/.bashrc } edit:add-var vb~ {|@argv| $cmd $@argv ~/.bashrc }
@ -6,5 +7,6 @@ edit:add-var vc~ {|@argv| $cmd $@argv ~/.vimrc }
edit:add-var ve~ {|@argv| $cmd $@argv ~/.config/elvish/rc.elv } 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 vf~ {|@argv| $cmd $@argv ~/.config/fish/config.fish }
edit:add-var vp~ {|@argv| $cmd $@argv PKGBUILD } edit:add-var vp~ {|@argv| $cmd $@argv PKGBUILD }
edit:add-var vv~ {|@argv| $cmd -R $@argv } #edit:add-var vv~ {|@argv| $cmd -R $@argv }
edit:add-var vv~ {|@argv| $cmd -ro $@argv }
edit:add-var vz~ {|@argv| $cmd $@argv ~/.zshrc } edit:add-var vz~ {|@argv| $cmd $@argv ~/.zshrc }