summaryrefslogtreecommitdiff
path: root/bin/guiscripts
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-20 12:01:39 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-20 12:01:39 +0200
commit947f7df73f16981f170265a64a964142fc617023 (patch)
tree75c7f8560539303e4a5c1f93241a1e8912bad4cc /bin/guiscripts
parentff6c38d3364165a7bae431888a87aab1e53a80b9 (diff)
checkpoint
Diffstat (limited to 'bin/guiscripts')
-rwxr-xr-xbin/guiscripts/osurf-fill22
-rwxr-xr-xbin/guiscripts/osurftxt28
-rwxr-xr-xbin/guiscripts/osurftxts22
3 files changed, 52 insertions, 20 deletions
diff --git a/bin/guiscripts/osurf-fill b/bin/guiscripts/osurf-fill
index 311c273..43af807 100755
--- a/bin/guiscripts/osurf-fill
+++ b/bin/guiscripts/osurf-fill
@@ -1,6 +1,16 @@
#!/bin/sh
-# bitwarden dmenu script - based off of the autofill userscript from qutebrowser
-# requires the fifo patch
+
+# Fills a password for a given website
+# original script by Avalon Williams (avalonwilliams@protonmail.com)
+# This version uses the window id to know the url of the surf window
+# and to know which fifo it must use. Then it injects javascript code.
+# that will fill the forms with the credentials
+
+# dependencies:
+# - surf fifo patch (http://surf.suckless.org/patches/fifo/)
+# - xprop
+# - 'pass' with password store in form dir/url/pass.gpg
+
# $1: winid
fifodir="$HOME/.config/surf/fifo"
@@ -12,6 +22,7 @@ fi
fifo="$fifodir/$winid"
[ -p "$fifo" ] || exit 2
+# Get only domain name + top-level domain
url="$(xprop -id "$winid" _SURF_URI |
cut -f 2 -d'"' |
sed 's,^.*://\([^/]*\)/.*,\1,' |
@@ -19,13 +30,15 @@ url="$(xprop -id "$winid" _SURF_URI |
[ "$url" ] || exit 3
>&2 printf 'url: %s\n' "$url"
-
+# get pass with url and ask if multiple are found
pass="$({ find $PASSWORD_STORE_DIR/websites/ -type f -name '*.gpg' |
grep "$url/" || echo; } | head -n 1 |
sed "s,$PASSWORD_STORE_DIR/,,;s/\.gpg$//" |
dmenu -c)"
+# if dmenu was stopped, exit
[ $? -gt 0 ] && exit 4
+# if no password was found, search through password store manually with dmenu
if [ -z "$pass" ]
then
store="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
@@ -44,14 +57,15 @@ then
pass="$file"
fi
>&2 printf 'pass: %s\n' "$pass"
-
herbe "filling ${pass#websites/}" &
# Get password and username in variables with only one call to 'pass'
+# escape single quotes
eval "$(pass show "$pass" |
sed -n "1s/'/'\\\\''/g;1s/.*/password='&'/p;s/^login: \?\(.\+\)/username='\1'/p")"
printf '%s : %s\n' "$username" "$password"
+# Escape quotes and backslashes for javascript
javascript_escape() {
printf '%s' "$1" | sed -s 's,['\''"\\\\],\\\\&,g'
}
diff --git a/bin/guiscripts/osurftxt b/bin/guiscripts/osurftxt
index ef60166..9a1d4f4 100755
--- a/bin/guiscripts/osurftxt
+++ b/bin/guiscripts/osurftxt
@@ -1,22 +1,18 @@
#!/bin/sh
-# open all links in txt file into one tabbed surf
+# open a link from a txt file in surf
# dependencies: surf, osurf, dmenu
-# $1: file path for non interactive use
-if [ -z "$1" ]
-then
- d="$HOME/dl/txtabs"
- f="$(find "$d" -type f -printf '%f\n' | dmenu)"
- [ "$f" ] || exit 1
- f="$d"/"$f"
-else
- [ -f "$1" ] || exit 1
- f="$1"
-fi
+winid="$1"
+>&2 printf 'winid: %s\n' "$winid"
+tabs="$HOME/dl/txtabs"
-winid="$(osurf "$(head -n 1 "$f")")"
-tail -n +2 "$f" | while read -r url;
- do surf -e "$winid" "$url" &
- done
+f="$(find "$tabs" -type f -printf '%f\n' | dmenu -c)"
+[ "$f" ] || exit 1
+f="$tabs"/"$f"
+>&2 printf 'f: %s\n' "$f"
+
+url="$(dmenu -c < "$f")"
+
+printf 'loaduri %s' "$url" > $HOME/.config/surf/fifo/$winid
diff --git a/bin/guiscripts/osurftxts b/bin/guiscripts/osurftxts
new file mode 100755
index 0000000..ef60166
--- /dev/null
+++ b/bin/guiscripts/osurftxts
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# open all links in txt file into one tabbed surf
+
+# dependencies: surf, osurf, dmenu
+
+# $1: file path for non interactive use
+if [ -z "$1" ]
+then
+ d="$HOME/dl/txtabs"
+ f="$(find "$d" -type f -printf '%f\n' | dmenu)"
+ [ "$f" ] || exit 1
+ f="$d"/"$f"
+else
+ [ -f "$1" ] || exit 1
+ f="$1"
+fi
+
+winid="$(osurf "$(head -n 1 "$f")")"
+tail -n +2 "$f" | while read -r url;
+ do surf -e "$winid" "$url" &
+ done