diff --git a/sway/config b/sway/config index 66a86f7..fdf948d 100644 --- a/sway/config +++ b/sway/config @@ -13,8 +13,6 @@ set $tty-popup $scripts/tty-popup set $menu bash ~/.config/sway/scripts/menu set $pass_menu $tty-popup pass $scripts/fzf-pass -set $clipman_menu bash ~/.config/sway/scripts/menu_clipman -set $clipman_clear_menu bash ~/.config/sway/scripts/clipman_clear_menu set $printscreen bash ~/.config/sway/scripts/printscreen # Support for picture in picture mode. diff --git a/sway/config.d/autostart b/sway/config.d/autostart index cf16e7c..6390cee 100644 --- a/sway/config.d/autostart +++ b/sway/config.d/autostart @@ -7,6 +7,10 @@ exec --no-startup-id protonmail-bridge 2>&1 >/tmp/mail.log ### Make things a little easier easier on the eyes. exec --no-startup-id redshift 2>&1 >/tmp/redshift.log +### Clipboard manager +exec --no-startup-id $scripts/clipboard daemon 2>&1 >/tmp/clipboardmanager.log + + ### Notifications # https://github.com/emersion/mako exec --no-startup-id mako 2>&1 >/tmp/mako.log @@ -39,9 +43,5 @@ exec_always { tail -f /tmp/wobpipe | ~/.config/sway/scripts/sanitize_wob | wob } -### Clipboard manager -# https://github.com/yory8/clipman -exec --no-startup-id wl-paste -t text --watch clipman store - # vim: ft=cfg # -*- mode: conf-space -*- diff --git a/sway/config.d/keybinds b/sway/config.d/keybinds index e64e962..493568d 100644 --- a/sway/config.d/keybinds +++ b/sway/config.d/keybinds @@ -8,9 +8,7 @@ bindsym $mod+q kill bindsym $mod+space exec $menu # gopass prompt bindsym $mod+backslash exec $pass_menu -# Clipboard management -bindsym $mod+Mod1+c exec $clipman_menu -bindsym $mod+Shift+Mod1+c exec $clipman_clear_menu + # reload the configuration file bindsym $mod+Shift+c reload diff --git a/sway/scripts/clipboard b/sway/scripts/clipboard new file mode 100755 index 0000000..511ca50 --- /dev/null +++ b/sway/scripts/clipboard @@ -0,0 +1,50 @@ +#!/bin/bash + +workdir="${XDG_DATA_HOME:-$HOME/.local/share/clipboard/history}" +mkdir -p "$workdir" +cd "$workdir" + +if [ "$1" = "daemon" ]; then + wl-paste -w $0 on-copy +elif [ "$1" = "lock" ]; then + touch .lock +elif [ "$1" = "unlock" ]; then + rm -f .lock +elif [ "$1" = "on-copy" ]; then + [ -f .lock ] && exit 0 + file="$(date +%s)" + cat >"$file" + ext="$(file --mime-type "$file" | cut -d' ' -f2 | cut -d'/' -f2)" + mv "$file" "$file.$ext" + fdupes -idN . + find . -type f -size 0 -delete + find . -type f -size +10000000c -delete + find . -type f -print0 | sort -zn | head -z -n -10000 | xargs -r -0 rm +elif [ "$1" = "dmenu" ]; then + find . -type f -printf '%P\0' | sort -znr | while IFS= read -r -d '' file; do + if [[ "$file" =~ \.(plain|x-python)$ ]]; then + cat "$file" + else + printf '%s' "$file" + fi + printf '\0' + done | dmenu -0 -p clipboard -r "$(realpath "$0") preview" | { + read -r -d '' result + if [ -z "$result" ]; then + exit 0 + elif [ -f "$result" ]; then + wl-copy <"$result" + else + printf '%s' "$result" | sed -e 's/[[:space:]]*$//' | sed -Ez 's/\s+$//' | wl-copy + fi + } +elif [ "$1" = "preview" ]; then + if [ -f "$2" ]; then + kitty +kitten icat --silent --stdin=no "$2" + else + echo "$2" | bat -l bash --color always -pp + fi +else + echo >&2 "Usage: $0 " + exit 1 +fi diff --git a/sway/scripts/clipman_clear_menu b/sway/scripts/clipman_clear_menu deleted file mode 100644 index 84735d5..0000000 --- a/sway/scripts/clipman_clear_menu +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh -# -*- sh -*- -clipman clear --tool rofi diff --git a/sway/scripts/menu_clipman b/sway/scripts/menu_clipman deleted file mode 100755 index abed059..0000000 --- a/sway/scripts/menu_clipman +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh -# -*- sh -*- -clipman pick --tool rofi