Utilisation de nvim comme éditeur par défaut + ajout d’un gestionnaire de VPN

This commit is contained in:
Benjamin VAUDOUR 2022-08-27 11:57:06 +02:00
parent 4f5dd6ea11
commit 7a55097eee
3 changed files with 138 additions and 5 deletions

View File

@ -15,6 +15,6 @@ edit:add-var commitkcp~ {|@argv|
set msg = (printf '%s - %s' $msg (str:join ' ' $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 git commit -am $msg; git push
} }

View File

@ -1,6 +1,6 @@
var cmd = $e:nvim~ #var cmd = $e:nvim~
#var cmd = $e:helix~ #var cmd = $e:helix~
#var cmd = $e:kak~ var cmd = $e:kak~
#var cmd = $e:emacs~ #var cmd = $e:emacs~
edit:add-var vi~ {|@argv| $cmd $@argv } 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 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 } # vim/nvim #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 -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 vv~ {|@argv| $cmd $@argv --eval '(setq buffer-read-only t)' } # emacs
edit:add-var vz~ {|@argv| $cmd $@argv ~/.zshrc } edit:add-var vz~ {|@argv| $cmd $@argv ~/.zshrc }

132
aliases/vpn.elv Normal file
View File

@ -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 ' <vpn> 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
}
}
}