From 7a55097eee3493b7c21a549137b3b295236a5c98 Mon Sep 17 00:00:00 2001 From: Benjamin VAUDOUR Date: Sat, 27 Aug 2022 11:57:06 +0200 Subject: [PATCH] =?UTF-8?q?Utilisation=20de=20nvim=20comme=20=C3=A9diteur?= =?UTF-8?q?=20par=20d=C3=A9faut=20+=20ajout=20d=E2=80=99un=20gestionnaire?= =?UTF-8?q?=20de=20VPN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aliases/commitkcp.elv | 2 +- aliases/vi.elv | 9 +-- aliases/vpn.elv | 132 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 aliases/vpn.elv diff --git a/aliases/commitkcp.elv b/aliases/commitkcp.elv index d8272b0..f9e0813 100644 --- a/aliases/commitkcp.elv +++ b/aliases/commitkcp.elv @@ -15,6 +15,6 @@ edit:add-var commitkcp~ {|@argv| set msg = (printf '%s - %s' $msg (str:join ' ' $argv)) } - printf "git commit -am '%s'; git push" $msg + printf "git commit -am '%s'; git push\n" $msg git commit -am $msg; git push } diff --git a/aliases/vi.elv b/aliases/vi.elv index 2a25be1..f3bbc21 100644 --- a/aliases/vi.elv +++ b/aliases/vi.elv @@ -1,6 +1,6 @@ -var cmd = $e:nvim~ +#var cmd = $e:nvim~ #var cmd = $e:helix~ -#var cmd = $e:kak~ +var cmd = $e:kak~ #var cmd = $e:emacs~ edit:add-var vi~ {|@argv| $cmd $@argv } @@ -9,7 +9,8 @@ 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 } # vim/nvim -#edit:add-var vv~ {|@argv| $cmd -ro $@argv } # kak +#edit:add-var vv~ {|@argv| $cmd -R $@argv } # vim/nvim +edit:add-var vv~ {|@argv| $cmd -ro $@argv } # kak +#edit:add-var vv~ {|@argv| $cmd $@argv } # helix - pas de mode lecture seule pour le moment #edit:add-var vv~ {|@argv| $cmd $@argv --eval '(setq buffer-read-only t)' } # emacs edit:add-var vz~ {|@argv| $cmd $@argv ~/.zshrc } diff --git a/aliases/vpn.elv b/aliases/vpn.elv new file mode 100644 index 0000000..1b1ee11 --- /dev/null +++ b/aliases/vpn.elv @@ -0,0 +1,132 @@ +use str +use framagit.org/benjamin.vaudour/elv-lib/mods/list + +var vpnType = [ + &wireguard=$nil + &vpn=$nil +] + +var shortcut = [ + &ca=ca.kaosx.cf + &fr=fr.kaosx.cf + &lu=luence-wg + &lu2=luence-ovpn + &cli=lunce-client + &nl=proton-nl5 + &jp=proton-jp2 + &us=proton-us3 +] + +var next = [ + &ca.kaosx.cf=fr.kaosx.cf + &fr.kaosx.cf=luence-wg + &luence-wg=luence-client + &luence-ovpn=luence-client + &luence-client=proton-nl5 + &proton-nl5=proton-us3 + &proton-us3=proton-jp2 +] + +fn -list {|&active=$false| + var @argv = connection show + if $active { + set @argv = $@argv --active + } + nmcli $@argv | eawk {|_ @name uuid tpe dev| + if (has-key $vpnType $tpe) { + str:join ' ' $name + } + } +} + +fn -up {|name| + nmcli connection up $name +} + +fn -down {|name| + nmcli connection down $name +} + +fn -active {|| + -list &active=$true +} + +fn -is-active {|name| + -active | list:contains $name +} + +fn -next {|| + var @n = (-active | list:first {|e| has-key $next $e }) + if (== 1 (count $n)) { + put $next[$n[0]] + } else { + put ca.kaosx.cf + } +} + +fn -vpn-stop {|| + var @a = (-active) + if (== (count $a) 0) { + echo 'Aucune connexion active' + } else { + -active | each $-down~ + } +} + +fn -vpn-start {|name| + if (has-key $shortcut $name) { + set name = $shortcut[$name] + } + if (not (-list | list:contains $name)) { + printf "Le VPN “%s” n’èxiste pas\n" $name + } else { + -active | each $-down~ + -up $name + } +} + +fn -vpn-list {|| + var @act = (-active) + -list | each {|n| + if (list:contains $n $act) { + echo (styled $n green) + } else { + echo $n + } + } +} + +fn -vpn-help {|| + echo 'vpn: Active ou désactive les connections VPN' + echo 'Usage:' + echo ' help Affiche cette aide' + echo ' list Liste les VPN disponibles' + echo ' stop Arrête toutes les connexions VPN actives' + echo ' Active la connexion VPN donnée et désactive les autres' + echo ' (sans argument) Active la prochaine connexion VPN et désactive les autres' +} + +fn -vpn {|| + -vpn-start (-next) +} + +edit:add-var vpn~ {|@argv| + var c = (count $argv) + if (== $c 0) { + -vpn + } elif (!= $c 1) { + -vpn-help + fail 'Arguments invalides' + } else { + var e = $argv[0] + if (eq $e help) { + -vpn-help + } elif (eq $e list) { + -vpn-list + } elif (eq $e stop) { + -vpn-stop + } else { + -vpn-start $e + } + } +}