Compare commits

...

16 Commits

Author SHA1 Message Date
33b541dbd8 update 2025-12-07 21:45:34 -08:00
a93761b042 update 2025-12-04 22:42:27 -08:00
a1ec1a54ba update 2025-12-03 22:49:24 -08:00
kyasuda
7b7fae9b91 update 2025-12-03 14:12:00 -08:00
d8a0e95bb5 bump versions 2025-12-02 18:49:10 -08:00
154f9e3ea6 update 2025-12-02 18:48:58 -08:00
4983623860 update mpv config 2025-12-02 18:48:51 -08:00
3628e70b72 update 2025-12-01 18:40:58 -08:00
31cfb8dd1c fux docs script 2025-12-01 18:09:32 -08:00
3fc0b32a9d update 2025-11-30 22:58:47 -08:00
4005e4650e move float center window rule down 2025-11-30 22:58:39 -08:00
3b87c06731 update rofi scripts 2025-11-30 22:57:56 -08:00
099d5e8ba6 update 2025-11-30 12:25:38 -08:00
21d6320cc1 update to new monitor 2025-11-30 12:25:25 -08:00
kyasuda
cb3641a9d9 send input directly to codecompanion inline command 2025-11-25 09:32:26 -08:00
b2cda94362 update window rules to new format 2025-11-20 12:26:07 -08:00
18 changed files with 518 additions and 300 deletions

View File

