summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-07-01 01:14:59 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-07-01 01:14:59 +0200
commite1de506156454ba1d324faf548ad15fe804aa806 (patch)
tree1ca249b22bace59d41e950b7482443440ccc8c5e /bin
parentfecb6306631aaec1774497093b7da44ab5950d92 (diff)
parentb2077bbddf86dbdbf6cc63aaf2ceb8a2da614ebc (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'bin')
-rwxr-xr-xbin/common/askpass8
-rwxr-xr-xbin/common/gt142
-rwxr-xr-xbin/extra/clock19
-rwxr-xr-xbin/extra/myalscore.sh3
-rwxr-xr-xbin/extra/ntfy15
-rwxr-xr-xbin/extra/wd24
-rwxr-xr-xbin/guiscripts/osurf-fill49
-rwxr-xr-xbin/guiscripts/osurf-txt5
-rwxr-xr-xbin/guiscripts/stplumb29
-rwxr-xr-xbin/guiscripts/sturl11
-rwxr-xr-xbin/menuscripts/pomo101
11 files changed, 227 insertions, 179 deletions
diff --git a/bin/common/askpass b/bin/common/askpass
index 2725dbf..c7d2249 100755
--- a/bin/common/askpass
+++ b/bin/common/askpass
@@ -3,11 +3,15 @@
# We can figure out the password for the key based on $1
# which is in the following form:
# Enter passphrase for key 'path/to/key':
-# The point is to retrieve the path and use the final name of the key
-# find the according password.
+# The point is to retrieve the path where the filename is the name of
+# the key.
+# Then we can construct the path for pass and get the password.
key="$(printf '%s\n' "$1" |
cut -f 2 -d \' |
awk -F '/' '{print $NF}')"
pass="keys/$(hostname)/ssh/$key"
+# optional: add key to running ssh-agent
+keyadd "$key" &
+
pass show "$pass" | head -n 1
diff --git a/bin/common/gt b/bin/common/gt
index 5bcc7c3..c16623e 100755
--- a/bin/common/gt
+++ b/bin/common/gt
@@ -4,118 +4,128 @@
# dependencies:
# - git
-# - $EDITOR: -e
+# - $EDITOR: -e
repos=$HOME/sync/share/git-track.txt
# prevent file not found errors
touch "$repos" || exit 1
help() {
- >&2 cat <<EOF
+ cat >&2 <<EOF
usage: gt [OPTION]
-a PATH add repo
-s update and show status of each repo
--c COMMAND run 'git COMMAND' in each repo
+-c COMMAND run 'git COMMAND' in each repo
-h show this help
-l list repos
--e edit repos in $EDITOR
+-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
+ git fetch --progress 2>/dev/null | while read -r line; do # \r\033[0K : clear current line
+ printf >&2 '\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@~@" )"
+ while read -r repo; do
+ repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")"
- # absolute path
- cd "$repo"
+ if [ ! -d "$repo" ]; then
+ printf '%s missing\n' "$repo_pretty"
+ continue
+ fi
- # replace line with status
- >&2 printf '\r\033[0K'
+ # absolute path
+ cd "$repo"
- status="$(git status --porcelain 2> /dev/null | awk '{print $1}' | uniq | tr -d '\n')"
- remote="$(git branch -v 2>/dev/null |
- sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')"
+ # replace line with status
+ printf >&2 '\r\033[0K'
- printf '%s %s %s\n' "$repo_pretty" "$status" "$remote"
- done < "$repos"
+ status="$(git status --porcelain 2>/dev/null |
+ awk '{print $1}' |
+ sort | uniq | tr -s '?' |
+ tr -d '\n')"
+ remote="$(git branch -v 2>/dev/null |
+ sed '/^*/!d;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"
+ 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
+if [ -z "$1" ]; then
+ help
+ exit 1
fi
-while getopts ":a:c:f:lshe" opt
-do
+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) f_command=1; f_arg="$OPTARG" ;;
- s) f_status=1 ;;
- l) cat "$repos" ;;
- e) $EDITOR "$repos" ;;
- f) repos="$OPTARG" ;;
- h) help ;;
- :) >&2 printf -- '-%s requires argument\n' "$OPTARG"; exit 1 ;;
- ?) >&2 printf -- 'Invalid option: -%s\n' "$OPTARG"; exit 1 ;;
+ a)
+ cd "$OPTARG" || exit 1
+ r="$(git rev-parse --show-toplevel)"
+ [ "$r" ] || exit 2
+
+ if grep "$r" "$repos" >/dev/null 2>&1; then
+ printf >&2 'added already.\n'
+ exit 2
+ fi
+
+ printf '%s\n' "$r" >>"$repos"
+
+ printf >&2 'added.\n'
+ ;;
+ c)
+ f_command=1
+ f_arg="$OPTARG"
+ ;;
+ s) f_status=1 ;;
+ l) cat "$repos" ;;
+ e) $EDITOR "$repos" ;;
+ f) repos="$OPTARG" ;;
+ h) help ;;
+ :)
+ printf >&2 -- '-%s requires argument\n' "$OPTARG"
+ exit 1
+ ;;
+ ?)
+ printf >&2 -- 'Invalid option: -%s\n' "$OPTARG"
+ exit 1
+ ;;
esac
done
# commands hereafter must happen in order
-[ "$(wc -l < "$repos")" -gt 0 ] || exit 0
+[ "$(wc -l <"$repos")" -gt 0 ] || exit 0
-if [ "$f_command" ]
-then
+if [ "$f_command" ]; then
repos_cmd "$f_arg"
-fi
+fi
-if [ "$f_status" ]
-then
- status
+if [ "$f_status" ]; then
+ status
fi
# eval "herbe $(status | sed 's/"/\"/g;s/.*/"&"/' | tr '\n' ' ')"
diff --git a/bin/extra/clock b/bin/extra/clock
index bd6efd2..6c5bfe0 100755
--- a/bin/extra/clock
+++ b/bin/extra/clock
@@ -1,12 +1,25 @@
#!/bin/sh
-clocks="${XDG_DATA_HOME:-$HOME}"/clocks.csv
+clocks="$HOME"/sync/share/clocks.csv
-if [ ! -f "$clocks" ]
-then
+# Create csv file with headers if not exist
+[ -f "$clocks" ] ||
printf 'start,end,message\n' > "$clocks"
+
+
+if [ "$1" = "-h" ]
+then
+ >&2 cat <<EOF
+usage: clock [OPTION]
+-h shows this help
+-p print clockings prettily
+
+With no option it will start clocking and prompt for a task.
+EOF
+ exit 1
fi
+
# print clocks file prettily
if [ "$1" = "-p" ]
then
diff --git a/bin/extra/myalscore.sh b/bin/extra/myalscore.sh
index ef68bcc..e2b4e25 100755
--- a/bin/extra/myalscore.sh
+++ b/bin/extra/myalscore.sh
@@ -4,4 +4,5 @@
query="$(printf '%s' "$*" | sed 's/\s/%20/g')"
curl -s "https://myanimelist.net/search/prefix.json?type=all&keyword=$query&v=1" \
-H 'Accept: application/json, text/javascript, */*; q=0.01' |
- jq -r '.categories[].items[] | [.payload.score, .name] | join(" ")'
+ jq -r '.categories[].items[] | "\(.payload.score)@\(.name)@\(.url)"' |
+ column -t -l 3 -s '@'
diff --git a/bin/extra/ntfy b/bin/extra/ntfy
new file mode 100755
index 0000000..0522499
--- /dev/null
+++ b/bin/extra/ntfy
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+which jq > /dev/null || exit 1
+
+[ "$1" ] || exit 1
+
+curl -s -N "http://debuc.com:32336/$1/json?since=60m" |
+while read -r notification
+do
+ s="$(printf '%s' "$notification" | jq -r -c '"\(.title)@@@@@\(.message)"')"
+ message="${s#*@@@@@}"
+ title="${s%%@@@@@*}"
+ [ "$message" = "null" ] && [ "$title" = "null" ] && continue
+ herbe "$title" "$message" &
+done
diff --git a/bin/extra/wd b/bin/extra/wd
index 73bbaf7..1b56aa6 100755
--- a/bin/extra/wd
+++ b/bin/extra/wd
@@ -1,16 +1,14 @@
#!/bin/sh
+[ "$1" ] || exit 1
+dict "$1" |
+ sed -e '/^ /!d;s/^ //' |
+ sed -e '/^$/d;s/^[^ ].*$/\o033[1;4;34m&\o033[0m/' |
-### Word Definition
-# Based on https://askubuntu.com/questions/191125/is-there-an-offline-command-line-dictionary
-#
-### Installation
-# > sudo mkdir -p /usr/share/stardict/dic/
-## Get the dictionaries
-# > wget https://web.archive.org/web/20140428003644/http://abloz.com/huzheng/stardict-dic/dict.org/stardict-dictd_www.dict.org_gcide-2.4.2.tar.bz2
-# > wget https://web.archive.org/web/20140428004049/http://abloz.com/huzheng/stardict-dic/misc/stardict-xfardic-gnu-linux-2.4.2.tar.bz2
-## Other dictionaries I'd like to get
-# https://foldoc.org/scalar
+ # foldoc
+ sed -e '/^ /s/</\o033[2m/g' -e '/^ /s/>/\o033[0m/g' |
-sdcv -nj "$1" |
- jq -r '.[].definition' |
- sed -e '/^$/d;s/^[^ ].*$/\o033[1;4;38m&\o033[0m/'
+ # webster
+ sed -r -e 's/ \\\<\w+\>\\//g' -e '/^ *\[[^]]*Webster[^]]*\]/d' |
+ # replace {} by blue underline
+ sed -e '/^ /s/{/\o033[4m/g' -e '/^ /s/}/\o033[0m/g' |
+ tr -d '{}' # remove {} in word definition
diff --git a/bin/guiscripts/osurf-fill b/bin/guiscripts/osurf-fill
index 43af807..52a410d 100755
--- a/bin/guiscripts/osurf-fill
+++ b/bin/guiscripts/osurf-fill
@@ -1,10 +1,11 @@
#!/bin/sh
-# Fills a password for a given website
+# 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
+printf '\n\n'
# dependencies:
# - surf fifo patch (http://surf.suckless.org/patches/fifo/)
@@ -13,10 +14,9 @@
# $1: winid
-fifodir="$HOME/.config/surf/fifo"
-if [ -z "${winid:=$1}" ]
-then
- winid="$(osurfls | dmenu -c -F -i | cut -f1 -d' ')"
+fifodir="$HOME/.config/surf/fifo"
+if [ -z "${winid:=$1}" ]; then
+ winid="$(osurfls | dmenu -c -F -i | cut -f1 -d' ')"
fi
[ "$winid" ] || exit 1
fifo="$fifodir/$winid"
@@ -24,26 +24,24 @@ fifo="$fifodir/$winid"
# Get only domain name + top-level domain
url="$(xprop -id "$winid" _SURF_URI |
- cut -f 2 -d'"' |
- sed 's,^.*://\([^/]*\)/.*,\1,' |
- sed -r -e 's/^([^.]+)\.([^.]+)\.([^.]+)$/\2.\3/')"
+ cut -f 2 -d'"' |
+ sed 's,^.*://\([^/]*\)/.*,\1,' |
+ sed -r -e 's/^([^.]+)\.([^.]+)\.([^.]+)$/\2.\3/')"
[ "$url" ] || exit 3
->&2 printf 'url: %s\n' "$url"
+printf >&2 '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)"
+ 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}"
- while [ -d "$store/$file" ]
- do
+if [ -z "$pass" ]; then
+ store="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
+ while [ -d "$store/$file" ]; do
choice="$(find "$store/$file" \
-maxdepth 1 -mindepth 1 \
-not -name '.*' -type d -printf "%y\t%f\n" -o \
@@ -56,22 +54,24 @@ then
done
pass="$file"
fi
->&2 printf 'pass: %s\n' "$pass"
+printf >&2 '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")"
+ 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'
+ # The string will be inside double quotes
+ # we need to add 2 backslashes, one for shell (heredoc) and one for javascript
+ printf '%s' "$1" | sed -s 's,["\\],\\\\&,g'
}
js() {
-cat <<EOF
+ cat <<EOF
function isVisible(elem) {
var style = elem.ownerDocument.defaultView.getComputedStyle(elem, null);
if (style.getPropertyValue("visibility") !== "visible" ||
@@ -99,15 +99,12 @@ cat <<EOF
input.focus();
input.value = "$(javascript_escape "$username")";
input.blur();
- console.log("user: $(javascript_escape "$username")")
}
if (input.type == "password" || input.name == "password" || input.autocomplete == "password" || input.id == "password" ) {
input.focus();
input.value = "$(javascript_escape "$password")";
input.blur();
- console.log("password: $(javascript_escape "$password")")
}
- console.log(input)
}
};
var forms = document.getElementsByTagName("form");
@@ -121,7 +118,7 @@ EOF
}
printjs() {
- js | sed 's,//.*$,,' | tr '\n' ' '
+ js | sed 's,//.*$,,' | tr '\n' ' '
}
-echo "inject $(printjs)" >> "$fifo"
+echo "inject $(printjs)" >>"$fifo"
diff --git a/bin/guiscripts/osurf-txt b/bin/guiscripts/osurf-txt
index 9a1d4f4..a544f85 100755
--- a/bin/guiscripts/osurf-txt
+++ b/bin/guiscripts/osurf-txt
@@ -13,6 +13,7 @@ f="$(find "$tabs" -type f -printf '%f\n' | dmenu -c)"
f="$tabs"/"$f"
>&2 printf 'f: %s\n' "$f"
-url="$(dmenu -c < "$f")"
+url="$(dmenu -x -c < "$f")"
+[ "$url" ] || exit 1
-printf 'loaduri %s' "$url" > $HOME/.config/surf/fifo/$winid
+printf 'loaduri %s\n' "$url" > $HOME/.config/surf/fifo/$winid
diff --git a/bin/guiscripts/stplumb b/bin/guiscripts/stplumb
new file mode 100755
index 0000000..1898bd1
--- /dev/null
+++ b/bin/guiscripts/stplumb
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+select_link() {
+ regex='(((file|https?|gopher|gemini|ftps?|git)://|www\.)[a-zA-Z0-9.]*[:;!a-zA-Z0-9./+@$&%?$\#=_~-]*)|(magnet:\?xt=urn:btih:[a-zA-Z0-9]*)'
+ tr -d '\n' | grep -Eo "$regex" | dmenu -n -x -c
+}
+
+case $1 in
+'copylink')
+ url="$(select_link)"
+ [ "$url" ] || exit 1
+ printf '%s' "$url" | clipp
+ ;;
+'open')
+ url="$(select_link)"
+ [ "$url" ] || exit 1
+ lh "$url"
+ ;;
+'copypath')
+ path="$(grep -Eo -e '/([^/ ](/?)+)+' -e '[^ /]+/+([^ /]+(/?)+)*' |
+ sort | uniq | dmenu -n -x -c)"
+ [ "$path" ] || exit 1
+ printf '%s' "$path" | clipp
+ ;;
+*)
+ echo "no option"
+ exit 1
+ ;;
+esac
diff --git a/bin/guiscripts/sturl b/bin/guiscripts/sturl
deleted file mode 100755
index 2712d92..0000000
--- a/bin/guiscripts/sturl
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-regex='(((file|https?|gopher|gemini|ftps?|git)://|www\.)[a-zA-Z0-9.]*[:;!a-zA-Z0-9./+@$&%?$\#=_~-]*)|(magnet:\?xt=urn:btih:[a-zA-Z0-9]*)'
-url="$(tr -d '\n' | grep -Eo "$regex" | commander -xcl)"
-[ -z "$url" ] && exit 1
-
-case $1 in
- 'c') printf '%s' "$url" | clipp ;;
- 'o') lh "$url" ;;
- *) echo "no option" ;;
-esac
diff --git a/bin/menuscripts/pomo b/bin/menuscripts/pomo
index e8795e7..eb4c30b 100755
--- a/bin/menuscripts/pomo
+++ b/bin/menuscripts/pomo
@@ -1,78 +1,69 @@
#!/bin/sh
### FUNCTIONS
-notif() {
- herbe "pomo" "$1" &
- sleep 1
- pkill -SIGUSR1 herbe
+notif() {
+ herbe "pomo" "$1" &
+ sleep 1
+ pkill -SIGUSR1 herbe
}
-logn () { >&2 printf '%s\n' "$@"; }
-log () { >&2 printf '%s' "$@"; }
# Plays ringing sound
# Then wait for user input to start/end the break
-player_command()
-{
- >&2 printf ' > '
+player_command() {
+ printf >&2 ' > '
[ -r "$ringSound" ] || PLAYER=""
case "$PLAYER" in
- mpv) mpv --loop --msg-level=all=no "$ringSound" ;;
- "") head -n 1;;
- *) $PLAYER "$ringSound" ;;
+ mpv) mpv --loop --msg-level=all=no "$ringSound" ;;
+ "") head -n 1 ;;
+ *) $PLAYER "$ringSound" ;;
esac
}
# $1: time in minutes
# $2: msg for notification
-ring_ring()
-{
- logn "$(date '+%R') B $round"
+ring_ring() {
+ printf >&2 '%s B %s\n' "$(date '+%R')" "$round"
player_command
- herbe "pomo" "$2" &
- sleep "${1}m"
+ herbe "pomo" "$2" &
+ sleep "${1}m"
player_command
- >&2 printf '\n'
+ printf >&2 '\n'
}
-### PROGRAM
-main()
-{
- round="${1-0}"
- case "$round" in
- 0|1|2|3) ;;
- ring) ;;
- *) logn "Invalid \$round value." && exit 1 ;;
- esac
+### Program
- ringSound="${XDG_DATA_HOME:-$HOME/.local/share}"/pomo/ring.aac
- [ -r "$ringSound" ] && logn "ring: $ringSound"
+trap 'exit 1' INT
- if [ "$1" = "ring" ]
- then
- player_command
- exit
- fi
+round="${1:-0}"
+# args
+case "$round" in
+0 | 1 | 2 | 3) ;;
+ring) ;;
+*) printf >&2 'Invalid value: %s\n' "$round"; exit 1 ;;
+esac
- # Countdown
- for msg in "three" "two" "one"
- do notif "$msg"
- done
+ringSound="${XDG_DATA_HOME:-$HOME/.local/share}"/pomo/ring.aac
+[ -r "$ringSound" ] && printf >&2 'ring: %s\n' "$ringSound"
- while true
- do
- notif "START"
- logn "$(date '+%R') S $round"
- sleep 25m
- if [ "$round" -eq 3 ]
- then
- ring_ring 20 "GIGA BREAK TIME"
- round=0
- else
- ring_ring 5 "BREAK TIME"
- round=$((round+1))
- fi
- done
-}
+if [ "$1" = "ring" ]; then
+ player_command
+ exit
+fi
-trap 'exit 1' INT
-main "$@"
+# Countdown
+for msg in "three" "two" "one"; do
+ notif "$msg"
+done
+
+while true; do
+ notif "START"
+ printf >&2 '%s S %s\n' "$(date '+%R')" "$round"
+ sleep 25m
+ if [ "$round" -eq 3 ]; then
+ ring_ring 20 "GIGA BREAK TIME"
+ round=0
+ else
+ ring_ring 5 "BREAK TIME"
+ round=$((round + 1))
+ fi
+done