Skip to content

Instantly share code, notes, and snippets.

@haolian9
Created March 8, 2022 16:01
Show Gist options
  • Save haolian9/4384711216dd2931b8ea7bb4e2ae84ba to your computer and use it in GitHub Desktop.
Save haolian9/4384711216dd2931b8ea7bb4e2ae84ba to your computer and use it in GitHub Desktop.
xsel wrapper of xclip for [pass](https://www.passwordstore.org)
#!/usr/bin/env python3
import os
import sys
def as_xsel_args():
"""only supports xclip options that are used by pass
* xclip -selection "$X_SELECTION"
* xclip -o -selection "$X_SELECTION"
"""
argv = sys.argv
def pop_first():
try:
return argv.pop(0)
except IndexError:
raise SystemExit("expects more args")
bin = pop_first()
if not bin.endswith("xclip"):
raise SystemExit("unexpected bin")
while argv:
arg = pop_first()
if arg == "-o":
yield "--output"
continue
if arg == "-selection":
sel = pop_first()
if sel == "clipboard":
yield "--clipboard"
continue
raise SystemExit("unknown selection")
raise SystemExit("unknown option")
def main():
os.execvp("xsel", list(as_xsel_args()))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment