Add more utility stuff

main
Julius Riegel 6 months ago
parent f04dd75bc6
commit 55100c37da

@ -2,7 +2,7 @@ theme = "dracula-purple"
[editor] [editor]
rulers = [120] rulers = [120]
shell = ["nu", "--stdin", "-c"] shell = ["nu", "--stdin", "--no-newline", "-c"]
true-color = true true-color = true
cursorline = true cursorline = true
color-modes = true color-modes = true
@ -39,11 +39,17 @@ nbsp = "all"
esc = ["collapse_selection", "keep_primary_selection"] esc = ["collapse_selection", "keep_primary_selection"]
C-j = ["half_page_down", "goto_window_center", "align_view_center"] C-j = ["half_page_down", "goto_window_center", "align_view_center"]
C-k = ["half_page_up", "goto_window_center", "align_view_center"] C-k = ["half_page_up", "goto_window_center", "align_view_center"]
A-w = [":sh use ide.nu; ide write-here miw"]
A-W = [":sh use ide.nu; ide write-here miW"]
D = [":sh use ide.nu; ide write-here \"2y%d\"2p"]
[keys.select] [keys.select]
esc = ["collapse_selection", "keep_primary_selection", "normal_mode"] esc = ["collapse_selection", "keep_primary_selection", "normal_mode"]
C-j = ["half_page_down", "goto_window_center"] C-j = ["half_page_down", "goto_window_center"]
C-k = ["half_page_up", "goto_window_center"] C-k = ["half_page_up", "goto_window_center"]
A-w = [":sh use ide.nu; ide write-here miw"]
A-W = [":sh use ide.nu; ide write-here miW"]
D = [":sh use ide.nu; ide write-here \"9y%d\"9p"]
[keys.normal."A-/"] [keys.normal."A-/"]
j = ["goto_line_start", ":insert-output use ide.nu; ide doc-comment java-style", ":format", "normal_mode", "move_visual_line_up", "insert_at_line_end"] j = ["goto_line_start", ":insert-output use ide.nu; ide doc-comment java-style", ":format", "normal_mode", "move_visual_line_up", "insert_at_line_end"]

@ -80,6 +80,10 @@ export def `doc-comment rust-style` [] {
print `/// ` print `/// `
} }
export def write-here [...chars: string] {
zellij ac write-chars ...$chars
}
def open-editor [path: string] { def open-editor [path: string] {
zellij ac move-focus right zellij ac move-focus right
zellij ac write-chars $":open ($path)\r" zellij ac write-chars $":open ($path)\r"

@ -70,3 +70,29 @@ export def --env dotenv [file=".env"] {
| load-env $in | load-env $in
) )
} }
export def brute-force [
closure: closure, # closure to execute
--delay(-d): duration = 1sec, # delay between trys
--max-trys: number # maximum number of trys. Default unlimited
--print-errors, # print errors to stderr
] {
mut count = 0;
loop {
$count += 1
let iteration = $count
try {
return (do -c $closure)
} catch {|e|
if $print_errors {
print -e $e.msg
}
if $max_trys != null and $iteration >= $max_trys {
error make $e
}
sleep $delay
}
}
}

