You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

import sqlite3, pyperclip, os.path, subprocess, sys
conn = sqlite3.connect(os.path.expanduser("~/.local/share/clipstack.sqlite3"))
conn.executescript("""CREATE TABLE IF NOT EXISTS stack (pos INTEGER PRIMARY KEY, data BLOB NOT NULL)""")
def push(data):
c = conn.cursor()
c.execute("SELECT max(pos) FROM stack")
res = c.fetchone()[0]
if res == None: nxt = 0
else: nxt = res + 1
c.execute("INSERT INTO stack VALUES (?, ?)", (nxt, data))
def pop():
c = conn.cursor()
c.execute("SELECT * FROM stack ORDER BY pos DESC LIMIT 1")
res = c.fetchone()
if not res: return
pos, data = res
c.execute("DELETE FROM stack WHERE pos = ?", (pos,))
return data
mode = sys.argv[1]
if mode == "push":
proc =["xclip", "-selection", "clipboard", "-o"], stdout=subprocess.PIPE)
if proc.returncode == 0:
elif mode == "pop":
data = pop()
if data:
proc =["xclip", "-selection", "clipboard"], input=data)