summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/common/gt24
-rwxr-xr-xbin/common/gt-st8
-rwxr-xr-xbin/extra/trl33
-rwxr-xr-xbin/guiscripts/dmfm22
-rwxr-xr-xbin/menuscripts/mmedia91
-rwxr-xr-xbin/menuscripts/tsh275
6 files changed, 202 insertions, 251 deletions
diff --git a/bin/common/gt b/bin/common/gt
index 48321af..477adfc 100755
--- a/bin/common/gt
+++ b/bin/common/gt
@@ -6,6 +6,7 @@
# - git
# - $EDITOR: -e
# - parallel: optional, if installed will run the commands on all repos with parallel
+# - gt-[cmd,st,sync]
repos=$HOME/sync/share/git-track.txt
# prevent file not found errors
@@ -36,17 +37,6 @@ fetch() {
done
}
-sync_status() {
- if [ "$parallel" ]; then
- parallel --colsep ' ' gt-sync {1} {2} <"$repos"
- else
- IFS=' '
- while read -r repo remote_url; do
- gt-sync "$repo" "$remote_url"
- done <"$repos"
- fi
-}
-
# no options
if [ -z "$1" ]; then
help
@@ -55,7 +45,7 @@ fi
[ "$(wc -l <"$repos")" -gt 0 ] || exit 0
-while getopts ":a:c:f:lsheuy" opt; do
+while getopts ":a:c:f:lsheu" opt; do
case "$opt" in
a)
if ! cd "$OPTARG" 2>/dev/null; then
@@ -84,12 +74,18 @@ while getopts ":a:c:f:lsheuy" opt; do
fi
;;
s) cut -f 1 -d ' ' "$repos" | xargs -I{} gt-st {} ;;
- y) sync_status ;;
l) cut -f 1 -d ' ' "$repos" ;;
e) $EDITOR "$repos" ;;
f) repos="$OPTARG" ;;
u)
- sync_status | awk -F ':' '/x$/ {print $1}' |
+ if [ "$parallel" ]; then
+ parallel --colsep ' ' gt-sync {1} {2} <"$repos"
+ else
+ IFS=' '
+ while read -r repo remote_url; do
+ gt-sync "$repo" "$remote_url"
+ done <"$repos"
+ fi | awk -F ':' '/x$/ {print $1}' |
if [ "$parallel" ]; then
parallel gt-cmd {} pull
else
diff --git a/bin/common/gt-st b/bin/common/gt-st
index 98184b9..43443cd 100755
--- a/bin/common/gt-st
+++ b/bin/common/gt-st
@@ -14,11 +14,15 @@ if [ ! -d "$repo" ]; then
fi
# replace line with status
-status="$(git -C "$repo" status --porcelain 2>/dev/null |
+status="$(git -C "$repo" status --porcelain 2>/dev/null |
awk '{print $1}' |
sort | uniq | tr -s '?' |
tr -d '\n')"
remote="$(git -C "$repo" branch -v 2>/dev/null |
sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')"
-printf '%s %s %s\n' "$repo_pretty" "$status" "$remote"
+if [ "$status" ] || [ "$remote" ]; then
+ printf '%s: \033[0;31m%s %s\033[0m\n' "$repo_pretty" "$status" "$remote"
+else
+ printf '%s\n' "$repo_pretty"
+fi
diff --git a/bin/extra/trl b/bin/extra/trl
index 55d65ee..957d0fb 100755
--- a/bin/extra/trl
+++ b/bin/extra/trl
@@ -5,33 +5,7 @@
# returns available languages
languages () {
- cat <<-EOF
- arabic
- dutch
- french
- german
- polish
- english
- portuguese
- spanish
- romanian
- hebrew
- swedish
- italian
- turkish
- japanese
- ukrainian
- korean
- chinese
- czech
- hungarian
- danish
- persian
- greek
- slovak
- hindi
- thai
- EOF
+ printf 'arabic\nchinese\nczech\ndanish\ndutch\nenglish\nfrench\ngerman\ngreek\nhebrew\nhindi\nhungarian\nitalian\njapanese\nkorean\npersian\npolish\nportuguese\nromanian\nslovak\nspanish\nswedish\nthai\nturkish\nukrainian\n'
}
if [ -z "${word:=$1}" ]
@@ -47,11 +21,12 @@ primary="$(languages | fzf --prompt="from:")"
secondary="$(languages | fzf --prompt="to:")"
[ "$secondary" ] || exit 1
-curl -s "https://context.reverso.net/translation/$primary-$secondary/$word" \
+# url="https://www.reverso.net/text-translation#sl=$primary&tl=$secondary&text=$word"
+url="https://context.reverso.net/translation/$primary-$secondary/$word"
+curl -s "$url" \
--compressed \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \
- -H 'Accept-Language: en-US,en;q=0.5' \
-H 'Accept-Encoding: gzip, deflate, br' |
pup 'a.link_highlighted em text{}' |
sed 's/.*/\L&/' |
diff --git a/bin/guiscripts/dmfm b/bin/guiscripts/dmfm
index 9485469..b7a68d2 100755
--- a/bin/guiscripts/dmfm
+++ b/bin/guiscripts/dmfm
@@ -1,20 +1,20 @@
#!/bin/sh
-while true
-do
- dir="$(printf '%s' "$PWD" | sed "s#^$HOME#\~#;s#\([^/]\)[^/]*/#\1/#g")"
- file=$(find . -maxdepth 1 -mindepth 1 -not -name '.*' -printf '%y\t%f\n' |
+[ -d "$1" ] && cd "$1"
+
+while true; do
+ choice=$(find . -maxdepth 1 -mindepth 1 -not -name '.*' -printf '%y\t%f\n' |
sort -k 1 -k 2 | cut -f 2- |
- commander -xc -p "$dir")
+ dmenu -x -c -i -p "$(pwd)")
- [ "$file" ] || break
- [ ! -e "$file" ] && continue
+ [ "$choice" ] || break
+ [ -e "$choice" ] || continue
- if [ -d "$file" ]
- then
- cd "$file" || continue
+ if [ -d "$choice" ]; then
+ cd "$choice" || continue
else
- setsid xdg-open "$PWD/$file" &
+ setsid xdg-open "$choice" &
+ exit
fi
done
diff --git a/bin/menuscripts/mmedia b/bin/menuscripts/mmedia
index 3141c3b..f4e6e3c 100755
--- a/bin/menuscripts/mmedia
+++ b/bin/menuscripts/mmedia
@@ -6,52 +6,65 @@ dirs="$HOME/dl"
concat_path() { sed "s#^$HOME#\~#;s#\([^/]\)[^/]*/#\1/#g"; }
-case "$1" in
- "video")
- regex='^.\+\.\(webm\|mp4\|mpeg\|mkv\)$'
- dirs="$dirs $HOME/vids"
- viewer() { $PLAYER "$1"; } ;;
- "pdf")
- regex='^.\+\.\(pdf\)$'
- dirs="$dirs $HOME/docs"
- viewer() { $VIEWER "$1"; } ;;
- "image")
- regex='^.\+\.\(png\|avif\|jpg\)$'
- dirs="$dirs $HOME/pics"
- viewer() { $IMAGE "$1"; } ;;
- "cursus")
- regex='^.*/[cC]ursus/index.html$'
- dirs="$HOME/docs/school/Vakken"
- concat_path() { sed "s#$dirs/##;s#/[cC]ursus/index.html##"; }
- viewer() { $BROWSER "$1"; } ;;
- "schoolpdf")
- regex='^.\+\.\(pdf\)$'
- dirs="$HOME/docs/school/Vakken"
- concat_path() { sed "s#$dirs/##;s#/[cC]ursus/index.html##;s#/Cursus/viewer/files/#: #"; }
- viewer() { $VIEWER "$1"; } ;;
- *)
- choice="$(cat <<-EOF | dmenu -g 5 -l 1 -c
- video
- pdf
- image
- cursus
- schoolpdf
+case "$1" in
+"video")
+ regex='^.\+\.\(webm\|mp4\|mpeg\|mkv\)$'
+ dirs="$dirs $HOME/vids"
+ viewer() { $PLAYER "$1"; }
+ ;;
+"pdf")
+ regex='^.\+\.\(pdf\)$'
+ dirs="$dirs $HOME/docs"
+ viewer() { $VIEWER "$1"; }
+ ;;
+"image")
+ regex='^.\+\.\(png\|avif\|jpg\)$'
+ dirs="$dirs $HOME/pics"
+ viewer() { $IMAGE "$1"; }
+ ;;
+"cursus")
+ regex='^.*/[cC]ursus/index.html$'
+ dirs="$HOME/docs/school/Vakken"
+ concat_path() { sed "s#$dirs/##;s#/[cC]ursus/index.html##"; }
+ viewer() { $BROWSER "$1"; }
+ ;;
+"schoolpdf")
+ regex='^.\+\.\(pdf\)$'
+ dirs="$HOME/docs/school/Vakken"
+ concat_path() { sed "s#$dirs/##;s#/[cC]ursus/index.html##;s#/Cursus/viewer/files/#: #"; }
+ viewer() { $VIEWER "$1"; }
+ ;;
+"lecture")
+ dmfm $HOME/docs/lecture
+ exit
+ ;;
+*)
+ choice="$(
+ cat <<-EOF | dmenu -g 6 -l 1 -c
+ video
+ pdf
+ image
+ cursus
+ schoolpdf
+ lecture
EOF
- )"
- [ "$choice" ] || exit 1
- "$0" "$choice"
- exit ;;
+ )"
+ [ "$choice" ] || exit 1
+ "$0" "$choice"
+ exit
+ ;;
esac
shift
[ "$1" ] && dirs="$1"
choice="$(
- find -L $dirs 2> /dev/null |
- grep "$regex" |
- sort | tee "$tmp" |
- concat_path |
- dmenu -px -c -i -l 10 -g 1 -x)"
+ find -L $dirs 2>/dev/null |
+ grep -i "$regex" |
+ sort | tee "$tmp" |
+ concat_path |
+ dmenu -px -c -i -l 10 -g 1 -x
+)"
file="$(sed -n "${choice}p" "$tmp")"
[ -r "$file" ] || exit 1
diff --git a/bin/menuscripts/tsh b/bin/menuscripts/tsh
index 0c57ee0..ea582d8 100755
--- a/bin/menuscripts/tsh
+++ b/bin/menuscripts/tsh
@@ -3,206 +3,169 @@
PROG="$(basename "$0")"
## VARIABLES
# copy command and deps variable
-deps="pup curl $MENUCMD"
+deps="pup curl clipp transmission-cli"
MODULES_PATH=$HOME/.local/share/tsh
module='nyaa.sh' # default module
# Files
export tmp="/tmp/$PROG"
+
files="seeds sizes names html tmp_types"
# Use export so that these variables can be used inside of modules
-for file in $files
-do eval "export $file=$tmp/$file"
+for file in $files; do
+ eval "export $file=$tmp/$file"
done
+
# Files not in $files won't be deleted
export results="$tmp/results"
export links="$tmp/links"
categories="music anime movies shows other software games isos books"
-if [ "$WAYLAND_DISPLAY" ]
-then
- clipp() { wl-copy -n; }
- deps="$deps wl-copy"
-else
- clipp() { xclip -selection clipboard -r; }
- deps="$deps xclip"
-fi
-## FUNCTIONS
-
-help ()
-{
- >&2 cat <<-EOF
- Usage: $PROG [options] query
- Options:
- -h Show this help message and exit
- -r Skip getting pages and use last results
- -s OPTION Sort results based on the specified OPTION
- Available options: seeds, size, name
- -m MODULE Select a module, if MODULE is 'list',
- lists out available modules
- -c CATEGORY Select category
- -f Do not list files
- -d Download without confirming
- EOF
+logn() { >&2 printf '%s\n' "$*"; }
+die() {
+ logn "$@"
+ exit 1
}
-
-log () { >&2 printf '%s' "$*"; }
-logn () { >&2 printf '%s\n' "$*"; }
-die () { logn "$@"; exit 1; }
-
-confirm()
-{
- log "$1"
+confirm() {
+ >&2 printf '%s' "$1"
head -n 1 | grep -q "[yY]"
}
-dependencies ()
-{
- for p in $deps
- do
- if ! command -v "$p" > /dev/null
- then
- logn "E: Program '$p' not found."
- error=1
- fi
- done
- [ "${error:-0}" -eq 1 ] && exit 1
-}
-
-# shellcheck disable=SC2046
-# (we use word splitting on purpose)
-isOnline () { grep -q '1' $(echo /sys/class/net/*/carrier | sed 's#/sys/class/net/lo/carrier ##'); }
-
# Remove temp files and quit
-cleanup ()
-{
- for file in $files
- do eval "rm -f \$$file"
+cleanup() {
+ for file in $files; do
+ eval "rm -f \$$file"
done
}
-list_modules () { find -L "$MODULES_PATH" -type f -printf "%f\n"; }
-
-# get a query from user based on MENUCMD
-get_query ()
-{
- isOnline || exit 1
- if [ "${query:="$*"}" ]
- then
- printf "%s" "$query"
- else
- log ' > '
- head -n 1
- fi | tr ' ' '+'
-}
-
-# Select a result from the result file sorterd with sort_results
-# and select with fzf
-select_result ()
-{
- command -v sort_results > /dev/null || sort_results() { sort -k3 -n -r; }
- awk '{print NR, $0}' "$results" |
- sort_results |
- column -t -l 3 |
- fzf -m --with-nth 2.. |
- awk '{print $1}'
-}
-
-show_files()
-{
- hash="${1##*btih:}"
- hash="${hash%%&*}"
-
- # Download the torrent file from a torrent website
- curl -s "https://itorrents.org/torrent/${hash}.torrent" > "$tmp"/.torrent
- transmission-show "$tmp"/.torrent | sed -n '/^FILES/,$p' | head -n -1 | tail -n +3 >&2
- rm -f "$tmp"/.torrent
-}
+list_modules() { find -L "$MODULES_PATH" -type f -printf "%f\n"; }
-trap "exit 1" INT
+trap "exit 2" INT
trap "cleanup" EXIT
## OPTIONS
-skip=0
-while getopts ":hm:rs:c:fd" opt
-do
+while getopts ":hm:rs:c:fd" opt; do
case $opt in
- h) help && exit ;;
- c)
- [ "$OPTARG" = "list" ] && >&2 printf '%s\n' "$categories" && exit
- category="$(printf '%s\n' "$categories" | tr ' ' '\n' | grep -m 1 "^$OPTARG")"
- [ -z "$category" ] && die "No valid category for '$OPTARG'"
- logn "category: $category" ;;
- f) noaskfiles="1" ;;
- d) noaskdownload="1" ;;
- m)
- [ "$OPTARG" = "list" ] && list_modules && exit
- module="$(list_modules | grep -m 1 "^$OPTARG")"
- [ -z "$module" ] && die "No valid module for '$OPTARG'"
- logn "module: $module" ;;
- r)
- [ ! -r "$results" ] && die "No previous results found."
- skip=1 ;;
- s)
- case $OPTARG in
- "seeds") sort_results() { sort -k3 -n -r; } ;;
- "size") sort_results() { sort -k2 -h -r; } ;;
- "name") sort_results() { sort -k4; } ;;
- *) die "argument '$OPTARG' not seeds,size,name" ;;
- esac ;;
- :) die "Option -$OPTARG requires an argument" ;;
- ?) die "Invalid option: -$OPTARG" ;;
+ h)
+ >&2 cat <<-EOF
+ Usage: $PROG [options] query
+ Options:
+ -h Show this help message and exit
+ -r Skip getting pages and use last results
+ -s OPTION Sort results based on the specified OPTION
+ Available options: seeds, size, name
+ -m MODULE Select a module, if MODULE is 'list',
+ lists out available modules
+ -c CATEGORY Select category
+ -f Do not list files
+ -d Download without confirming
+ EOF
+
+ exit
+ ;;
+ c)
+ [ "$OPTARG" = "list" ] && >&2 printf '%s\n' "$categories" && exit
+ category="$(printf '%s\n' "$categories" | tr ' ' '\n' | grep -m 1 "^$OPTARG")"
+ [ -z "$category" ] && die "No valid category for '$OPTARG'"
+ logn "category: $category"
+ ;;
+ f) noaskfiles="1" ;;
+ d) noaskdownload="1" ;;
+ m)
+ [ "$OPTARG" = "list" ] && list_modules && exit
+ module="$(list_modules | grep -m 1 "^$OPTARG")"
+ [ -z "$module" ] && die "No valid module for '$OPTARG'"
+ logn "module: $module"
+ ;;
+ r)
+ [ ! -r "$results" ] && die "No previous results found."
+ skip=1
+ ;;
+ s)
+ case $OPTARG in
+ "seeds") sort_results() { sort -k3 -n -r; } ;;
+ "size") sort_results() { sort -k2 -h -r; } ;;
+ "name") sort_results() { sort -k4; } ;;
+ *) die "argument '$OPTARG' not seeds,size,name" ;;
+ esac
+ ;;
+ :) die "Option -$OPTARG requires an argument" ;;
+ ?) die "Invalid option: -$OPTARG" ;;
esac
done
shift $((OPTIND - 1))
-dependencies
+for p in $deps; do
+ if ! command -v "$p" >/dev/null; then
+ logn "E: Program '$p' not found."
+ error=1
+ fi
+done
+[ "${error:-0}" -eq 1 ] && exit 3
# Get the torrents with module
-if [ $skip -ne 1 ]
-then
+if [ "${skip:-0}" -eq 1 ]; then
+ module="$(tail -n 1 "$links")"
+else
mkdir -p "$tmp"
- query="$(get_query "$*")"
- [ "$query" ] || exit 1
+ query="$(
+ if [ "${query:="$*"}" ]; then
+ printf "%s" "$query"
+ else
+ >&2 printf ' > '
+ head -n 1
+ fi | tr ' ' '+'
+ )"
+ [ "$query" ] || exit 4
- # Get results
- rm -f "$results" "$links"
# shellcheck source=/usr/local/lib/$PROG/nyaa.sh disable=SC1091
. "$MODULES_PATH/$module"
+ rm -f "$results" "$links"
+ get_torrents
+
[ -f "$results" ] || die "No results."
- # Save which module was used
- printf "%s\n" "$module" >> "$links"
-else
- module="$(tail -n 1 "$links")"
+ # Save which module was used (hack)
+ printf "%s\n" "$module" >>"$links"
fi
-# acquire get_magnet function
-# shellcheck source=/usr/local/lib/$PROG/nyaa.sh disable=SC1091
-getfunctions=1 . "$MODULES_PATH/$module"
+# Default sorting if unset
+command -v sort_results >/dev/null || sort_results() { sort -k3 -n -r; }
# select result from "$results"
-for choice in $(select_result | xargs)
-do
- printf 'choice: %s\n' "$(sed -n "${choice}p" "$results" | cut -f 3-)"
- magnet="$(get_magnet "$choice")"
- [ "$magnet" ] || exit 1
-
- if [ -z "$noaskfiles" ] && confirm 'files?'; then
- show_files "$magnet"
- fi
-
- if [ "$noaskdownload" ] || confirm 'download?'
- then
- [ "$category" ] || category="$(printf '%s' "$categories" | tr ' ' '\n' | fzf)"
- [ "$category" ] || exit 2
- transmission-remote debuc.com -a "$magnet" -w "/downloads/$category"
- elif confirm "copy?"
- then
- echo "$magnet" | clipp
- fi
+for choice in $(
+ # Select result(s) from the result file sorted with sort_results
+ # with fzf
+ awk '{print NR, $0}' "$results" |
+ sort_results |
+ column -t -l 3 |
+ fzf -m --with-nth 2.. |
+ awk 'BEGIN{OFS=" "} {print $1}'
+); do
+
+ printf 'choice: %s\n' "$(sed -n "${choice}p" "$results" | cut -f 3-)"
+ magnet="$(get_magnet "$choice")"
+ [ "$magnet" ] || exit 5
+
+ if [ -z "$noaskfiles" ] && confirm 'files?'; then
+ hash="${1##*btih:}"
+ hash="${hash%%&*}"
+
+ # Download the torrent file from a torrent website
+ curl -s "https://itorrents.org/torrent/${hash}.torrent" >"$tmp"/.torrent
+ transmission-show "$tmp"/.torrent | sed -n '/^FILES/,$p' | head -n -1 | tail -n +3 >&2
+ rm -f "$tmp"/.torrent
+ fi
+
+ if [ -z "$noaskdownload" ] && confirm 'download?'; then
+ [ "$category" ] || category="$(printf '%s' "$categories" | tr ' ' '\n' | fzf)"
+ [ "$category" ] || exit 6
+ transmission-remote debuc.com -a "$magnet" -w "/downloads/$category"
+ elif confirm "copy?"; then
+ echo "$magnet" | clipp
+ fi
done