diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/common/gt | 111 | ||||
-rwxr-xr-x | bin/extra/aivpn | 30 | ||||
-rwxr-xr-x | bin/extra/ytplay | 2 | ||||
-rwxr-xr-x | bin/guiscripts/osurf-fill | 22 | ||||
-rwxr-xr-x | bin/guiscripts/osurftxt | 28 | ||||
-rwxr-xr-x | bin/guiscripts/osurftxts | 22 | ||||
-rwxr-xr-x | bin/menuscripts/mpass-otp | 2 |
7 files changed, 195 insertions, 22 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/extra/aivpn b/bin/extra/aivpn new file mode 100755 index 0000000..841d926 --- /dev/null +++ b/bin/extra/aivpn @@ -0,0 +1,30 @@ +#!/bin/sh + +err() { printf "%s\n" "$@"; } + +if [ "$1" = "-k" ] +then + pgrep -f -- "ssh.*-L.*vm" | xargs kill + exit +fi + +err "I: Waiting for connectivity..." +while ! ssh -o ConnectTimeout=1 -o BatchMode=yes vm 2>&1 | grep "Permission denied" > /dev/null +do sleep 1 +done + + +export SSH_ASKPASS="sshpass" +export SSH_ASKPASS_REQUIRE="prefer" +export PASSWORD="zot/quickemu" + +err "I: Activating vpn" +ssh vm "rasdial \"vpn.student.ehb.be\"" + +keyadd ehb/ai +ssh -f -N -L 2222:10.2.160.41:22 vm + +keyadd ehb/vm_int +ssh -f -N -L 2223:10.2.160.9:22 vm +ssh -f -N -L 2224:10.2.160.10:22 vm +ssh -f -N -L 2225:10.2.160.11:22 vm diff --git a/bin/extra/ytplay b/bin/extra/ytplay index 66204c4..5243364 100755 --- a/bin/extra/ytplay +++ b/bin/extra/ytplay @@ -1,4 +1,4 @@ #!/bin/sh url="$(ytlink)" -notify-send "playing: $url" & +herbe "playing: $url" & yt-dlp -o - "$url" | mpv - 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/bin/menuscripts/mpass-otp b/bin/menuscripts/mpass-otp index 52d1341..2be6186 100755 --- a/bin/menuscripts/mpass-otp +++ b/bin/menuscripts/mpass-otp @@ -1,7 +1,7 @@ #!/bin/sh pass="$(find "$PASSWORD_STORE_DIR"/keys/otp -iname "*.gpg" | sed "/^\./d;s#^$PASSWORD_STORE_DIR/keys/otp/##;s/\.gpg$//" | - commander -c)" + dmenu -c)" [ "$pass" ] || exit 1 pass otp -c keys/otp/"$pass" notify-send -t 1000 "mpass" "copied $pass" |