aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2024-06-08 17:42:11 +0300
committeromagdy7 <omar.professional8777@gmail.com>2024-06-08 17:42:11 +0300
commit3e2b2c1beb85dce314d5dc67294aa55643f2aa6d (patch)
treebf833d09d1f305605e57fa1c6fd0953feec2f3ad /scripts
parent4db4fabf25efe99f6c92596720e8d68e79775b53 (diff)
downloaddotfiles-3e2b2c1beb85dce314d5dc67294aa55643f2aa6d.tar.xz
dotfiles-3e2b2c1beb85dce314d5dc67294aa55643f2aa6d.zip
Changed screenshot script to use flameshot instead and also fixed delay when yanking in neovim
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/.scripts/pwned.py62
-rwxr-xr-xscripts/.scripts/screenshot.sh10
2 files changed, 68 insertions, 4 deletions
diff --git a/scripts/.scripts/pwned.py b/scripts/.scripts/pwned.py
new file mode 100755
index 0000000..6c28d09
--- /dev/null
+++ b/scripts/.scripts/pwned.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+import hashlib
+import sys
+
+try:
+ import requests
+except ModuleNotFoundError:
+ print("### pip install requests ###")
+ raise
+
+
+def lookup_pwned_api(pwd):
+ """Returns hash and number of times password was seen in pwned database.
+
+ Args:
+ pwd: password to check
+
+ Returns:
+ A (sha1, count) tuple where sha1 is SHA-1 hash of pwd and count is number
+ of times the password was seen in the pwned database. count equal zero
+ indicates that password has not been found.
+
+ Raises:
+ RuntimeError: if there was an error trying to fetch data from pwned
+ database.
+ UnicodeError: if there was an error UTF_encoding the password.
+ """
+ sha1pwd = hashlib.sha1(pwd.encode('utf-8')).hexdigest().upper()
+ head, tail = sha1pwd[:5], sha1pwd[5:]
+ url = 'https://api.pwnedpasswords.com/range/' + head
+ res = requests.get(url)
+ if not res.ok:
+ raise RuntimeError('Error fetching "{}": {}'.format(
+ url, res.status_code))
+ hashes = (line.split(':') for line in res.text.splitlines())
+ count = next((int(count) for t, count in hashes if t == tail), 0)
+ return sha1pwd, count
+
+
+def main(args):
+ ec = 0
+ for pwd in args or sys.stdin:
+ pwd = pwd.strip()
+ try:
+ sha1pwd, count = lookup_pwned_api(pwd)
+ except UnicodeError:
+ errormsg = sys.exc_info()[1]
+ print("{0} could not be checked: {1}".format(pwd, errormsg))
+ ec = 1
+ continue
+
+ if count:
+ foundmsg = "{0} was found with {1} occurrences (hash: {2})"
+ print(foundmsg.format(pwd, count, sha1pwd))
+ ec = 1
+ else:
+ print("{} was not found".format(pwd))
+ return ec
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
diff --git a/scripts/.scripts/screenshot.sh b/scripts/.scripts/screenshot.sh
index f56a771..374dfe9 100755
--- a/scripts/.scripts/screenshot.sh
+++ b/scripts/.scripts/screenshot.sh
@@ -1,6 +1,8 @@
#!/bin/sh -e
-selection=$(hacksaw -f "-i %i -g %g")
-shotgun $selection - | xclip -t 'image/png' -selection clipboard
-random_word=$(cat /usr/share/dict/cracklib-small | shuf -n 1)
-shotgun $selection - >/tmp/$random_word.png
+# selection=$(hacksaw -f "-i %i -g %g")
+# shotgun $selection - | xclip -t 'image/png' -selection clipboard
+# random_word=$(cat /usr/share/dict/cracklib-small | shuf -n 1)
+# shotgun $selection - >/tmp/$random_word.png
+
+flameshot gui --clipboard