chore: cleanup

This commit is contained in:
2022-05-04 18:55:48 +02:00
parent 7acbafb7fe
commit 29eed372ff
36 changed files with 172 additions and 1138 deletions

View File

@ -4,3 +4,4 @@ width=500
dynamic_lines=true
term=kitty
insensitive=true
layer=overlay

View File

@ -1,8 +1,8 @@
#!/bin/bash
entries="⏻ Shutdown\n Reboot\n⇠ Logout\n⏾ Suspend"
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)}')
selected=$(echo -e $entries|wofi --width 250 --height 150 --dmenu --cache-file /dev/null | awk '{print tolower($2)}')
case $selected in
logout)

View File

@ -1,25 +0,0 @@
#!/usr/bin/env bash
swaymsg -t get_tree | jq -r '
# descend to workspace or scratchpad
.nodes[].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| {
read -r id name
swaymsg "[con_id=$id]" focus
}

View File

@ -1,122 +0,0 @@
#!/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

View File

@ -1,3 +0,0 @@
#!/bin/bash
rofimoji

View File

@ -1,138 +0,0 @@
#!/usr/bin/env bash
# Source: https://gist.github.com/NearHuscarl/5d366e1a3b788814bcbea62c1f66241d
#
# Use wofi to pick emoji because that's what this
# century is about apparently...
#
# Requirements:
# wofi, wlroots based compositor
#
# Usage:
# 1. Download all emoji
# $ wofi-emoji --download
#
# 2. Run it!
# $ wofi-emoji
#
# Notes:
# * You'll need a emoji font like "Noto Emoji" or "EmojiOne".
# * Confirming an item will automatically paste it WITHOUT
# writing it to your clipboard.
# * Ctrl+C will copy it to your clipboard WITHOUT pasting it.
#
# Where to save the emojis file.
EMOJI_FILE="$HOME/.cache/emojis.txt"
# Urls of emoji to download.
# You can remove what you don't need.
URLS=(
'https://emojipedia.org/people/'
'https://emojipedia.org/nature/'
'https://emojipedia.org/food-drink/'
'https://emojipedia.org/activity/'
'https://emojipedia.org/travel-places/'
'https://emojipedia.org/objects/'
'https://emojipedia.org/symbols/'
'https://emojipedia.org/flags/'
)
function notify() {
if [ "$(command -v notify-send)" ]; then
notify-send "$1" "$2"
fi
}
function download() {
notify "$(basename "$0")" 'Downloading all emoji for your pleasure'
echo "" > "$EMOJI_FILE"
for url in "${URLS[@]}"; do
echo "Downloading: $url"
# Download the list of emoji and remove all the junk around it
emojis=$(curl -s "$url" | \
xmllint --html \
--xpath '//ul[@class="emoji-list"]' - 2>/dev/null)
# Get rid of starting/closing ul tags
emojis=$(echo "$emojis" | head -n -1 | tail -n +1)
# Extract the emoji and its description
emojis=$(echo "$emojis" | \
sed -rn 's/.*<span class="emoji">(.*)<\/span> (.*)<\/a><\/li>/\1 \2/p')
echo "$emojis" >> "$EMOJI_FILE"
done
notify "$(basename "$0")" "We're all set!"
}
function wofi_menu() { # {{{
wofi -width 25 -lines 7 -dmenu -i -p 'emoji: ' \
-kb-row-tab '' \
-kb-row-select Tab \
-kb-custom-1 Ctrl+c
}
# }}}
function repeat() { # {{{
local rplc str="$1" count="$2"
rplc="$(printf "%${count}s")"
echo "${rplc// /"$str"}"
}
# }}}
function toclipboard() { # {{{
wl-copy
}
# }}}
function pastedirectly() { #{{{
wtype -
}
# }}}
function display() {
local emoji line exit_code quantifier
emoji=$(cat "$EMOJI_FILE" | grep -v '#' | grep -v '^[[:space:]]*$')
line="$(echo "$emoji" | wofi_menu)"
exit_code=$?
line=($line)
last=${line[${#line[@]}-1]}
quantifier="${last:${#last}-1:1}"
if [[ ! "$quantifier" =~ [0-9] ]]; then
quantifier=1
fi
emoijs="$(repeat "${line[0]}" "$quantifier")"
if [ $exit_code == 0 ]; then
echo -n "$emoijs" | pastedirectly
elif [ $exit_code == 10 ]; then
echo -n "$emoijs" | toclipboard
fi
}
# Some simple argparsing
if [[ "$1" =~ -D|--download ]]; then
download
exit 0
elif [[ "$1" =~ -h|--help ]]; then
echo "usage: $0 [-D|--download]"
exit 0
fi
# Download all emoji if they don't exist yet
if [ ! -f "$EMOJI_FILE" ]; then
download
fi
# display displays :)
display