Compare commits

..

No commits in common. "ba5680253d204cb40e841d35e2b5f459b50a2901" and "22d2a9d827f169dc2e48a0356b7d74bc3bcb293e" have entirely different histories.

4 changed files with 1 additions and 133 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
__pycache__

View File

@ -1,56 +0,0 @@
#!/usr/bin/env python
import requests
import sys
import fileinput
## EXIT CODES:
# 1: Fail in arg parsing
# 2: Network error
def eprint(*args, **kwargs):
# uncomment to enable debug...
#print(*args, file=sys.stderr, **kwargs)
pass
#isbn can be a csv list
def convert_isbn_to_bibtex(isbn):
url = "https://api.paperpile.com/api/public/convert"
payload = {
"input": isbn,
"targetFormat": "Bibtex",
"fromIds": True
}
eprint(payload)
response = requests.post(url, json=payload)
eprint(response.text)
if response.status_code == 200 or response.status_code == 201:
return response.json().get("output")
else:
eprint("Failed!, res code: ", response.status_code)
return None
isbn = None
if not sys.stdin.isatty() and fileinput.input():
stdin_ = list(fileinput.input())
isbn = ",".join(stdin_)
print("isbn from stdin:", isbn)
# favour stdin over args!
if (not isbn):
if (len(sys.argv) > 1):
isbn = sys.argv[1]
print("isbn from args:", isbn)
else:
eprint("No Arguments (or stdin) Provided!")
sys.exit(1)
bibtex = convert_isbn_to_bibtex(isbn)
if bibtex:
print(bibtex)
else:
print("Failed to convert ISBN to BibTeX")
sys.exit(2)
sys.exit(0)

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
setxkbmap -option ctrl:swapcaps setxkbmap -option ctrl:swapcaps
setxkbmap -option altwin:swap_lalt_lwin setxkbmap -option altwin:swap_lalt_lwin
setxkbmap -model pc105 -layout us,ara -variant ,qwerty -option grp:shifts_toggle setxkbmap -model pc105 -layout us,ar -variant ,qwerty -option grp:shifts_toggle
xset r rate 300 50 xset r rate 300 50

View File

@ -1,75 +0,0 @@
#!/usr/bin/env python
import sys
def eprint(*args, **kwargs):
# uncomment to enable debug...
print(*args, file=sys.stderr, **kwargs)
pass
def bash_it(cmd):
eprint("bash_it", cmd)
result = subprocess.run(["bash", "-c", cmd], capture_output=True)
result = result.stdout.decode("utf-8")
return result
def read_clipboard():
# Read the clipboard on linux
return subprocess.check_output(["xclip", "-o", "-sel", "clipboard"], universal_newlines=True)
# Read the clipboard on macOS
# return subprocess.check_output(["pbpaste"], universal_newlines=True)
# Read the clipboard on Windows
# return subprocess.check_output(["powershell", "-command", "Get-Clipboard"], universal_newlines=True)
def write_to_clipboard(text):
# Write the text to the clipboard on Linux
subprocess.run(["xclip", "-selection", "clipboard"], input = text.strip().encode('utf-8'), check=True)
# bash_it("echo " + text + "|" + "xclip -sel c")
# Write the text to the clipboard on macOS
# subprocess.run(["echo", "-n", text, "|", "pbcopy"], shell=True)
# Write the text to the clipboard on Windows
# subprocess.run(["powershell", "-command", "Set-Clipboard", text], shell=True)
def send_notif(title, message):
eprint(title, message)
subprocess.Popen(['notify-send', title, message])
import subprocess
commands = ['isbn to bibtex',
'b',
'c']
rofi_process = subprocess.Popen(['rofi', '-dmenu'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
selected_command, _ = rofi_process.communicate('\n'.join(commands))
selected_command = selected_command.strip()
if selected_command:
send_notif("Command Execution", f'Executing command: {selected_command}')
if selected_command == 'isbn to bibtex':
clipboard = read_clipboard()
isbn = bash_it(f"echo \"{clipboard}\n'Esc to Cancel'\" | rofi -dmenu")
exit(0) if not isbn else False
isbn = isbn.replace("\n", ",")
res = bash_it('echo ' + isbn + '| isbn_to_bibtex.py')
write_to_clipboard(res)
send_notif("status", "done!: "+ res)
else:
send_notif("Failure", "Unkown Command")
exit(1)
else:
print('No command selected')
exit(0)