This commit is contained in:
2024-01-08 20:50:29 +01:00
commit 2fb62acda6
121 changed files with 16413 additions and 0 deletions
+224
View File
@@ -0,0 +1,224 @@
@import "../config.rasi"
configuration {
modi: "";
show-icons: false;
drun-display-format: "{name}";
window-format: "{w} · {c} · {t}";
}
mainbox {
enabled: true;
spacing: 10px;
margin: 0px;
padding: 30px;
border: 0px solid;
border-radius: 0px 0px 0px 0px;
border-color: @border;
background-color: transparent;
children: [ "message", "listview", "inputbar" ];
}
inputbar {
enabled: true;
spacing: 10px;
margin: 0;
padding: 20px 0px 0;
border: 0px solid;
border-radius: 0px;
border-color: @border;
background-color: transparent;
text-color: @foreground;
children: [ "textbox-prompt-colon", "entry", "mode-switcher" ];
}
prompt {
enabled: true;
background-color: inherit;
text-color: inherit;
}
textbox-prompt-colon {
enabled: true;
padding: 5px 0px 0px 15px;
expand: false;
font: "MonarchOS 14";
str: "";
background-color: inherit;
text-color: inherit;
}
entry {
enabled: true;
padding: 5px 0px;
background-color: inherit;
text-color: inherit;
cursor: text;
placeholder: "...";
placeholder-color: inherit;
}
num-filtered-rows {
enabled: true;
expand: false;
background-color: inherit;
text-color: inherit;
}
textbox-num-sep {
enabled: true;
expand: false;
str: "/";
background-color: inherit;
text-color: inherit;
}
num-rows {
enabled: true;
expand: false;
background-color: inherit;
text-color: inherit;
}
case-indicator {
enabled: true;
background-color: inherit;
text-color: inherit;
}
/*****----- Listview -----*****/
listview {
enabled: true;
columns: 1;
lines: 2;
cycle: true;
dynamic: true;
scrollbar: false;
layout: vertical;
reverse: false;
fixed-height: true;
fixed-columns: true;
spacing: 5px;
margin: 0px;
padding: 0px;
border: 0px solid;
border-radius: 0px;
border-color: @border;
background-color: transparent;
text-color: @foreground;
cursor: "default";
}
scrollbar {
handle-width: 5px;
handle-color: @handle-colour;
border-radius: 10px;
background-color: transparent;
}
/*****----- Elements -----*****/
element {
enabled: true;
spacing: 10px;
margin: 0px;
padding: 5px 10px;
border: 0px solid;
border-radius: 10px;
border-color: @border;
background-color: transparent;
text-color: @foreground;
cursor: pointer;
}
element normal.normal {
background-color: transparent;
text-color: var(normal-foreground);
}
element normal.urgent {
background-color: var(urgent-background);
text-color: var(urgent-foreground);
}
element normal.active {
background-color: var(normal-foreground);
text-color: var(normal-background);
}
element selected.normal {
background-color: var(selected-normal-background);
text-color: var(normal-foreground);
}
element selected.urgent {
background-color: var(selected-urgent-background);
text-color: var(normal-background);
}
element selected.active {
background-color: var(selected-active-background);
text-color: var(normal-background);
}
element-icon {
background-color: transparent;
text-color: inherit;
size: 24px;
cursor: inherit;
}
element-text {
background-color: transparent;
text-color: inherit;
highlight: inherit;
cursor: inherit;
vertical-align: 0.5;
horizontal-align: 0.0;
}
/*****----- Mode Switcher -----*****/
mode-switcher{
enabled: true;
spacing: 10px;
margin: 0px;
padding: 0px;
border: 0px solid;
border-radius: 0px;
border-color: @border;
background-color: transparent;
text-color: @foreground;
}
button {
padding: 7px 15px 7px 10px;
border: 0px solid;
border-radius: 100%;
border-color: @border;
background-color: @alternate-background;
text-color: inherit;
cursor: pointer;
}
button selected {
background-color: var(selected-normal-background);
text-color: var(selected-normal-foreground);
}
/*****----- Message -----*****/
message {
enabled: true;
margin: 0px;
padding: 0px;
border: 0px solid;
border-radius: 0px 0px 0px 0px;
border-color: @border;
background-color: transparent;
text-color: @foreground;
}
textbox {
padding: 8px 10px;
border: 0px solid;
border-radius: 10px;
border-color: @border;
background-color: @alternate-background;
text-color: @foreground;
vertical-align: 0.5;
horizontal-align: 0.0;
highlight: none;
placeholder-color: @foreground;
blink: true;
markup: true;
}
error-message {
padding: 10px;
border: 2px solid;
border-radius: 10px;
border-color: @border;
background-color: @background;
text-color: @foreground;
}
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# Copyright (C) 2021 Damien Cassou
# Author: Damien Cassou <damien@cassou.me>
# Url: https://gitlab.com/DamienCassou/rofi-vpn
# Version: 0.2.0
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Commentary:
# This program uses rofi and nmcli to let the user enable/disable VPN
# connections.
# Code:
# What to show in front of an active VPN connection:
ACTIVE_PREFIX="󰌘 "
# What to show in front of an inactive VPN connection:
INACTIVE_PREFIX="󰌙 "
# Display on standard output all VPN connections, one per line. An
# active VPN connection is prefixed with `ACTIVE_PREFIX` and an inactive
# one is prefixed with `INACTIVE_PREFIX`.
function list_vpn_connections() {
nmcli --get-values ACTIVE,NAME,TYPE connection show \
| grep ':vpn$' \
| sed \
-e "s/^no:/${INACTIVE_PREFIX}/" \
-e "s/^yes:/${ACTIVE_PREFIX}/" \
-e 's/:vpn$//'
}
# Take a line as displayed by `list_vpn_connections()` as argument and
# use nmcli to toggle the corresponding connection.
function toggle_vpn_connection() {
local result="$1"
local connection
connection=$(extract_connection_name_from_result "${result}")
if [[ $result = ${ACTIVE_PREFIX}* ]]; then
feedback=$(nmcli connection down "$connection")
dunstify "VPN Status '$connection'" "$feedback" --replace=553
else
kitty --class "kitty-vpn" --title "VPN Connection" nmcli connection --ask up "$connection"
#feedback=$(nmcli connection up "$connection")
dunstify "VPN Status '$connection'" "" --replace=553
fi
}
# Take a line as displayed by `list_vpn_connections()` as argument and
# remove `ACTIVE_PREFIX` or `INACTIVE_PREFIX` to only display the
# connection name.
function extract_connection_name_from_result() {
local result="$1"
# I don't know how to use plain bash to remove the prefix so I'm
# using sed:
# shellcheck disable=SC2001
sed -e 's/^.* \([^ ]\+\)$/\1/' <<< "$result"
}
# Execute the `rofi` command. The first argument of the function is
# used as lines to select from.
function start_rofi() {
local content="$1"
echo -e "$content" | rofi -dmenu -theme $HOME/.config/rofi/nm-vpn/nm-vpn.rasi -mesg "󰖂 VPN Connection Manager" -icon "󰖂"
}
# List the VPN connections and let the user toggle one using rofi.
function main() {
local connections
local result
connections=$(list_vpn_connections)
result=$(start_rofi "$connections")
if [ -n "$result" ]; then
toggle_vpn_connection "$result"
else
exit 1
fi
}
main