feat: switch from rofi to wofi
This commit is contained in:
6
configs/wofi/config
Normal file
6
configs/wofi/config
Normal file
@ -0,0 +1,6 @@
|
||||
allow_images=true
|
||||
allow_markup=true
|
||||
width=500
|
||||
dynamic_lines=true
|
||||
term=allacritty
|
||||
insensitive=true
|
57
configs/wofi/select-vpn.sh
Executable file
57
configs/wofi/select-vpn.sh
Executable file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
# Connect to VPN connections
|
||||
|
||||
# Starts a scan of available broadcasting SSIDs
|
||||
# nmcli dev wifi rescan
|
||||
export LC_ALL="en_US.UTF-8"
|
||||
export LANG="en_US.UTF-8"
|
||||
export LANGUAGE="en_US:en"
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
FIELDS=NAME,TYPE,STATE
|
||||
POSITION=0
|
||||
XOFF=-30
|
||||
LOC=3
|
||||
CACHE=~/.local/tmp/vpn-wofi
|
||||
WWIDTH=340
|
||||
|
||||
LIST=$(nmcli --fields "$FIELDS" connection show | awk \
|
||||
-F "[ ]{2,}" \
|
||||
'$2 ~ /vpn/ {
|
||||
sub(/activated/, "");
|
||||
sub(/activating/, "");
|
||||
sub(/--/, "");
|
||||
printf "<tt>%-30s\t</tt>%s\n", $1,$3 }')
|
||||
|
||||
# Dynamically change the height of the rofi menu
|
||||
LINENUM=$(echo "$LIST" | wc -l)
|
||||
|
||||
WHEIGHT=$((30*$LINENUM))
|
||||
|
||||
CHENTRY=$(echo -e "$LIST" | uniq -u | \
|
||||
wofi -i \
|
||||
--dmenu \
|
||||
-p "Choose a VPN connection: " \
|
||||
--width "$WWIDTH" \
|
||||
--height $WHEIGHT \
|
||||
--cache-file ${CACHE} \
|
||||
--location $LOC \
|
||||
--xoffset $XOFF | \
|
||||
sed -e 's/<[^>]*>//g')
|
||||
|
||||
rm ${CACHE}
|
||||
|
||||
ACTIVE=$(echo $CHENTRY | awk -F "[ ]{2,}" '{print //}')
|
||||
|
||||
VPNID=$(echo "$CHENTRY" | awk -F "[ ]{2,}" '{print $1}')
|
||||
|
||||
# It is assumed that if the connection is in active, then
|
||||
# the user wants to deactivate it
|
||||
if [[ $ACTIVE =~ 1 ]]; then
|
||||
nmcli connection down "$VPNID"
|
||||
else
|
||||
nmcli connection up "$VPNID"
|
||||
fi
|
||||
|
||||
pkill -SIGRTMIN+2 waybar
|
105
configs/wofi/select-wifi.sh
Executable file
105
configs/wofi/select-wifi.sh
Executable file
@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env bash
|
||||
# Connect to WIFI
|
||||
# Modified from https://github.com/zbaylin/rofi-wifi-menu/blob/master/rofi-wifi-menu.sh
|
||||
|
||||
# export LC_ALL="en_US.UTF-8"
|
||||
export LANG="en_US.UTF-8"
|
||||
export LANGUAGE="en_US:en"
|
||||
# Starts a scan of available broadcasting SSIDs
|
||||
# nmcli dev wifi rescan
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# FIELDS=SSID,SECURITY,BARS,ACTIVE
|
||||
FIELDS=SSID,BARS,ACTIVE,SECURITY
|
||||
POSITION=0
|
||||
XOFF=-30
|
||||
LOC=3
|
||||
CACHE=~/.local/tmp/wifi-wofi
|
||||
WWIDTH=370
|
||||
MAXHEIGHT=1000
|
||||
|
||||
LIST=$(nmcli --fields "$FIELDS" device wifi list | sed '/^--/d' | \
|
||||
awk -F "[ ]{2,}" '/SSID/ {next} {;
|
||||
sub(/yes/, "", $3);
|
||||
sub(/no/, "", $3);
|
||||
if ($4 == "--") $4=""; else $4="";
|
||||
printf "<tt>%-4s %-26s </tt>%s %s\n", $2,$1,$3,$4 }')
|
||||
|
||||
# Bluetooth connections
|
||||
LISTB=$(nmcli --fields NAME,TYPE,ACTIVE con show | \
|
||||
awk -F "[ ]{2,}" '/bluetooth/ {;
|
||||
sub(/yes/, "", $3);
|
||||
sub(/no/, "", $3);
|
||||
printf "<tt> %-26s </tt>%s \n", $1,$3 }')
|
||||
|
||||
# Gives a list of known connections so we can parse it later
|
||||
KNOWNCON=$(nmcli connection show | awk -F '[[:space:]][[:space:]]+' '{printf "%s\n", $1}')
|
||||
|
||||
# Really janky way of telling if there is currently a connection
|
||||
CONSTATE=$(nmcli -fields WIFI g | awk '/enabled|disabled/ { print $0}')
|
||||
|
||||
CURRSSID=$(LANGUAGE=C nmcli -t -f active,ssid dev wifi | awk -F: '$1 ~ /^yes/ {print $2}')
|
||||
|
||||
if [[ ! -z $CURRSSID ]]; then
|
||||
HIGHLINE=$(echo "$(echo "$LIST" | awk -F "[ ]{2,}" '{print $2}' | grep -Fxn -m 1 "$CURRSSID" | awk -F ":" '{print $1}') + 1" | bc )
|
||||
fi
|
||||
|
||||
LINENUM=$(echo -e "toggle\nmanual\n${LISTB}\n${LIST}" | wc -l)
|
||||
|
||||
# If there are more than 20 SSIDs, the menu will still only have 20 lines
|
||||
if [ "$LINENUM" -gt 20 ] && [[ "$CONSTATE" =~ "enabled" ]]; then
|
||||
LINENUM=20
|
||||
elif [[ "$CONSTATE" =~ "disabled" ]]; then
|
||||
LINENUM=1
|
||||
fi
|
||||
|
||||
|
||||
if [[ "$CONSTATE" =~ "enabled" ]]; then
|
||||
TOGGLE="toggle off"
|
||||
elif [[ "$CONSTATE" =~ "disabled" ]]; then
|
||||
TOGGLE="toggle on"
|
||||
fi
|
||||
|
||||
CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LISTB\n$LIST" | uniq -u | \
|
||||
wofi -i --dmenu -p "Wi-Fi SSID: " --width "$WWIDTH" --lines ${LINENUM} --cache-file /dev/null --location $LOC --xoffset $XOFF | awk -F "[ ]{2,}" '{gsub(/<[^>]*>/, ""); print $0}')
|
||||
|
||||
|
||||
CHSSID=$(echo "$CHENTRY" | awk -F "[ ]{2,}" '{print $2}')
|
||||
|
||||
# If the user inputs "manual" as their SSID in the start window, it will bring them to this screen
|
||||
if [ "$CHENTRY" = "manual" ] ; then
|
||||
# Manual entry of the SSID and password (if appplicable)
|
||||
MSSID=$(echo "enter the SSID of the network (SSID,password)" | wofi --dmenu -p "Manual Entry: ")
|
||||
# Separating the password from the entered string
|
||||
MPASS=$(echo "$MSSID" | awk -F "," '{print $2}')
|
||||
|
||||
# If the user entered a manual password, then use the password nmcli command
|
||||
if [ "$MPASS" = "" ]; then
|
||||
nmcli dev wifi con "$MSSID"
|
||||
else
|
||||
nmcli dev wifi con "$MSSID" password "$MPASS"
|
||||
fi
|
||||
|
||||
elif [ "$CHENTRY" = "toggle on" ]; then
|
||||
nmcli radio wifi on
|
||||
|
||||
elif [ "$CHENTRY" = "toggle off" ]; then
|
||||
nmcli radio wifi off
|
||||
|
||||
else
|
||||
|
||||
# If the connection is already in use, then this will still be able to get the SSID
|
||||
if [ "$CHSSID" = "*" ]; then
|
||||
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $3}')
|
||||
fi
|
||||
|
||||
# Parses the list of preconfigured connections to see if it already contains the chosen SSID. This speeds up the connection process
|
||||
|
||||
if [[ $(echo "$KNOWNCON" | grep -w "$CHSSID") = "$CHSSID" ]]; then
|
||||
nmcli con up "$CHSSID"
|
||||
else
|
||||
nmcli dev wifi con "$CHSSID"
|
||||
fi
|
||||
|
||||
fi
|
41
configs/wofi/style.css
Normal file
41
configs/wofi/style.css
Normal file
@ -0,0 +1,41 @@
|
||||
/* https://cloudninja.pw/docs/wofi.html */
|
||||
window {
|
||||
/* border: solid 1px white; */
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
#input {
|
||||
border: none;
|
||||
border-radius: 0px;
|
||||
background-color: white;
|
||||
color: black;
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#img {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
|
||||
#outer-box {
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
#scroll {
|
||||
margin: 5px 0px;
|
||||
font-size: 16px;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
#scroll label {
|
||||
margin: 2px 0px;
|
||||
}
|
||||
|
||||
#entry:selected{
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#text:selected{
|
||||
color: black;
|
||||
}
|
25
configs/wofi/sway-select-window.sh
Executable file
25
configs/wofi/sway-select-window.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
swaymsg -t get_tree | jq -r '
|
||||
# descend to workspace or scratchpad
|
||||
.nodes[].nodes[]
|
||||
# save workspace name as .w
|
||||
| {"w": .name} + (
|
||||
if .nodes then # workspace
|
||||
[recurse(.nodes[])]
|
||||
else # scratchpad
|
||||
[]
|
||||
end
|
||||
+ .floating_nodes
|
||||
| .[]
|
||||
# select nodes with no children (windows)
|
||||
| select(.nodes==[])
|
||||
)
|
||||
| ((.id | tostring) + "\t "
|
||||
# remove markup and index from workspace name, replace scratch with "[S]"
|
||||
+ (.w | gsub("^[^:]*:|<[^>]*>"; "") | sub("__i3_scratch"; "[S]"))
|
||||
+ "\t " + .name)
|
||||
' | wofi --show dmenu -Ddynamic-lines=true --prompt=0 | {
|
||||
read -r id name
|
||||
swaymsg "[con_id=$id]" focus
|
||||
}
|
122
configs/wofi/swytcher.sh
Executable file
122
configs/wofi/swytcher.sh
Executable file
@ -0,0 +1,122 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Swytch is a script providing a window switcher for sway using rofi, awk and jq.
|
||||
# The script is based on:
|
||||
# https://www.reddit.com/r/swaywm/comments/aolf3u/quick_script_for_rofi_alttabbing_window_switcher/
|
||||
# Copyright (C) 2019 Björn Sonnenschein
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
# todo: first, query all existing workspaces from sway and build color dict, so that
|
||||
# all workspaces always get the same color, even if no windows at some workspace in between exists.
|
||||
|
||||
# obtain command to execute with swaymsg for selected window
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
command_=focus
|
||||
else
|
||||
command_=$1
|
||||
fi
|
||||
|
||||
# Obtain the avaliable windows' workspaces, names and IDs as strings
|
||||
mapfile -t windows < <(
|
||||
swaymsg -t get_tree | jq -r '[
|
||||
recurse(.nodes[]?)
|
||||
|recurse(.floating_nodes[]?)
|
||||
|select(.type=="workspace")
|
||||
| . as $workspace | recurse(.nodes[]?)
|
||||
|select(.type=="con" and .name!=null)
|
||||
|{workspace: $workspace.name, name: .name, id: .id, focused: .focused, app_id: .app_id}]
|
||||
|sort_by(.workspace, .name)[]
|
||||
|.workspace + if .focused then "* " else " " end + .app_id + " - " + .name + " " + (.id|tostring)'
|
||||
)
|
||||
rm $HOME/.cache/wofi-dmenu
|
||||
|
||||
windows_separators=()
|
||||
colors=(blue green orange red magenta)
|
||||
workspace_previous=''
|
||||
index_workspace_active=0
|
||||
num_separators=0
|
||||
index_color=0
|
||||
bold=-1
|
||||
for index_window in "${!windows[@]}"
|
||||
do
|
||||
window="${windows[$index_window]}"
|
||||
# todo: consider arbitraty workspace name length by separating by space instead of simply taking first argument.
|
||||
workspace=${window:0:1}
|
||||
# obtain index of the active window
|
||||
if [ "${window:1:1}" == "*" ]
|
||||
then
|
||||
index_workspace_active=$(($index_window))
|
||||
fi
|
||||
|
||||
# if window has different workspace than previous, use next color. Cycle through colors
|
||||
if [ "$workspace" != "$workspace_previous" ] && [ ! -z "$workspace_previous" ]
|
||||
then
|
||||
index_color=$index_color+1
|
||||
fi
|
||||
|
||||
if (($index_color == ${#colors[@]}))
|
||||
then
|
||||
index_color=0
|
||||
fi
|
||||
if (( $bold == 1))
|
||||
then
|
||||
windows_separators+=("<b><span foreground=\"${colors[$index_color]}\">[${workspace}]</span>${window:1}</b>")
|
||||
else
|
||||
windows_separators+=("<span foreground=\"${colors[$index_color]}\">[${workspace}]</span>${window:1}")
|
||||
fi
|
||||
workspace_previous=$workspace
|
||||
done
|
||||
|
||||
HEIGHT=$(( $(printf '%s\n' "${windows_separators[@]}" | wc -l) * 30 ))
|
||||
|
||||
echo $HEIGHT
|
||||
# Select window with rofi, obtaining ID of selected window
|
||||
idx_selected=$(printf '%s\n' "${windows_separators[@]}" | wofi -d -p "$command_" -m -H $HEIGHT )
|
||||
selected=${windows[$idx_selected]}
|
||||
id_selected=$(echo $selected | awk '{print $NF}')
|
||||
workspace_selected=${selected:0:1}
|
||||
|
||||
|
||||
### unmaximize all maximized windows on the workspace of the selected window
|
||||
# Obtain the avaliable windows' workspaces, names and IDs as strings
|
||||
mapfile -t ids_windows_maximized < <(
|
||||
swaymsg -t get_tree | jq -r '[
|
||||
recurse(.nodes[]?)
|
||||
|recurse(.floating_nodes[]?)
|
||||
|select(.type=="workspace")
|
||||
| . as $workspace | recurse(.nodes[]?)
|
||||
|select(.type=="con" and .name!=null and .fullscreen_mode==1 and $workspace.name=="'"$workspace_selected"'")
|
||||
|{workspace: $workspace.name, name: .name, id: .id, focused: .focused, app_id: .app_id}]
|
||||
|sort_by(.workspace, .name)[]
|
||||
|(.id|tostring)'
|
||||
)
|
||||
|
||||
# unmaximize the maximized windows that are not the selected one
|
||||
for id_window_maximized in "${ids_windows_maximized[@]}"
|
||||
do
|
||||
if [ "$id_window_maximized" != "$id_selected" ]
|
||||
then
|
||||
swaymsg "[con_id=$id_window_maximized] fullscreen disable"
|
||||
fi
|
||||
done
|
||||
|
||||
# Tell sway to focus said window
|
||||
# todo: do not execute if selected is the separator
|
||||
if [ ! -z "$id_selected" ]
|
||||
then
|
||||
swaymsg "[con_id=$id_selected] $command_"
|
||||
fi
|
33
configs/wofi/web-search.sh
Executable file
33
configs/wofi/web-search.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Info:
|
||||
# author: Miroslav Vidovic
|
||||
# file: web-search.sh
|
||||
# created: 24.02.2017.-08:59:54
|
||||
# revision: ---
|
||||
# version: 1.0
|
||||
# -----------------------------------------------------------------------------
|
||||
# Requirements:
|
||||
# rofi
|
||||
# Description:
|
||||
# Use rofi to search the web.
|
||||
# Usage:
|
||||
# web-search.sh
|
||||
# -----------------------------------------------------------------------------
|
||||
# Script:
|
||||
|
||||
|
||||
searx="https://searx.tiekoetter.com/search?language=en&time_range=None&safesearch=0&categories=general&q="
|
||||
startpage="https://www.startpage.com/sp/search?q="
|
||||
|
||||
query=$( wofi -d -p "Search: " -W 600 -H 100 -k ~/.cache/wofi-web)
|
||||
|
||||
if [[ -n "$query" ]]; then
|
||||
url="$startpage$query"
|
||||
xdg-open "$url"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
|
||||
exit 0
|
16
configs/wofi/wofi-power-menu.sh
Executable file
16
configs/wofi/wofi-power-menu.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
entries="⏻ Shutdown\n⭮ Reboot\n⇠ Logout\n⏾ Suspend"
|
||||
|
||||
selected=$(echo -e $entries|wofi --width 250 --height 210 --dmenu --cache-file /dev/null | awk '{print tolower($2)}')
|
||||
|
||||
case $selected in
|
||||
logout)
|
||||
swaymsg exit;;
|
||||
suspend)
|
||||
exec systemctl suspend;;
|
||||
reboot)
|
||||
exec systemctl reboot;;
|
||||
shutdown)
|
||||
exec systemctl poweroff -i;;
|
||||
esac
|
Reference in New Issue
Block a user