summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/common/gt111
-rwxr-xr-xbin/guiscripts/osurf-fill22
-rwxr-xr-xbin/guiscripts/osurftxt28
-rwxr-xr-xbin/guiscripts/osurftxts22
-rw-r--r--config/essentials/shell/aliases.sh3
-rw-r--r--config/essentials/shell/functions.sh2
-rw-r--r--config/essentials/vis/plugins/vis-snippets/init.lua0
-rw-r--r--config/essentials/vis/visrc.lua1
8 files changed, 165 insertions, 24 deletions
diff --git a/bin/common/gt b/bin/common/gt
new file mode 100755
index 0000000..bdbd00f
--- /dev/null
+++ b/bin/common/gt
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+# Git Trach, track the state of multiple repos from a single file.
+
+# dependencies:
+# - git
+# - $EDITOR: -e
+# - herbe (optional): -s
+
+repos="${XDG_DATA_HOME:-$HOME}"/git-track.txt
+touch "$repos"
+
+help() {
+ >&2 cat <<EOF
+usage: gt [OPTION]
+-a PATH add repo
+-s update and show status of each repo
+-c COMMAND run 'git COMMAND' in each repo
+-h show this help
+-l list repos
+-e edit repos in $EDITOR
+EOF
+}
+
+# fetch repository prettily, outputs nothing if failed
+fetch() {
+ # fetch with one-line printing of progress
+ git fetch --progress 2>/dev/null | while read -r line
+ # \r\033[0K : clear current line
+ do >&2 printf '\r\033[0K%s' "$line"
+ done
+}
+
+# Print repositories prettily
+# This function function prints animations (eg. clearing the line)
+# to stderr and the final status line is outputted to stdout.
+status() {
+ while read -r repo
+ do
+ repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@" )"
+
+ # absolute path
+ cd "$repo"
+
+ # replace line with status
+ >&2 printf '\r\033[0K'
+
+ status="$(git status --porcelain 2> /dev/null | awk '{print $1}' | uniq | tr -d '\n')"
+ remote="$(git branch -v 2>/dev/null | sed 's/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')"
+
+ printf '%s %s %s\n' "$repo_pretty" "$status" "$remote"
+ done < "$repos"
+}
+
+# run git command in each repo
+# $1: command
+repos_cmd() {
+ while read -r repo
+ do
+ repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@" )"
+ printf ''\''%s'\'' in %s' "$1" "$repo_pretty"
+ (
+ cd "$repo"
+ git "$1" > /dev/null 2>&1
+ [ $? -gt 0 ] && s="x" || s="o"
+ printf '\r\033[0K%s: %s\n' "$repo_pretty" "$s"
+ )
+ done < "$repos"
+}
+
+# no options
+if [ -z "$1" ]
+then
+ help
+ exit 1
+fi
+
+while getopts ":a:c:f:lshe" opt
+do
+ case "$opt" in
+ a)
+ cd "$OPTARG" || exit 1
+ r="$(git rev-parse --show-toplevel)"
+ [ "$r" ] || exit 2
+
+ if grep "$r" "$repos" > /dev/null 2>&1
+ then
+ >&2 printf 'added already.\n'
+ exit 2
+ fi
+
+ printf '%s\n' "$r" >> "$repos"
+
+ >&2 printf 'added.\n' ;;
+ c) repos_cmd "$OPTARG" ;;
+ s) status=1 ;;
+ l) cat "$repos" ;;
+ e) $EDITOR "$repos" ;;
+ f) repos="$OPTARG" ;;
+ T) help ;;
+ :) >&2 printf -- '-%s requires argument\n' "$OPTARG"; exit 1 ;;
+ ?) >&2 printf -- 'Invalid option: -%s\n' "$OPTARG"; exit 1 ;;
+ esac
+done
+
+if [ "$status" ]
+then
+ status
+ which herbe > /dev/null 2>&1 &&
+ eval "herbe $(status | sed 's/"/\"/g;s/.*/"&"/' | tr '\n' ' ')" &
+fi
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
diff --git a/config/essentials/shell/aliases.sh b/config/essentials/shell/aliases.sh
index fdd9d17..ddc605a 100644
--- a/config/essentials/shell/aliases.sh
+++ b/config/essentials/shell/aliases.sh
@@ -164,9 +164,6 @@ alias wtip='wt ip -c -brief addr'
alias fusephone='sshfs myphone: /media/phone'
alias ttyper='ttyper -l english1000'
-alias wgup='doas wg-quick up wg0'
-alias wgdown='doas wg-quick down wg0'
-
# NPM
alias npi="npm init --yes"
diff --git a/config/essentials/shell/functions.sh b/config/essentials/shell/functions.sh
index 8e51135..1b69fbd 100644
--- a/config/essentials/shell/functions.sh
+++ b/config/essentials/shell/functions.sh
@@ -306,7 +306,7 @@ gdown () {
}
# toggle wireguard vpn on $1 -> interface
-wgtoggle() {
+wgt() {
d="${1:-wg0}"
ip -br a | awk '{print $1}' | grep "$d" > /dev/null &&
doas wg-quick down "$d" ||
diff --git a/config/essentials/vis/plugins/vis-snippets/init.lua b/config/essentials/vis/plugins/vis-snippets/init.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/config/essentials/vis/plugins/vis-snippets/init.lua
diff --git a/config/essentials/vis/visrc.lua b/config/essentials/vis/visrc.lua
index a424613..1813888 100644
--- a/config/essentials/vis/visrc.lua
+++ b/config/essentials/vis/visrc.lua
@@ -5,6 +5,7 @@
require('vis')
require('plugins/vis-cursors')
require('plugins/vis-title')
+require('plugins/vis-snippets')
------------------------------------
--- EVENTS