feat: script: edit-clipboard

This commit is contained in:
js0ny 2025-11-14 08:17:38 +00:00
parent 4977346e60
commit f80d83bbd7
14 changed files with 133 additions and 71 deletions

View file

@ -62,6 +62,7 @@ vim:ft=gotmpl
.config/krunnerrc .config/krunnerrc
.config/fcitx5 .config/fcitx5
.config/niri .config/niri
.config/neovide
.local/share/kio/** .local/share/kio/**
.local/share/fonts/** .local/share/fonts/**
{{ end }} {{ end }}

View file

@ -10,55 +10,6 @@ key_bindings = KeyBindings()
def in_navigation_mode(): def in_navigation_mode():
return ip.pt_app.app.vi_state.input_mode == InputMode.NAVIGATION return ip.pt_app.app.vi_state.input_mode == InputMode.NAVIGATION
# colemak keymap hnei
@key_bindings.add("n", filter=in_navigation_mode)
def _(event):
"Move cursor down by visual line"
event.current_buffer.auto_down(count=event.arg)
@key_bindings.add("e", filter=in_navigation_mode)
def _(event):
"Move cursor up by visual line"
event.current_buffer.auto_up(count=event.arg)
@key_bindings.add("i", filter=in_navigation_mode)
def _(event):
"Move cursor right"
event.current_buffer.cursor_right(count=event.arg)
# Insert with 'l' and 'L'
@key_bindings.add("l", filter=in_navigation_mode)
def _(event):
"Enter insert mode (similar position to 'i' in Colemak)"
event.app.vi_state.input_mode = InputMode.INSERT
@key_bindings.add("L", filter=in_navigation_mode)
def _(event):
"Enter insert mode at the beginning of the line"
event.current_buffer.cursor_position += event.current_buffer.document.get_start_of_line_position()
# Ne[k]st
@key_bindings.add("k", filter=in_navigation_mode)
def _(event):
"Find next match"
event.current_buffer.forward_search()
@key_bindings.add("K", filter=in_navigation_mode)
def _(event):
"Find previous match"
event.current_buffer.reverse_search()
# [J]ump
@key_bindings.add("j", filter=in_navigation_mode)
def _(event):
"Move to end of next word"
event.current_buffer.cursor_right_word()
@key_bindings.add("J", filter=in_navigation_mode)
def _(event):
"Move to end of next word with capital E"
event.current_buffer.cursor_right_word(end=True)
# Yank to end of line with 'Y' # Yank to end of line with 'Y'
@key_bindings.add("Y", filter=in_navigation_mode) @key_bindings.add("Y", filter=in_navigation_mode)
def _(event): def _(event):

View file

@ -18,8 +18,5 @@ vsync = true
wsl = false wsl = false
[font] [font]
normal = [ normal = ["Maple Mono NF CN",]
"Maple Mono NF",
"Iosevka Nerd Font",
] # Will use the bundled Fira Code Nerd Font by default
size = 14.0 size = 14.0

View file

@ -88,13 +88,13 @@ return {
img_dirs = { "90 - System/Assets" }, img_dirs = { "90 - System/Assets" },
}, },
}, },
-- keys = { keys = {
-- { {
-- "<leader>ft", "<leader>ba",
-- function() function()
-- require("snacks").explorer() require("snacks").dashboard()
-- end, end,
-- desc = "Toggle File Explorer", desc = "Toggle Dashboard";
-- }, },
-- }, },
} }

View file

@ -13,5 +13,4 @@
papers papers
gtop gtop
]; ];
services.xremap.withGnome = true;
} }

View file

@ -11,5 +11,4 @@
hyprpolkitagent hyprpolkitagent
xdg-desktop-portal-wlr xdg-desktop-portal-wlr
]; ];
services.xremap.withHypr = true;
} }

View file

@ -12,6 +12,7 @@
services.xremap = { services.xremap = {
enable = true; enable = true;
withNiri = true;
# modmap: single key # modmap: single key
serviceMode = "user"; serviceMode = "user";
userName = "js0ny"; userName = "js0ny";
@ -39,13 +40,33 @@
]; ];
keymap = [ keymap = [
{ {
name = "Telegram Navigator"; name = "IM Navigator - Alt-Up/Down";
application = { application = {
only = ["org.telegram.desktop" "telegram-desktop"]; only = ["org.telegram.desktop" "telegram-desktop" "wechat"];
}; };
remap = { remap = {
"M-j" = "M-down"; # alt.j = macro(C-tab) "M-j" = "M-down";
"M-k" = "M-up"; # alt.k = C-S-tab "M-k" = "M-up";
};
}
{
name = "IM Navigator - Ctrl-Up/Down";
application = {
only = ["qq"];
};
remap = {
"M-j" = "C-down";
"M-k" = "C-up";
};
}
{
name = "Zotero PDF Navigator";
application = {
only = ["zotero"];
};
remap = {
"M-j" = "KEY_PAGEDOWN";
"M-k" = "KEY_PAGEUP";
}; };
} }
]; ];

View file

@ -37,7 +37,6 @@
vmopts = ''-Dawt.toolkit.name=WLToolkit''; vmopts = ''-Dawt.toolkit.name=WLToolkit'';
}) })
localsend localsend
neovide
cherry-studio cherry-studio
kdePackages.kdeconnect-kde kdePackages.kdeconnect-kde
picard picard

View file

@ -35,12 +35,12 @@ in {
imports = [ imports = [
../../rofi.nix ../../rofi.nix
./waybar.nix ./waybar.nix
./swww.nix
]; ];
home.packages = with pkgs; [ home.packages = with pkgs; [
swayidle # Screensaver swayidle # Screensaver
dunst # Notification daemon dunst # Notification daemon
cliphist # Clipboard daemon cliphist # Clipboard daemon
swww # Wallpaper daemon
wmname wmname
# swayidleWrapper # swayidleWrapper
brightnessctl brightnessctl

View file

@ -0,0 +1,3 @@
{...}: {
services.swww.enable = true;
}

View file

@ -0,0 +1,68 @@
{pkgs, ...}: let
editClipboard = pkgs.writeShellScriptBin "edit-clipboard" ''
#!/usr/bin/env bash
# POSIX-compliant edit-clipboard function
# Reads clipboard content, opens it in $EDITOR, and writes back to clipboard
edit-clipboard() {
# Detect clipboard command based on platform
if command -v pbpaste >/dev/null 2>&1; then
# macOS
PASTE_CMD="pbpaste"
COPY_CMD="pbcopy"
elif command -v wl-paste >/dev/null 2>&1; then
# Wayland
PASTE_CMD="wl-paste"
COPY_CMD="wl-copy"
elif command -v xclip >/dev/null 2>&1; then
# X11 (xclip)
PASTE_CMD="xclip -selection clipboard -o"
COPY_CMD="xclip -selection clipboard -i"
elif command -v xsel >/dev/null 2>&1; then
# X11 (xsel)
PASTE_CMD="xsel --clipboard --output"
COPY_CMD="xsel --clipboard --input"
else # TODO: Test it on WSL2
echo "Error: No clipboard utility found" >&2
echo "Install one of: pbpaste/pbcopy (macOS), wl-clipboard (Wayland), xclip, or xsel (X11)" >&2
return 1
fi
# Create temporary file
TMPFILE=$(mktemp /tmp/clipboard.XXXXXX) || {
echo "Error: Failed to create temporary file" >&2
return 1
}
# Read clipboard into temp file
$PASTE_CMD > "$TMPFILE" || {
echo "Error: Failed to read from clipboard" >&2
rm -f "$TMPFILE"
return 1
}
# Open in editor
"''${EDITOR:-vi}" "$TMPFILE" || {
echo "Error: Editor exited with error" >&2
rm -f "$TMPFILE"
return 1
}
# Write back to clipboard
$COPY_CMD < "$TMPFILE" || {
echo "Error: Failed to write to clipboard" >&2
rm -f "$TMPFILE"
return 1
}
# Cleanup
rm -f "$TMPFILE"
}
if [ "''${0##*/}" = "edit-clipboard" ] || [ "''${0##*/}" = "edit-clipboard.sh" ]; then
edit-clipboard "$@"
fi
'';
in {
home.packages = [editClipboard];
}

View file

@ -0,0 +1,22 @@
{...}: {
programs.neovide = {
enable = true;
settings = {
fork = true;
ide = true;
maximized = false;
frame = "full";
no-multigrid = false;
srgb = false;
tabs = true;
theme = "auto";
title-hidden = true;
vsync = true;
wsl = false;
font = {
normal = ["Maple Mono NF CN"];
size = 14;
};
};
};
}

View file

@ -36,7 +36,7 @@ in {
home.packages = [pdf2zhRunner]; home.packages = [pdf2zhRunner];
home.file.".local/share/kio/servicemenus/pdf2zh.desktop" = { home.file.".local/share/kio/servicemenus/pdf2zh.desktop" = {
enable = false; # TODO: Write a wrapper for status tracking enable = true; # TODO: Write a wrapper for status tracking
executable = true; executable = true;
text = '' text = ''
[Desktop Entry] [Desktop Entry]

View file

@ -42,6 +42,8 @@
./programs/magick.nix ./programs/magick.nix
./programs/miniserve.nix ./programs/miniserve.nix
./programs/retroarch.nix ./programs/retroarch.nix
./programs/neovide.nix
./programs/edit-clipboard.nix
# Desktop Linux # Desktop Linux
./programs/desktop/plasma ./programs/desktop/plasma