@ -0,0 +1,140 @@
#!/bin/bash
# Usage: ww -f "window class filter" -c "run if not found"
# Usage: ww -fa "window title filter" -c "run if not found"
TOGGLE="false"
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-c | --command)
COMMAND="$2"
shift # past argument
shift # past value
;;
-f | --filter)
FILTERBY="$2"
shift # past argument
shift # past value
;;
-fa | --filter-alternative)
FILTERALT="$2"
shift # past argument
shift # past value
;;
-t | --toggle)
TOGGLE="true"
shift # past argument
;;
-h | --help)
HELP="1"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ -n "$HELP" ]; then
cat << EOF
ww. Utility to raise or jump an applications in KDE. It interacts with KWin using KWin scripts and it is compatible with X11 and Wayland
Paramaters:
-h --help show this help
-f --filter filter by window class
-fa --filter-alternative filter by window title (caption)
-t --toggle also minimize the window if it is already active
-c --command command to check if running and run if no process is found
EOF
exit 0
fi
SCRIPT_TEMPLATE=$(
cat << EOF
function kwinactivateclient(clientClass, clientCaption, toggle) {
var clients = workspace.clientList();
var compareToCaption = new RegExp(clientCaption || '', 'i');
var compareToClass = clientClass;
var isCompareToClass = clientClass.length > 0
for (var i=0; i<clients.length; i++) {
var client = clients[i];
var classCompare = (isCompareToClass && client.resourceClass == compareToClass)
var captionCompare = (!isCompareToClass && compareToCaption.exec(client.caption))
if (classCompare || captionCompare) {
if (workspace.activeClient != client) {
workspace.activeClient = client;
} else if (toggle) {
client.minimized = true;
}
break;
}
}
}
kwinactivateclient('CLASS_NAME', 'CAPTION_NAME', TOGGLE);
EOF
)
CURRENT_SCRIPT_NAME=$(basename "$0")
# ensure the script file exists
function ensure_script {
if [ ! -f SCRIPT_PATH ]; then
if [ ! -d "$SCRIPT_FOLDER" ]; then
mkdir -p "$SCRIPT_FOLDER"
fi
SCRIPT_CONTENT=${SCRIPT_TEMPLATE/CLASS_NAME/$1}
SCRIPT_CONTENT=${SCRIPT_CONTENT/CAPTION_NAME/$2}
SCRIPT_CONTENT=${SCRIPT_CONTENT/TOGGLE/$3}
#if [ "$1" == "class" ]; then
#SCRIPT_CONTENT=${SCRIPT_CLASS_NAME/REPLACE_ME/$2}
#else
#SCRIPT_CONTENT=${SCRIPT_CAPTION/REPLACE_ME/$2}
#fi
echo "$SCRIPT_CONTENT" > "$SCRIPT_PATH"
fi
}
if [ -z "$FILTERBY" ] && [ -z "$FILTERALT" ]; then
echo You need to specify a window filter. Either by class -f or by title -fa
exit 1
fi
IS_RUNNING=$(pgrep -o -a -f "$COMMAND" | grep -v "$CURRENT_SCRIPT_NAME")
if [ -n "$IS_RUNNING" ] || [ -n "$FILTERALT" ]; then
# trying for XDG_CONFIG_HOME first
SCRIPT_FOLDER_ROOT=$XDG_CONFIG_HOME
if [[ -z $SCRIPT_FOLDER_ROOT ]]; then
# fallback to the home folder
SCRIPT_FOLDER_ROOT=$HOME
fi
SCRIPT_FOLDER="$SCRIPT_FOLDER_ROOT/.wwscripts/"
SCRIPT_NAME=$(echo "$FILTERBY$FILTERALT" | md5sum | head -c 32)
SCRIPT_PATH="$SCRIPT_FOLDER$SCRIPT_NAME"
ensure_script "$FILTERBY" "$FILTERALT" "$TOGGLE"
SCRIPT_NAME="ww$RANDOM"
#SCRIPT_NAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# install the script
ID=$(dbus-send --session --dest=org.kde.KWin --print-reply=literal /Scripting org.kde.kwin.Scripting.loadScript "string:$SCRIPT_PATH" "string:$SCRIPT_NAME" | awk '{print $2}')
# run it - some KDEs version use Script.run others Scripting.run
dbus-send --session --dest=org.kde.KWin --print-reply=literal "/$ID" org.kde.kwin.Scripting.run > /dev/null 2>&1
dbus-send --session --dest=org.kde.KWin --print-reply=literal "/$ID" org.kde.kwin.Script.run > /dev/null 2>&1
# stop it - some KDEs version use Script.run others Scripting.run
dbus-send --session --dest=org.kde.KWin --print-reply=literal "/$ID" org.kde.kwin.Scripting.stop > /dev/null 2>&1
dbus-send --session --dest=org.kde.KWin --print-reply=literal "/$ID" org.kde.kwin.Script.stop > /dev/null 2>&1
# uninstall it
dbus-send --session --dest=org.kde.KWin --print-reply=literal /Scripting org.kde.kwin.Scripting.unloadScript "string:$SCRIPT_NAME" > /dev/null 2>&1
elif [ -n "$COMMAND" ]; then
$COMMAND &
fi

@ -66,6 +66,7 @@ config.modules = {
'plantuml', 'plantuml',
'websocat', 'websocat',
'pandoc', 'pandoc',
'anyrun',
}, },
gui = mod { gui = mod {
'kdePackages.breeze-icons', 'kdePackages.breeze-icons',

Loading…
Cancel
Save