diff --git a/dotfiles/config/clipit/clipitrc b/dotfiles/config/clipit/clipitrc new file mode 100644 index 00000000..6ddf634d --- /dev/null +++ b/dotfiles/config/clipit/clipitrc @@ -0,0 +1,25 @@ +[rc] +use_copy=true +use_primary=true +synchronize=true +automatic_paste=false +show_indexes=true +save_uris=true +use_rmb_menu=false +save_history=true +history_limit=500 +items_menu=20 +statics_show=true +statics_items=10 +hyperlinks_only=false +confirm_clear=false +single_line=true +reverse_history=false +item_length=50 +ellipsize=2 +history_key= +actions_key= +menu_key= +search_key= +offline_key= +offline_mode=false diff --git a/dotfiles/config/systemd/user/clipit.service b/dotfiles/config/systemd/user/clipit.service new file mode 100644 index 00000000..ea7b3974 --- /dev/null +++ b/dotfiles/config/systemd/user/clipit.service @@ -0,0 +1,12 @@ +[Unit] +Description=clipit +Wants=taffybar.service +After=taffybar.service + +[Service] +Type=simple +ExecStart=/usr/bin/env clipit +ExecStop=/usr/bin/pkill clipit + +[Install] +WantedBy=wm.target diff --git a/dotfiles/config/xmonad/xmonad.hs b/dotfiles/config/xmonad/xmonad.hs index 8d8d8f87..d358a7e0 100644 --- a/dotfiles/config/xmonad/xmonad.hs +++ b/dotfiles/config/xmonad/xmonad.hs @@ -973,7 +973,7 @@ addKeys conf@XConfig { modMask = modm } = , ((modm, xK_v), spawn "copyq paste") , ((modm .|. controlMask, xK_s), spawn "split_current_chrome_tab.sh") - , ((hyper, xK_v), spawn "copyq_rofi.sh") + , ((hyper, xK_v), spawn "clipit_rofi.sh") , ((hyper, xK_p), spawn "rofi-pass") , ((hyper, xK_h), spawn "screenshot.sh") , ((hyper, xK_c), spawn "shell_command.sh") diff --git a/dotfiles/lib/bin/clipit_history.py b/dotfiles/lib/bin/clipit_history.py new file mode 100755 index 00000000..fb485555 --- /dev/null +++ b/dotfiles/lib/bin/clipit_history.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +from __future__ import print_function +import appdirs +import argparse +import os +import struct +import string + + +clipit_history_file = os.path.join(appdirs.user_data_dir(), "clipit/history") + + +def get_clipit_history(filename): + with open(filename, 'rb') as f: + f.read(68) + size, _ = struct.unpack('2i', f.read(8)) + while (size > 0): + item = f.read(size) + if item: + yield item + _, _, _, size, _ = struct.unpack('5i', f.read(20)) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Lookup clipit history') + parser.add_argument( + '--separator', '-s', + help='the separator to use when outputting history', + type=str, + default='\n', + ) + parser.add_argument( + '--begin-index', '-b', + type=int, + default=0 + ) + parser.add_argument( + '--end-index', '-e', + type=int, + default=None + ) + parser.add_argument( + '--index', '-i', + type=int, + default=None + ) + parser.add_argument( + '--separator-replacement', '-r', + type=str, + default=None + ) + args = parser.parse_args() + if not args.separator_replacement: + args.separator_replacement = args.separator + history = list(get_clipit_history(clipit_history_file)) + if args.index is not None: + text = history[args.index] + else: + selected = history[args.begin_index:args.end_index] + text = args.separator.join([string.replace(s, args.separator, args.separator_replacement) + for s in selected]) + print(text, end='') diff --git a/dotfiles/lib/bin/clipit_rofi.sh b/dotfiles/lib/bin/clipit_rofi.sh new file mode 100755 index 00000000..c6e4a7c8 --- /dev/null +++ b/dotfiles/lib/bin/clipit_rofi.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +SELECTED_INDEX="$(clipit_history.py -r '(newline)' | rofi -dmenu -format i)" + +if [ "$SELECTED_INDEX" -eq "$SELECTED_INDEX" ] 2>/dev/null; then + xdotool type "$(clipit_history.py -e 5 -i $SELECTED_INDEX)" +fi