@@ -14,10 +14,32 @@
################
# See https://wiki.hyprland.org/Configuring/Monitors/
monitor=DP-1,2560x1440@144,0x0,1
monitor=DP-3,2560x1440@144,2560x0,1
# monitor=DP-1,2560x1440@144,0x0,1
# monitor=DP-3,2560x1440@144,2560x0,1
# vrr 2 enables vrr if application is fullscreen
# vrr 3 enables vrr if application is fullscreen and video or game content
# monitor = DP-1, 3440x1440@240,0x0,1,vrr,3
monitorv2 {
output = DP-1
mode = 3440x1440@240
position = 0x0
scale = 1
vrr = 2
cm = srgb
# Optional HDR settings
# cm = hdr
# bitdepth = 10
# sdr_min_luminance = 0.005
# sdr_max_luminance = 200
# min_luminance = 0
# max_luminance = 1000
# max_avg_luminance = 200
# sdrbrightness = 1.2
# sdrsaturation = 0.98
}
source = ~/.config/hypr/keybindings.conf
source = ~/.config/hypr/windowrules.conf
source = ~/.config/hypr/macchiato.conf
# unscale XWayland
@@ -46,8 +68,8 @@ $notification_daemon = uwsm app -- swaync -c ~/.config/swaync/config.json
# Autostart necessary processes (like notifications daemons, status bars, etc.)
# Or execute your favorite apps at launch like this:
exec-once = uwsm app -sb -- hyprpm update -nn
exec-once = uwsm app -sb -- hyprpm reload -nn
exec-once = uwsm app -sb -- hyprpm update -n
exec-once = uwsm app -sb -- hyprpm reload -n
exec-once = $notification_daemon
exec-once = $terminal
exec-once = uwsm app -sb -S both -t scope -- hyprpm update -nn
@@ -166,10 +188,6 @@ animations {
# uncomment all if you wish to use that.
# workspace = w[tv1], gapsout:0, gapsin:0
# workspace = f[1], gapsout:0, gapsin:0
# windowrulev2 = bordersize 0, floating:0, onworkspace:w[tv1]
# windowrulev2 = rounding 0, floating:0, onworkspace:w[tv1]
# windowrulev2 = bordersize 0, floating:0, onworkspace:f[1]
# windowrulev2 = rounding 0, floating:0, onworkspace:f[1]
# See https://wiki.hyprland.org/Configuring/Dwindle-Layout/ for more
dwindle {
@@ -230,7 +248,8 @@ misc {
font_family = JetBrainsMono Nerd Font
}
# {{{ WORKSPACES
# {{{ WORKSPACES - HANDLED IN WAYBAR CONFIG
# See https://wiki.hyprland.org/Configuring/Window-Rules/ for more
# workspace = name:,monitor:DP-1
# workspace = 2,monitor:DP-1,defaultName:
# workspace = 2,monitor:DP-1,persistent:false
@@ -244,66 +263,9 @@ misc {
# workspace = 10,monitor:DP-3,persistent:false
# }}}
# windowrule = match:class my-window, border_size 10
##############################
### WINDOWS AND WORKSPACES ###
##############################
# See https://wiki.hyprland.org/Configuring/Window-Rules/ for more
# See https://wiki.hyprland.org/Configuring/Workspace-Rules/ for workspace rules
# Example windowrule v1
# windowrulev2 = float, class:com.mitchellh.ghostty
windowrule = float, class:discord
windowrule = float, class:mpv
windowrule = float, class:steam
windowrule = float, class:anki
windowrule = float, class:python, title:Import
windowrule = workspace 10 silent, class:discord
windowrule = workspace 9 silent, class:steam
windowrule = size 2118 1182, class:anki
windowrule = workspace 8 silent, class:anki
# windowrule = opacity 0.88, class:.* fullscreen:0
windowrule = opacity 1.0 override, class:mpv
windowrule = opacity 1.0 override, title:(.*)asbplayer
windowrule = tile, title:(.*)asbplayer
windowrule = opacity 1.0 override, class:^(remote-viewer)$
windowrule = opacity 1.0 override, class:com.obsproject.Studio
windowrule = opacity 1.0 override, title:(.*)(- YouTube(.*))
windowrule = opacity 1.0 override, class:zen, title:(.*)YouTube TV(.*)
windowrule = opacity 1.0 override, class:anki
# Example windowrule v2
# windowrulev2 = float,class:^(kitty)$,title:^(kitty)$
# Ignore maximize requests from apps. You'll probably like this.
windowrule = suppressevent maximize, class:.*
# Fix some dragging issues with XWayland
windowrule = nofocus,class:^$,title:^$,xwayland:1,floating:1,fullscreen:0,pinned:0
# https://github.com/hyprwm/Hyprland/issues/3835#issuecomment-2004448245
windowrule = suppressevent maximize, class:^(zen)$
exec-once = $HOME/.local/bin/bitwarden-nofloat.sh
# ENABLE_HDR_WSI=1 mpv --vo=gpu-next --target-colorspace-hint --gpu-api=vulkan --gpu-context=waylandvk "filename"
# {{{ Screen sharing workaround: https://wiki.hyprland.org/Useful-Utilities/Screen-Sharing/#xwayland
windowrule = opacity 0.0 override, class:^(xwaylandvideobridge)$
windowrule = noanim, class:^(xwaylandvideobridge)$
windowrule = noinitialfocus, class:^(xwaylandvideobridge)$
windowrule = maxsize 1 1, class:^(xwaylandvideobridge)$
windowrule = noblur, class:^(xwaylandvideobridge)$
windowrule = nofocus, class:^(xwaylandvideobridge)$
# }}}
plugin {
split-monitor-workspaces {
count = 5
keep_focused = 1
enable_notifications = 1
enable_persistent_workspaces = 1
}
debug {
disable_logs = true
enable_stdout_logs = false
}

View File

@@ -40,28 +40,28 @@ bind = CTRL+ALT, j, focusmonitor, r
bind = CTRL+ALT, k, focusmonitor, l
# Switch workspaces with mainMod + [0-9]
bind = $mainMod, 1, split-workspace, 1
bind = $mainMod, 2, split-workspace, 2
bind = $mainMod, 3, split-workspace, 3
bind = $mainMod, 4, split-workspace, 4
bind = $mainMod, 5, split-workspace, 5
bind = $mainMod, 6, split-workspace, 6
bind = $mainMod, 7, split-workspace, 7
bind = $mainMod, 8, split-workspace, 8
bind = $mainMod, 9, split-workspace, 9
bind = $mainMod, 0, split-workspace, 10
bind = $mainMod, 1, workspace, 1
bind = $mainMod, 2, workspace, 2
bind = $mainMod, 3, workspace, 3
bind = $mainMod, 4, workspace, 4
bind = $mainMod, 5, workspace, 5
bind = $mainMod, 6, workspace, 6
bind = $mainMod, 7, workspace, 7
bind = $mainMod, 8, workspace, 8
bind = $mainMod, 9, workspace, 9
bind = $mainMod, 0, workspace, 10
# Move active window to a workspace with mainMod + SHIFT + [0-9]
bind = $mainMod SHIFT, 1, split-movetoworkspacesilent, 1
bind = $mainMod SHIFT, 2, split-movetoworkspacesilent, 2
bind = $mainMod SHIFT, 3, split-movetoworkspacesilent, 3
bind = $mainMod SHIFT, 4, split-movetoworkspacesilent, 4
bind = $mainMod SHIFT, 5, split-movetoworkspacesilent, 5
bind = $mainMod SHIFT, 6, split-movetoworkspacesilent, 6
bind = $mainMod SHIFT, 7, split-movetoworkspacesilent, 7
bind = $mainMod SHIFT, 8, split-movetoworkspacesilent, 8
bind = $mainMod SHIFT, 9, split-movetoworkspacesilent, 9
bind = $mainMod SHIFT, 0, split-movetoworkspacesilent, 10
bind = $mainMod SHIFT, 1, movetoworkspacesilent, 1
bind = $mainMod SHIFT, 2, movetoworkspacesilent, 2
bind = $mainMod SHIFT, 3, movetoworkspacesilent, 3
bind = $mainMod SHIFT, 4, movetoworkspacesilent, 4
bind = $mainMod SHIFT, 5, movetoworkspacesilent, 5
bind = $mainMod SHIFT, 6, movetoworkspacesilent, 6
bind = $mainMod SHIFT, 7, movetoworkspacesilent, 7
bind = $mainMod SHIFT, 8, movetoworkspacesilent, 8
bind = $mainMod SHIFT, 9, movetoworkspacesilent, 9
bind = $mainMod SHIFT, 0, movetoworkspacesilent, 10
# Example special workspace (scratchpad)
bind = SUPER, S, togglespecialworkspace, magic
@@ -137,3 +137,7 @@ bind = $mainMod, code:117, submap, clean
submap = clean
bind = $mainMod, code:112, submap, reset
submap = reset
bind = SUPER, l, exec, hyprlock
bind = $mainMod SHIFT, a, exec, ~/.config/rofi/scripts/rofi-anki-script.sh

View File

@@ -25,7 +25,7 @@ sub-fix-timing=yes
sub-ass-override=scale
sub-gauss=1.0
sub-gray=yes
sub-pos=90
sub-pos=100
# --- Audio chain ---
volume=75
@@ -154,9 +154,11 @@ ytdl-raw-options-append=sponsorblock-mark=all
ytdl-raw-options-append=sponsorblock-remove=sponsor,selfpromo,interaction
ytdl-format=bestvideo+bestaudio/best
sub-auto=fuzzy
slang=ja,jpn
alang=ja,jpn
alang=ja,jp,jpn,japanese,en,eng,english,English,enUS,en-US
slang=ja,jp,jpn,japanese,en,eng,english,English,enUS,en-US
vlang=ja,jpn
subs-with-matching-audio=yes
sub-font="Noto Sans CJK JP Regular"
glsl-shaders="~~/shaders/ArtCNN_C4F32.glsl"
scale=ewa_lanczossharp
dither=error-diffusion
@@ -164,7 +166,7 @@ deband=yes # Crucial for anime gradients
[anime-subs]
profile-cond=p["slang"] == "ja" or p["slang"] == "ja.hi"
sub-font="Noto Sans CJK JP"
sub-font="Noto Sans CJK JP Regular"
sub-font-size=42
sub-border-size=1.2
sub-shadow-color=0.0/0.0/0.0/0.6

View File

@@ -186,14 +186,15 @@ ytdl-raw-options-append=sponsorblock-mark=all
ytdl-raw-options-append=sponsorblock-remove=sponsor
ytdl-format=bestvideo+bestaudio/best
sub-auto=fuzzy
slang=ja,jpn,ja.hi,ja.*
alang=ja,jpn
alang=ja,jp,jpn,japanese,en,eng,english,English,enUS,en-US
slang=ja,jp,jpn,japanese,en,eng,english,English,enUS,en-US
vlang=ja,jpn
sub-font="Noto Sans CJK JP"
sub-font-size=42
sub-border-size=1.2
sub-shadow-color=0.0/0.0/0.0/0.6
sub-shadow-offset=3
subs-with-matching-audio=yes
sub-font="Noto Sans CJK JP Regular"
glsl-shaders="~~/shaders/ArtCNN_C4F32.glsl"
scale=ewa_lanczossharp
dither=error-diffusion
deband=yes # Crucial for anime gradients
# Anime subtitles profile
[anime-subs]

View File

@@ -239,7 +239,9 @@ local code_companion_mappings = {
{
mode = "n",
key = "<leader>Ci",
cmd = ":CodeCompanion #{buffer} ",
cmd = function()
vim.api.nvim_feedkeys(":CodeCompanion #{buffer} ", "n", false)
end,
group = "Inline CodeCompanion",
opts = nosilent,
},
@@ -249,7 +251,9 @@ local code_companion_mappings = {
{
mode = "v",
key = "<leader>Ci",
cmd = ":CodeCompanion #{buffer} ",
cmd = function()
vim.api.nvim_feedkeys(":CodeCompanion #{buffer} ", "n", false)
end,
group = "CodeCompanion Inline",
opts = nosilent,
},
@@ -432,6 +436,14 @@ local misc_utilities_mappings = {
end,
group = "mkdir under cursor",
},
{
mode = "v",
key = "<leader>m",
cmd = function()
mkdir_under_cursor()
end,
group = "mkdir selection",
},
}
-- }}}

View File

@@ -2,8 +2,20 @@ local M = {}
vim.notify = require("notify")
function M.mkdir_under_cursor()
-- Get the word under the cursor
local word = vim.fn.expand("<cWORD>")
local word
-- Check if in visual mode
if vim.fn.mode():match("[vV]") then
-- Get visual selection
local start_pos = vim.fn.getpos("'<")
local end_pos = vim.fn.getpos("'>")
local line = vim.fn.getline(start_pos[2])
word = line:sub(start_pos[3], end_pos[3])
else
-- Get word under cursor
word = vim.fn.expand("<cWORD>")
end
-- Remove quotes if present
word = word:gsub("^[\"']", ""):gsub("[\"']$", "")
-- Check if directory exists

View File

@@ -10,8 +10,10 @@
"Cloudflare - https://dash.cloudflare.com/",
"CoinMarketCap - https://coinmarketcap.com/",
"Deemix - http://pve-main:3358",
"Ephemera - https://ephemera.suda.codes",
"F1TV - https://f1tv.suda.codes",
"Fidelity - https://login.fidelity.com/",
"Ghstats - http://oracle-vm:3340",
"Gitea - https://gitea.suda.codes",
"Github - https://github.com",
"Ghostfolio - http://pve-main:3334",
@@ -23,7 +25,7 @@
"Jellyfin (Vue) - http://pve-main:8098",
"Karakeep - https://karakeep.suda.codes",
"Komodo - https://komodo.suda.codes",
"Komga - http://oracle-vm:3332",
"Komga - http://pve-main:3332",
"Lidarr - http://pve-main:3357",
"MeTube - https://metube.suda.codes",
"Navidrome - https://navidrome.suda.codes",
@@ -32,7 +34,8 @@
"Pihole - https://pihole.suda.codes/admin",
"Pihole2 - https://pihole2.suda.codes/admin",
"Proxmox - https://thebox.unicorn-ilish.ts.net",
"qBittorrent - https://qbit.suda.codes",
"qBittorrent - https://qbittorrent.suda.codes",
"qui - https://qui.suda.codes",
"Plausible - https://plausible.sudacode.com",
"Paperless - https://paperless.suda.codes",
"Prometheus - http://prometheus:9090",
@@ -42,6 +45,7 @@
"Sabnzbd - https://sabnzbd.suda.codes",
"Sonarr - https://sonarr.suda.codes",
"Sonarr Anime - http://pve-main:6969",
"Speedtest Tracker - http://pve-main:8765",
"Sudacode - https://sudacode.com",
"Suwayomi - https://suwayomi.suda.codes",
"Tailscale - https://login.tailscale.com/admin/machines",

View File

@@ -37,7 +37,7 @@ window {
location: center;
anchor: center;
fullscreen: false;
width: 45%;
width: 37%;
x-offset: 0px;
y-offset: 0px;

View File

@@ -1,20 +1,52 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/rofi-menu-helpers.sh"
BROWSER=/usr/bin/zen-browser
URLS=(
DOC_GROUPS=(
"Arch Linux (btw)|ARCH"
"Hyprland|HYPRLAND"
)
ARCH=(
"Archlinux Wiki|https://wiki.archlinux.org/title/Main_page"
)
HYPRLAND=(
"Hyprland Docs|https://wiki.hypr.land/"
"Hyprland Window Rules|https://wiki.hypr.land/Configuring/Window-Rules/"
)
DISPLAY_URLS=()
declare -A URL_MAP
for url in "${URLS[@]}"; do
DISPLAY_URLS+=("${url%%|*}")
label="${url%%|*}"
URL_MAP["$label"]="${url##*|}"
done
select_group() {
rofi_select_label_value "Select Documentation Group" DOC_GROUPS
}
SELECTION="$(printf "%s\n" "${DISPLAY_URLS[@]}" | rofi -theme-str 'window {width: 25%;} listview {columns: 1; lines: 10;}' -theme ~/.config/rofi/launchers/type-2/style-2.rasi -dmenu -l 5 -i -p "Select Documentation")"
URL="${URL_MAP[$SELECTION]}"
$BROWSER "$URL" &>/dev/null &
select_url() {
local urls_array="$1"
rofi_select_label_value "Select Documentation" "$urls_array" "Back"
}
main() {
while true; do
group_key="$(select_group)" || exit 0
case "$group_key" in
ARCH)
urls_ref=ARCH
;;
HYPRLAND)
urls_ref=HYPRLAND
;;
*)
exit 0
;;
esac
selection="$(select_url "$urls_ref")" || exit 0
if [[ "$selection" == "Back" ]]; then
continue
fi
$BROWSER "$selection" &>/dev/null &
exit 0
done
}
main

View File

@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# Lightweight helpers to build rofi menus with label/value pairs.
# Intended to be sourced from other scripts.
# Allow callers to override theme/args without touching code.
: "${ROFI_THEME:=$HOME/.config/rofi/launchers/type-2/style-2.rasi}"
: "${ROFI_THEME_STR:="window {width: 25%;} listview {columns: 1; lines: 10;}"}"
: "${ROFI_DMENU_ARGS:=-i -l 5}"
# rofi_menu prompt option...
# Prints the selected option to stdout and propagates the rofi exit code
# (1 when the user cancels).
rofi_menu() {
local prompt="$1"
shift
local -a options=("$@")
local selection
selection="$(printf "%s\n" "${options[@]}" | rofi -dmenu $ROFI_DMENU_ARGS \
${ROFI_THEME:+-theme "$ROFI_THEME"} \
${ROFI_THEME_STR:+-theme-str "$ROFI_THEME_STR"} \
-p "$prompt")"
local status=$?
[[ $status -ne 0 ]] && return "$status"
printf "%s\n" "$selection"
}
# rofi_select_label_value prompt array_name [back_label]
# array_name should contain entries shaped as "Label|Value".
# Prints the mapped value (or the back label when chosen). Returns 1 on cancel.
rofi_select_label_value() {
local prompt="$1"
local array_name="$2"
local back_label="${3:-}"
# Access caller's array by name
local -n kv_source="$array_name"
local -A kv_map=()
local -a display=()
for entry in "${kv_source[@]}"; do
local label="${entry%%|*}"
local value="${entry#*|}"
kv_map["$label"]="$value"
display+=("$label")
done
if [[ -n "$back_label" ]]; then
kv_map["$back_label"]="$back_label"
display+=("$back_label")
fi
local selection
selection="$(rofi_menu "$prompt" "${display[@]}")" || return "$?"
[[ -z "$selection" ]] && return 1
printf "%s\n" "${kv_map[$selection]}"
}
# rofi_select_list prompt array_name
# Convenience wrapper for plain lists (no label/value mapping).
rofi_select_list() {
local prompt="$1"
local array_name="$2"
local -n list_source="$array_name"
rofi_menu "$prompt" "${list_source[@]}"
}

View File

@@ -7,5 +7,7 @@ DIR="$HOME/Pictures/wallpapers/favorites"
SELECTED_WALL=$(cd "$DIR" && for a in *.jpg *.png; do echo -en "$a\0icon\x1f$a\n"; done | rofi -dmenu -i -no-custom -theme "$THEME" -p "Select a wallpaper" -theme-str 'configuration {icon-size: 128; dpi: 96;} window {width: 45%; height: 45%;}')
PTH="$(printf "%s" "$DIR/$SELECTED_WALL" | tr -s '/')"
notify-send -a "rofi-wallpaper" "Wallpaper set to" -i "$PTH" "$PTH"
hyprctl hyprpaper reload , "$DIR/$SELECTED_WALL"
echo "$PTH" > "$HOME/.wallpaper"
hyprctl hyprpaper preload "$PTH"
hyprctl hyprpaper wallpaper "DP-1,$PTH"
hyprctl hyprpaper unload "$(cat "$HOME/.wallpaper")"
echo "$PTH" >"$HOME/.wallpaper"

View File

@@ -2,7 +2,7 @@
"layer": "bottom",
"position": "top",
"height": 40,
"width": 2545,
"width": 3422,
"spacing": 1,
"reload_style_on_change": true,
"fixed-center": true,
@@ -232,8 +232,8 @@
// "20": "十",
},
"persistent-workspaces": {
// "*": 10,
"*": 5,
"*": 10,
// "*": 5,
},
"sort-by": "number",
"all-outputs": false,

