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 { } else {
ip:comp $e1 $e2 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 ]
}
}
}
} }
} }
var khosts = [&] fn searchips {|id|
cat ~/.ssh/known_hosts | eawk {|_ hosts @rest| if (has-key $ids $id) {
var key = (str:join ' ' $rest) each {|h|
if (not (has-key $khosts $key)) { if (ip:is-ip $h) {
set khosts[$key] = [&] put $h
} }
str:split , $hosts | each {|h| } $ids[$id]
set khosts[$key][$h] = $nil
} }
} }
var lines = [(keys $khosts | each {|key| fn hashost {|id|
var hosts = (keys $khosts[$key] | list:sort $sort-host~ | str:join ,) if (has-key $ids $id) {
put $hosts $key | str:join ' ' list:contains {|h| not (ip:is-ip $h) } $ids[$id]
})] } else {
echo (str:join "\n" $lines) > ~/.ssh/known_hosts put $false
}
}
fn formatlines {
keys $hosts | order | each {|h|
order $hosts[$h] | each {|id|
var hid = (str:join ',' [ $h (searchips $id) ])
put $hid $id | str:join ' '
}
}
keys $ips | list:sort $ip:comp~ | each {|ip|
order $ips[$ip] | each {|id|
if (not (hashost $id)) {
put $ip $id | str:join ' '
}
}
}
}
readfile
var @lines = (formatlines)
echo (str:join "\n" $lines) > $file
} }

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 }