summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-16 16:16:11 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-16 16:16:11 +0200
commit2dab2233ef9cb54a3878e0120016d542045c7ee8 (patch)
tree13f3f086adbe5edca4b0c6d3527bd040a50f627a
parent2a9d0908651ac236855fa515e14a83bada3ad7f9 (diff)
checkpoint
-rwxr-xr-xbin/extra/trl4
-rw-r--r--bin/guiscripts/mega.sh67
-rwxr-xr-xbin/guiscripts/osurf2
-rwxr-xr-xbin/guiscripts/osurf-fill113
-rwxr-xr-xbin/guiscripts/osurfls8
-rwxr-xr-xbin/guiscripts/osurftabs12
-rwxr-xr-xbin/guiscripts/osurftxt22
-rwxr-xr-xbin/guiscripts/record86
-rwxr-xr-xbin/guiscripts/setbg5
-rwxr-xr-xbin/guiscripts/yt4
-rwxr-xr-xbin/menuscripts/tsh10
-rwxr-xr-xconfig/X/x11/xinitrc2
-rwxr-xr-xconfig/common/mpv/mpv.conf5
-rw-r--r--config/essentials/shell/aliases.sh1
-rw-r--r--config/essentials/shell/functions.sh7
-rw-r--r--config/essentials/zsh/.zshrc2
16 files changed, 339 insertions, 11 deletions
diff --git a/bin/extra/trl b/bin/extra/trl
index bd4c2c5..55d65ee 100755
--- a/bin/extra/trl
+++ b/bin/extra/trl
@@ -41,10 +41,10 @@ then
fi
[ "$word" ] || exit 1
-primary="$(languages | fzf)"
+primary="$(languages | fzf --prompt="from:")"
[ "$primary" ] || exit 1
-secondary="$(languages | fzf)"
+secondary="$(languages | fzf --prompt="to:")"
[ "$secondary" ] || exit 1
curl -s "https://context.reverso.net/translation/$primary-$secondary/$word" \
diff --git a/bin/guiscripts/mega.sh b/bin/guiscripts/mega.sh
new file mode 100644
index 0000000..cafca0a
--- /dev/null
+++ b/bin/guiscripts/mega.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+URL=""
+
+if [[ $1 =~ ^https?:\/\/mega(\.co)?\.nz ]]; then
+ URL="$1"
+fi
+
+if [[ ! $URL ]]; then
+ echo "Usage: ${0##*/} url" >&2
+ exit 1
+fi
+
+CURL="curl -Y 1 -y 10"
+
+missing=false
+for cmd in openssl; do
+ if [[ ! $(command -v "$cmd" 2>&1) ]]; then
+ missing=true
+ echo "${0##*/}: $cmd: command not found" >&2
+ fi
+done
+if $missing; then
+ exit 1
+fi
+
+if [[ $URL =~ .*/file/[^#]*#[^#]* ]]; then
+ id="${URL#*file/}"; id="${id%%#*}"
+ key="${URL##*file/}"; key="${key##*#}"
+else
+ id="${URL#*!}"; id="${id%%!*}"
+ key="${URL##*!}"
+fi
+
+raw_hex=$(echo "${key}=" | tr '\-_' '+/' | tr -d ',' | base64 -d -i 2>/dev/null | od -v -An -t x1 | tr -d '\n ')
+hex=$(printf "%016x" \
+ $(( 0x${raw_hex:0:16} ^ 0x${raw_hex:32:16} )) \
+ $(( 0x${raw_hex:16:16} ^ 0x${raw_hex:48:16} ))
+)
+
+json=$($CURL -s -H 'Content-Type: application/json' -d '[{"a":"g", "g":"1", "p":"'"$id"'"}]' 'https://g.api.mega.co.nz/cs?id=&ak=') || exit 1; json="${json#"[{"}"; json="${json%"}]"}"
+file_url="${json##*'"g":'}"; file_url="${file_url%%,*}"; file_url="${file_url//'"'/}"
+
+json=$($CURL -s -H 'Content-Type: application/json' -d '[{"a":"g", "p":"'"$id"'"}]' 'https://g.api.mega.co.nz/cs?id=&ak=') || exit 1
+at="${json##*'"at":'}"; at="${at%%,*}"; at="${at//'"'/}"
+
+json=$(echo "${at}==" | tr '\-_' '+/' | tr -d ',' | openssl enc -a -A -d -aes-128-cbc -K "$hex" -iv "00000000000000000000000000000000" -nopad | tr -d '\0'); json="${json#"MEGA{"}"; json="${json%"}"}"
+file_name="${json##*'"n":'}"
+if [[ $file_name == *,* ]]; then
+ file_name="${file_name%%,*}"
+fi
+file_name="${file_name//'"'/}"
+
+aria2c -x 15 -o "$file_name" "$file_url"
+cat "$file_name" | openssl enc -d -aes-128-ctr -K "$hex" -iv "${raw_hex:32:16}0000000000000000" > "temp.new"
+mv -f temp.new "$file_name"
+
+echo "$file_url"
+echo "$file_name"
+echo "$hex"
+echo "${raw_hex:32:16}0000000000000000"
+sleep 5
+echo "Downloading... (press Ctrl + C to Cancel)"
+
+aria2c -x 16 -s 16 -o "$file_name" "$file_url"
+cat "$file_name" | openssl enc -d -aes-128-ctr -K "$hex" -iv "${raw_hex:32:16}0000000000000000" > "temp.new"
+mv -f temp.new "$file_name"
diff --git a/bin/guiscripts/osurf b/bin/guiscripts/osurf
new file mode 100755
index 0000000..6923848
--- /dev/null
+++ b/bin/guiscripts/osurf
@@ -0,0 +1,2 @@
+#!/bin/sh
+tabbed -c -dn tabbed-surf -r 2 surf -e '' "$1"
diff --git a/bin/guiscripts/osurf-fill b/bin/guiscripts/osurf-fill
new file mode 100755
index 0000000..311c273
--- /dev/null
+++ b/bin/guiscripts/osurf-fill
@@ -0,0 +1,113 @@
+#!/bin/sh
+# bitwarden dmenu script - based off of the autofill userscript from qutebrowser
+# requires the fifo patch
+# $1: winid
+
+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"
+[ -p "$fifo" ] || exit 2
+
+url="$(xprop -id "$winid" _SURF_URI |
+ cut -f 2 -d'"' |
+ sed 's,^.*://\([^/]*\)/.*,\1,' |
+ sed -r -e 's/^([^.]+)\.([^.]+)\.([^.]+)$/\2.\3/')"
+[ "$url" ] || exit 3
+>&2 printf 'url: %s\n' "$url"
+
+
+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)"
+[ $? -gt 0 ] && exit 4
+
+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 \
+ -not -name '.*' -not -type d -printf "%y\t%f\n" |
+ sort -k1 -k2 |
+ cut -f 2 | sed 's/\.gpg$//' |
+ dmenu -c)"
+ [ "$choice" ] || exit 1
+ [ -z "$file" ] && file="$choice" || file="$file/$choice"
+ done
+ 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'
+eval "$(pass show "$pass" |
+ sed -n "1s/'/'\\\\''/g;1s/.*/password='&'/p;s/^login: \?\(.\+\)/username='\1'/p")"
+printf '%s : %s\n' "$username" "$password"
+
+javascript_escape() {
+ printf '%s' "$1" | sed -s 's,['\''"\\\\],\\\\&,g'
+}
+
+js() {
+cat <<EOF
+ function isVisible(elem) {
+ var style = elem.ownerDocument.defaultView.getComputedStyle(elem, null);
+ if (style.getPropertyValue("visibility") !== "visible" ||
+ style.getPropertyValue("display") === "none" ||
+ style.getPropertyValue("opacity") === "0") {
+ return false;
+ }
+ return elem.offsetWidth > 0 && elem.offsetHeight > 0;
+ };
+ function hasPasswordField(form) {
+ var inputs = form.getElementsByTagName("input");
+ for (var j = 0; j < inputs.length; j++) {
+ var input = inputs[j];
+ if (input.type == "password" || input.autocomplete == "password" || input.name == "password") {
+ return true;
+ }
+ }
+ return false;
+ };
+ function loadData2Form (form) {
+ var inputs = form.getElementsByTagName("input");
+ for (var j = 0; j < inputs.length; j++) {
+ var input = inputs[j];
+ if (isVisible(input) && (input.type == "text" || input.type == "email")) {
+ 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");
+ for (i = 0; i < forms.length; i++) {
+ if (hasPasswordField(forms[i])) {
+ loadData2Form(forms[i]);
+ // forms[i].submit();
+ }
+ }
+EOF
+}
+
+printjs() {
+ js | sed 's,//.*$,,' | tr '\n' ' '
+}
+
+echo "inject $(printjs)" >> "$fifo"
diff --git a/bin/guiscripts/osurfls b/bin/guiscripts/osurfls
new file mode 100755
index 0000000..0abdd35
--- /dev/null
+++ b/bin/guiscripts/osurfls
@@ -0,0 +1,8 @@
+#!/bin/sh
+find "$HOME/.config/surf/fifo" -type p -printf '%f\n' |
+while read -r winid
+do
+ title="$(xprop -id "$winid" 2> /dev/null | awk -F'"' '/^_NET_WM_NAME/ {print $2}')"
+ [ "$title" ] || continue
+ printf '%s %s\n' "$winid" "$title"
+done \ No newline at end of file
diff --git a/bin/guiscripts/osurftabs b/bin/guiscripts/osurftabs
new file mode 100755
index 0000000..d41424b
--- /dev/null
+++ b/bin/guiscripts/osurftabs
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# list surf tabbed windows
+
+# dependencies: lsw, dmenu, xprop
+# expects the tabbed windows to be named 'tabbed-surf'
+lsw | cut -f1 -d' ' |
+ while read -r winid
+ do
+ [ "tabbed-surf" = "$(xprop -id "$winid" WM_CLASS | cut -f2 -d'"')" ] &&
+ printf '%s %s\n' "$winid" "$(xprop -id "$winid" WM_NAME | cut -f2 -d'"')"
+ done
diff --git a/bin/guiscripts/osurftxt b/bin/guiscripts/osurftxt
new file mode 100755
index 0000000..ef60166
--- /dev/null
+++ b/bin/guiscripts/osurftxt
@@ -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/guiscripts/record b/bin/guiscripts/record
new file mode 100755
index 0000000..778e02e
--- /dev/null
+++ b/bin/guiscripts/record
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# record - record an area of the screen
+
+lock="/tmp/record.lock"
+
+# dependencies: ffmpeg, hacksaw (part), xwininfo & lsw (window), xdotool (active)
+# optional:
+# - hacksaw: part
+# - xwininfo, lsw, commander: window
+# - xdotool: active
+# - xdg-user-dir
+
+# $1: width
+# $2: height
+# $3: x
+# $4: y
+# $5: output dir
+# $6: output name
+record_cmd()
+{
+ if [ -f "$lock" ]
+ then
+ >&2 printf 'already recording, please stop recording first\n'
+ exit 1
+ else
+ touch "$lock"
+ fi
+
+ herbe "started recording." &
+ w=$(($3 + $3 % 2))
+ h=$(($4 + $4 % 2))
+ ffmpeg \
+ -v 16 \
+ -r 30 \
+ -f pulse -ac 2 -i default \
+ -f x11grab \
+ -s "${w}x${h}" \
+ -i ":0.0+$1,$2" \
+ -preset slow \
+ -c:v h264 \
+ -pix_fmt yuv420p \
+ -crf 20 \
+ "$5/$6.mp4"
+ printf '%s\n' "$5/$6.mp4"
+ rm -f "$lock"
+ herbe "stopped recording." &
+}
+
+if [ -d "$1" ]
+then
+ dir="$1"
+ shift
+else
+ dir="$(which xdg-user-dir > /dev/null 2>&1 && xdg-user-dir VIDEOS)"
+ [ "$dir" ] && dir="$dir/records" || dir="$HOME/vids/records"
+fi
+mkdir -p "$dir"
+
+current=$(date +%F_%H-%M-%S)
+
+[ "$1" ] && option="$1" || option="$(printf 'active\nwindow\npart\nstop\nfull\n' | commander -c)"
+case "$option" in
+ active)
+ record_cmd $(xwininfo -id "$(xdotool getactivewindow)" |
+ sed -e '/Absolute\|Width:\|Height:/!d;s/.*:\s*//' | tr '\n' ' ') $dir $current
+ ;;
+
+ window)
+ winid="$(lsw | commander -cxl | cut -d' ' -f1)"
+ [ "$winid" ] || exit 1
+ values="$(xwininfo -id "$winid" | sed -e '/Absolute\|Width:\|Height:/!d;s/.*:\s*//' | tr '\n' ' ')"
+ [ "$values" ] || exit 1
+ record_cmd $values $dir $current
+ ;;
+
+ part)
+ hacksaw | {
+ IFS=+x read -r w h x y
+ record_cmd $w $h $x $y $dir $current
+ }
+ ;;
+ stop) kill "$(pgrep ffmpeg | xargs ps | grep 'x11grab' | awk '{print $1}')"; rm -f "$lock" ;;
+ full) record_cmd 0 0 1920 1080 $dir $current ;;
+ help|*) >&2 printf 'record [dir] (active|window|part|stop|full)\n' ;;
+esac
diff --git a/bin/guiscripts/setbg b/bin/guiscripts/setbg
new file mode 100755
index 0000000..a4109ab
--- /dev/null
+++ b/bin/guiscripts/setbg
@@ -0,0 +1,5 @@
+#!/bin/sh
+cd "$HOME/pics/wallpapers" || exit 1
+bg="$(find . -type f -printf '%f\n' | sed 's@^\./@@' | dmenu -c -x)"
+[ "$bg" ] || exit 1
+feh --no-fehbg --bg-scale "$bg"
diff --git a/bin/guiscripts/yt b/bin/guiscripts/yt
new file mode 100755
index 0000000..72f6e92
--- /dev/null
+++ b/bin/guiscripts/yt
@@ -0,0 +1,4 @@
+#!/bin/sh
+link="$(ytfzf -D -I l)"
+[ "$link" ] || exit 1
+yt-dlp $@ -o - "$link" | mpv -
diff --git a/bin/menuscripts/tsh b/bin/menuscripts/tsh
index aac27ee..70e7ca8 100755
--- a/bin/menuscripts/tsh
+++ b/bin/menuscripts/tsh
@@ -5,8 +5,8 @@ PROG="$(basename "$0")"
# copy command and deps variable
deps="pup curl $MENUCMD"
-LIBPFX=/home/aluc/.local/share/tsh
-module='1337x.sh' # default module
+MODULES_PATH=$HOME/.local/share/tsh
+module='nyaa.sh' # default module
# Files
export tmp="/tmp/$PROG"
@@ -83,7 +83,7 @@ cleanup ()
done
}
-list_modules () { find -L "$LIBPFX" -type f -printf "%f\n"; }
+list_modules () { find -L "$MODULES_PATH" -type f -printf "%f\n"; }
# get a query from user based on MENUCMD
get_query ()
@@ -179,7 +179,7 @@ then
# Get results
rm -f "$results" "$links"
# shellcheck source=/usr/local/lib/$PROG/nyaa.sh disable=SC1091
- . "$LIBPFX/$module"
+ . "$MODULES_PATH/$module"
[ -f "$results" ] || die "No results."
# Save which module was used
@@ -190,7 +190,7 @@ fi
# acquire get_magnet function
# shellcheck source=/usr/local/lib/$PROG/nyaa.sh disable=SC1091
-getfunctions=1 . "$LIBPFX/$module"
+getfunctions=1 . "$MODULES_PATH/$module"
# select result from "$results"
for choice in $(select_result | xargs)
diff --git a/config/X/x11/xinitrc b/config/X/x11/xinitrc
index bc1824a..8b3cf2b 100755
--- a/config/X/x11/xinitrc
+++ b/config/X/x11/xinitrc
@@ -22,7 +22,7 @@ export MENUCMD="dmenu"
export IMAGE="feh"
xcompmgr &
feh --no-fehbg --bg-scale ~/pics/wallpaper
-setxkbmap us -option ctrl:swapcaps,altwin:menu_win -variant colemak
+setxkbmap colemak -option ctrl:swapcaps,altwin:menu_win
# xautolock -locker slock &
gammastep -m randr &
# dunst &
diff --git a/config/common/mpv/mpv.conf b/config/common/mpv/mpv.conf
index 1fd96da..2e7318e 100755
--- a/config/common/mpv/mpv.conf
+++ b/config/common/mpv/mpv.conf
@@ -17,10 +17,11 @@ ytdl-raw-options=extractor-args="youtube:player-client=android"
# Default demuxer is 150/75 MB, note that this uses RAM so set a reasonable amount.
# 150MB, Max pre-load for network streams (1 MiB = 1048576 Bytes).
-demuxer-max-bytes=150000000
+demuxer-max-bytes=150MiB
+demuxer-readahead-secs=20
# 75MB, Max loaded video kept after playback.
-demuxer-max-back-bytes=75000000
+demuxer-max-back-bytes=75MiB
# Force stream to be seekable even if disabled.
force-seekable=yes
diff --git a/config/essentials/shell/aliases.sh b/config/essentials/shell/aliases.sh
index a8b9036..be35a6c 100644
--- a/config/essentials/shell/aliases.sh
+++ b/config/essentials/shell/aliases.sh
@@ -339,6 +339,7 @@ alias ddeps='pactree -r -d 1'
alias update-mirrors='reflector -p https | rankmirrors -n 10 -p -w - | doas tee /etc/pacman.d/mirrorlist'
alias tmpd='cd $(mktemp -d)'
+alias tmpf='$EDITOR $(mktemp)'
alias brs='$BROWSER'
which bat > /dev/null 2>&1 &&
alias cat="bat -p"
diff --git a/config/essentials/shell/functions.sh b/config/essentials/shell/functions.sh
index b69b775..945b716 100644
--- a/config/essentials/shell/functions.sh
+++ b/config/essentials/shell/functions.sh
@@ -241,6 +241,7 @@ pacsize()
mime-default ()
{
+ mime=
[ "${mime:=$1}" ] ||
mime="$(find /usr/share/applications/ -iname '*.desktop' -printf '%f\n' |
sed 's/\.desktop$//' |
@@ -364,3 +365,9 @@ ssh_port()
ssh -f -N -L 0.0.0.0:"$3":localhost:"$1" "$2"
>&2 printf "Forwarded port '%s' on '%s' to '%s'.\n" "$1" "$2" "$3"
}
+ffconcat () {
+ tmp=$(mktemp -p . ffconcat.XXXXX)
+ sed 's/.*/file &/' > "$tmp"
+ ffmpeg -y -f concat -safe 0 -i $tmp -c copy "$1"
+ rm $tmp
+}
diff --git a/config/essentials/zsh/.zshrc b/config/essentials/zsh/.zshrc
index 545f9cc..6bd948a 100644
--- a/config/essentials/zsh/.zshrc
+++ b/config/essentials/zsh/.zshrc
@@ -58,7 +58,7 @@ fi
# Add nnn shell level to prompt
-[ -n "$NNNLVL" ] && PS1="N$NNNLVL $PS1"
+[ -n "$NNNLVL" ] && PS1="N$NNNLVL$PS1"
# cd on nnn quiting
nnn_cd ()