View File

@@ -175,7 +175,7 @@ func downloadRandomWallpaper(wallpaperPath string, r *rand.Rand, topics []string
fmt.Fprintf(os.Stderr, "Searching for wallpapers related to: %s\n", displayName)
// Get wallpapers from Wallhaven API
resp, err := http.Get(fmt.Sprintf("%s/search?q=%s&purity=100&categories=110&sorting=random", wallhavenAPI, query))
resp, err := http.Get(fmt.Sprintf("%s/search?q=%s&purity=100&categories=110&sorting=random&atleast=3440x1440", wallhavenAPI, query))
if err != nil {
fmt.Fprintf(os.Stderr, "Error fetching from Wallhaven: %v\n", err)
return "", ""
@@ -272,11 +272,26 @@ func ensureSized(wallpaperPath string) (string, error) {
return "", err
}
if src.Bounds().Dx() == targetWidth && src.Bounds().Dy() == targetHeight {
srcWidth := float64(src.Bounds().Dx())
srcHeight := float64(src.Bounds().Dy())
targetW := float64(targetWidth)
targetH := float64(targetHeight)
// Calculate scale factor to fit image within target while maintaining aspect ratio
scaleW := targetW / srcWidth
scaleH := targetH / srcHeight
scale := min(scaleW, scaleH)
// If image already fits within target dimensions, no resize needed
if scale >= 1.0 {
return wallpaperPath, nil
}
dst := image.NewRGBA(image.Rect(0, 0, targetWidth, targetHeight))
// Calculate new dimensions maintaining aspect ratio (best fit)
newWidth := int(srcWidth * scale)
newHeight := int(srcHeight * scale)
dst := image.NewRGBA(image.Rect(0, 0, newWidth, newHeight))
draw.CatmullRom.Scale(dst, dst.Bounds(), src, src.Bounds(), draw.Over, nil)
var ext string
@@ -295,7 +310,7 @@ func ensureSized(wallpaperPath string) (string, error) {
}
base := strings.TrimSuffix(filepath.Base(wallpaperPath), filepath.Ext(wallpaperPath))
resizedPath := filepath.Join(filepath.Dir(wallpaperPath), fmt.Sprintf("%s-%dx%d%s", base, targetWidth, targetHeight, ext))
resizedPath := filepath.Join(filepath.Dir(wallpaperPath), fmt.Sprintf("%s-%dx%d%s", base, newWidth, newHeight, ext))
outFile, err := os.Create(resizedPath)
if err != nil {

226
projects/scripts/record-audio.sh Normal file → Executable file
View File

@@ -1,93 +1,145 @@
#!/bin/sh
#!/usr/bin/env bash
# Version 1.2
# shoutout to https://gist.github.com/Cephian/f849e326e3522be9a4386b60b85f2f23 for the original script,
# https://github.com/xythh/ added the ankiConnect functionality
# toggle record computer audio (run once to start, run again to stop)
# dependencies: ffmpeg, pulseaudio, curl
# Toggle desktop audio recording and attach the result to the newest Anki note
# (as tagged by Yomichan). Run once to start recording, run again to stop.
# Dependencies: jq, curl, ffmpeg/ffprobe, pulseaudio (parec+pactl), bc, notify-send
# where recording gets saved, gets deleted after being imported to anki
DIRECTORY="$HOME/.cache/"
FORMAT="mp3" # ogg or mp3
# cut file since it glitches a bit at the end sometimes
CUT_DURATION="0.1"
#port used by ankiconnect
ankiConnectPort="8765"
# gets the newest created card, so make sure to create the card first with yomichan
newestNoteId=$(curl -s localhost:$ankiConnectPort -X POST -d '{"action": "findNotes", "version": 6, "params": { "query": "is:new"}}' | jq '.result[-1]')
#Audio field name
audioFieldName="SentenceAudio"
set -euo pipefail
#if there is no newest note, you either have a complete empty anki or ankiconnect isn't running
if [ "$newestNoteId" = "" ]; then
notify-send "anki connect not found"
exit 1
fi
ANKI_CONNECT_PORT="${ANKI_CONNECT_PORT:-8765}"
AUDIO_FIELD_NAME="${AUDIO_FIELD_NAME:-SentenceAudio}"
FORMAT="${FORMAT:-mp3}" # mp3 or ogg
CUT_DURATION="${CUT_DURATION:-0.1}"
CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/record-audio"
RECORD_TIMEOUT="${RECORD_TIMEOUT:-60}"
ANKI_URL="http://localhost:${ANKI_CONNECT_PORT}"
if pgrep -f "parec"; then
pkill -f "parec"
else
time=$(date +%s)
name="$DIRECTORY/$time"
wav_file="$name.wav"
out_file="$name.$FORMAT"
if ! [ -d "$DIRECTORY" ]; then
mkdir "$DIRECTORY"
fi
notify-send -t 1000 "Audio recording started"
#timeout 1m arecord -t wav -f cd "$wav_file"
# just grabs last running source... may not always work if your pulseaudio setup is complicated
if ! timeout 1m parec -d"$(pactl list sinks | grep -B1 'State: RUNNING' | sed -nE 's/Sink #(.*)/\1/p' | tail -n 1)" --file-format=wav "$wav_file"; then
notify-send "Error recording " "most likely no audio playing"
rm "$wav_file"
exit 1
fi
input_duration=$(ffprobe -v error -select_streams a:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$wav_file")
output_duration=$(echo "$input_duration"-"$CUT_DURATION" | bc)
# encode file and delete OG
if [ $FORMAT = "ogg" ]; then
ffmpeg -i "$wav_file" -vn -codec:a libvorbis -b:a 64k -t "$output_duration" "$out_file"
elif [ $FORMAT = "mp3" ]; then
ffmpeg -i "$wav_file" -vn -codec:a libmp3lame -qscale:a 1 -t "$output_duration" "$out_file"
else
notify-send "Record Error" "Unknown format $FORMAT"
fi
rm "$wav_file"
# Update newest note with recorded audio
curl -s localhost:$ankiConnectPort -X POST -d '{
"action": "updateNoteFields",
"version": 6,
"params": {
"note": {
"id": '"$newestNoteId"',
"fields": {
"'$audioFieldName'": ""
},
"audio": [{
"path": "'"$out_file"'",
"filename": "'"$time"'.'$FORMAT'",
"fields": [
"'$audioFieldName'"
]
}]
require_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "Missing dependency: $1" >&2
exit 1
}
}
}'
# opens changed note, comment if you don't want it.
curl -s localhost:$ankiConnectPort -X POST -d '{
"action": "guiBrowse",
"version": 6,
"params": {
"query": "nid:'"$newestNoteId"'"
}
}'
notify-send -t 1000 "Audio recording copied"
rm "$out_file"
fi
notify() {
# Best-effort notification; keep script running if notify-send is missing.
if command -v notify-send >/dev/null 2>&1; then
notify-send -t 1000 "$@"
fi
}
get_active_sink() {
pactl list sinks short 2>/dev/null | awk '$6=="RUNNING"{print $1; exit 0}'
}
get_newest_note_id() {
local response
response=$(curl -sS "$ANKI_URL" -X POST -H 'Content-Type: application/json' \
-d '{"action":"findNotes","version":6,"params":{"query":"is:new"}}')
jq -r '.result[-1] // empty' <<<"$response"
}
update_anki_note() {
local note_id="$1" audio_path="$2" filename="$3"
local payload
payload=$(jq -n --argjson noteId "$note_id" --arg field "$AUDIO_FIELD_NAME" \
--arg path "$audio_path" --arg filename "$filename" '
{action:"updateNoteFields",version:6,
params:{note:{id:$noteId,fields:{($field):""},
audio:[{path:$path,filename:$filename,fields:[$field]}]}}}')
curl -sS "$ANKI_URL" -X POST -H 'Content-Type: application/json' -d "$payload" >/dev/null
}
open_note_in_browser() {
local note_id="$1"
local payload
payload=$(jq -n --argjson noteId "$note_id" '
{action:"guiBrowse",version:6,params:{query:("nid:" + ($noteId|tostring))}}')
curl -sS "$ANKI_URL" -X POST -H 'Content-Type: application/json' -d "$payload" >/dev/null
}
record_audio() {
local note_id="$1"
local sink
sink=$(get_active_sink) || true
if [[ -z "$sink" ]]; then
notify "Record Error" "No running PulseAudio sink found"
exit 1
fi
mkdir -p "$CACHE_DIR"
local timestamp wav_file out_file
timestamp=$(date +%s)
wav_file="$CACHE_DIR/$timestamp.wav"
out_file="$CACHE_DIR/$timestamp.$FORMAT"
notify "Audio recording started"
if ! timeout "$RECORD_TIMEOUT" parec -d"$sink" --file-format=wav "$wav_file"; then
notify "Record Error" "No audio captured (timeout or sink issue)"
rm -f "$wav_file"
exit 1
fi
local input_duration output_duration
input_duration=$(ffprobe -v error -select_streams a:0 \
-show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$wav_file")
output_duration=$(echo "$input_duration - $CUT_DURATION" | bc -l)
# Guard against negative durations
if [[ $(echo "$output_duration < 0" | bc -l) -eq 1 ]]; then
output_duration="0"
fi
case "$FORMAT" in
ogg)
ffmpeg -nostdin -y -i "$wav_file" -vn -codec:a libvorbis -b:a 64k \
-t "$output_duration" "$out_file"
;;
mp3)
ffmpeg -nostdin -y -i "$wav_file" -vn -codec:a libmp3lame -qscale:a 1 \
-t "$output_duration" "$out_file"
;;
*)
notify "Record Error" "Unknown format: $FORMAT"
rm -f "$wav_file"
exit 1
;;
esac
rm -f "$wav_file"
update_anki_note "$note_id" "$out_file" "$timestamp.$FORMAT"
open_note_in_browser "$note_id"
notify "Audio recording copied"
rm -f "$out_file"
}
main() {
for cmd in curl jq ffmpeg ffprobe parec pactl bc; do
require_cmd "$cmd"
done
if pgrep -x parec >/dev/null 2>&1; then
pkill -x parec
notify "Audio recording stopped"
exit 0
fi
local newest_note
newest_note=$(get_newest_note_id)
if [[ -z "$newest_note" ]]; then
notify "Anki Connect" "No new notes found or AnkiConnect unavailable"
exit 1
fi
record_audio "$newest_note"
}
main "$@"

View File

@@ -31,6 +31,9 @@ generate_thumbnail() {
local temp_thumb="/tmp/rmpv-thumbnail-$$.jpg"
local thumbnail_file="${video_file%.*}.jpg"
# Clean up previous thumbnail
rm -f "$THUMBNAIL_PATH"
# Validate input
if [[ -z "$video_file" ]]; then
echo "Error: No video file specified" >&2
@@ -51,28 +54,39 @@ generate_thumbnail() {
# Generate thumbnail if it doesn't exist
if [[ ! -f "$thumbnail_file" ]]; then
echo "Generating thumbnail for $(basename "$video_file")..."
if ! ffmpeg -i "$video_file" \
-vf "select='gt(scene,0.4)',scale=320:240:force_original_aspect_ratio=decrease,pad=320:240:(ow-iw)/2:(oh-ih)/2" \
# Try generating thumbnail side-by-side
if ! ffmpeg -ss 00:00:01 -i "$video_file" \
-vf "scale=320:240:force_original_aspect_ratio=decrease,pad=320:240:(ow-iw)/2:(oh-ih)/2" \
-frames:v 1 \
-q:v 4 \
"$thumbnail_file" \
-loglevel error -y 2>/dev/null; then
echo "Error: Failed to generate thumbnail" >&2
return 1
# Fallback to temp file if side-by-side fails (e.g. read-only fs)
echo "Warning: Failed to write to $thumbnail_file, trying temp location" >&2
thumbnail_file="$temp_thumb"
if ! ffmpeg -ss 00:00:01 -i "$video_file" \
-vf "scale=320:240:force_original_aspect_ratio=decrease,pad=320:240:(ow-iw)/2:(oh-ih)/2" \
-frames:v 1 \
-q:v 4 \
"$thumbnail_file" \
-loglevel error -y 2>/dev/null; then
echo "Error: Failed to generate thumbnail" >&2
return 1
fi
fi
fi
# Copy to temporary location with error handling
if ! cp "$thumbnail_file" "$temp_thumb" 2>/dev/null; then
echo "Error: Failed to copy thumbnail to temporary location" >&2
return 1
# Copy to consistent location for notify-send
# We use a fixed path so notify-send always finds it
if cp "$thumbnail_file" "$THUMBNAIL_PATH" 2>/dev/null; then
echo "Thumbnail ready at: $THUMBNAIL_PATH"
ls -l "$THUMBNAIL_PATH"
file "$THUMBNAIL_PATH"
else
echo "Error: Failed to copy thumbnail to $THUMBNAIL_PATH" >&2
fi
# Create symlink for consistent access
ln -sf "$temp_thumb" /tmp/rmpv-thumbnail.jpg 2>/dev/null
sleep 0.1
echo "Thumbnail ready: $temp_thumb"
}
choice="$(find . -iname "*[.mkv|.mp4]" | sort -h | rofi -dmenu -i -theme "$THEME" -theme-str 'listview {columns: 1; lines: 15;} window {width: 88%;}' -p "Choose Video")"
@@ -89,3 +103,4 @@ notify-send -i "$THUMBNAIL_PATH" "Playing Video" "$(basename "$choice")"
$COMMAND "$choice" &
# vim: ft=sh

171
projects/scripts/screenshot-anki.sh Normal file → Executable file
View File

@@ -1,75 +1,112 @@
#!/bin/sh
#!/usr/bin/env bash
# Version 1.2
# click and drag to screenshot dragged portion
# click on specific window to screenshot window area
# dependencies: imagemagick, xclip,curl maybe xdotool (see comment below)
# shoutout to https://gist.github.com/Cephian/f849e326e3522be9a4386b60b85f2f23 for the original script,
# https://github.com/xythh/ added the ankiConnect functionality
# if anki is running the image is added to your latest note as a jpg, if anki is not running it's added to your clipboard as a png
time=$(date +%s)
tmp_file="$HOME/.cache/$time"
ankiConnectPort="8765"
pictureField="Picture"
quality="90"
# Capture a region with slurp+grim. If AnkiConnect is available, attach the
# JPEG to the newest note; otherwise copy a PNG to the clipboard.
# This gets your notes marked as new and returns the newest one.
newestNoteId=$(curl -s localhost:$ankiConnectPort -X POST -d '{"action": "findNotes", "version": 6, "params": { "query": "is:new"}}' | jq '.result[-1]')
set -euo pipefail
# you can remove these two lines if you don't have software which
# makes your mouse disappear when you use the keyboard (e.g. xbanish, unclutter)
# https://github.com/ImageMagick/ImageMagick/issues/1745#issuecomment-777747494
xdotool mousemove_relative 1 1
xdotool mousemove_relative -- -1 -1
ANKI_CONNECT_PORT="${ANKI_CONNECT_PORT:-8765}"
PICTURE_FIELD="${PICTURE_FIELD:-Picture}"
QUALITY="${QUALITY:-90}"
CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/screenshot-anki"
ANKI_URL="http://localhost:${ANKI_CONNECT_PORT}"
REQUIREMENTS=(slurp grim wl-copy xdotool curl jq)
# if anki connect is running it will return your latest note id, and the following code will run, if anki connect is not running nothing is return.
if [ "$newestNoteId" != "" ]; then
if ! import -quality $quality "$tmp_file.jpg"; then
# most likley reason this returns a error, is for fullscreen applications that take full control which does not allowing imagemagick to select the area, use windowed fullscreen or if running wine use a virtual desktop to avoid this.
notify-send "Error screenshoting " "most likely unable to find selection"
exit 1
fi
notify() {
if command -v notify-send >/dev/null 2>&1; then
notify-send "$@"
fi
}
curl -s localhost:$ankiConnectPort -X POST -d '{
"action": "updateNoteFields",
"version": 6,
"params": {
"note": {
"id": '"$newestNoteId"',
"fields": {
"'$pictureField'": ""
},
"picture": [{
"path": "'"$tmp_file"'.jpg",
"filename": "paste-'"$time"'.jpg",
"fields": [
"'$pictureField'"
]
}]
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || {
notify "Missing dependency" "$1 is required"
exit 1
}
}'
}
#remove if you don't want anki to show you the card you just edited
curl -s localhost:$ankiConnectPort -X POST -d '{
"action": "guiBrowse",
"version": 6,
"params": {
"query": "nid:'"$newestNoteId"'"
}
}'
wiggle_mouse() {
# Avoid disappearing cursor on some compositors
xdotool mousemove_relative 1 1
xdotool mousemove_relative -- -1 -1
}
#you can comment this if you do not use notifcations.
notify-send "Screenshot Taken" "Added to note"
rm "$tmp_file.jpg"
else
if ! import -quality $quality "$tmp_file.png"; then
notify-send "Error screenshoting " "most likely unable to find selection"
exit 1
fi
# we use pngs when copying to clipboard because they have greater support when pasting.
xclip -selection clipboard -target image/png -i "$tmp_file.png"
rm "$tmp_file.png"
#you can comment this if you do not use notifcations.
notify-send "Screenshot Taken" "Copied to clipboard"
fi
capture_region() {
local fmt="$1" quality="$2" output="$3"
local geometry
geometry=$(slurp)
if [[ -z "$geometry" ]]; then
notify "Screenshot cancelled" "No region selected"
exit 1
fi
if [[ "$fmt" == "jpeg" ]]; then
grim -g "$geometry" -t jpeg -q "$quality" "$output"
else
grim -g "$geometry" -t png "$output"
fi
}
copy_to_clipboard() {
local file="$1"
if ! wl-copy <"$file"; then
notify "Error copying screenshot" "wl-copy failed"
exit 1
fi
}
get_newest_note_id() {
local response
response=$(curl -sS "$ANKI_URL" -X POST -H 'Content-Type: application/json' \
-d '{"action":"findNotes","version":6,"params":{"query":"is:new"}}')
jq -r '.result[-1] // empty' <<<"$response"
}
update_note_with_image() {
local note_id="$1" image_path="$2" filename="$3"
local payload
payload=$(jq -n --argjson noteId "$note_id" --arg field "$PICTURE_FIELD" \
--arg path "$image_path" --arg filename "$filename" '
{action:"updateNoteFields",version:6,
params:{note:{id:$noteId,fields:{($field):""},
picture:[{path:$path,filename:$filename,fields:[$field]}]}}}')
curl -sS "$ANKI_URL" -X POST -H 'Content-Type: application/json' -d "$payload" >/dev/null
}
open_note_in_browser() {
local note_id="$1"
local payload
payload=$(jq -n --argjson noteId "$note_id" '
{action:"guiBrowse",version:6,params:{query:("nid:" + ($noteId|tostring))}}')
curl -sS "$ANKI_URL" -X POST -H 'Content-Type: application/json' -d "$payload" >/dev/null
}
main() {
for cmd in "${REQUIREMENTS[@]}"; do
require_cmd "$cmd"
done
mkdir -p "$CACHE_DIR"
local timestamp base newest_note image_path
timestamp=$(date +%s)
base="$CACHE_DIR/$timestamp"
wiggle_mouse
newest_note=$(get_newest_note_id)
if [[ -n "$newest_note" ]]; then
image_path="$base.jpg"
capture_region "jpeg" "$QUALITY" "$image_path"
update_note_with_image "$newest_note" "$image_path" "paste-$timestamp.jpg"
open_note_in_browser "$newest_note"
notify -i "$image_path" "Screenshot Taken" "Added to Anki note"
rm -f "$image_path"
else
image_path="$base.png"
capture_region "png" "" "$image_path"
copy_to_clipboard "$image_path"
notify -i "$image_path" "Screenshot Taken" "Copied to clipboard"
rm -f "$image_path"
fi
}
main "$@"