aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-01-04 15:41:32 -0300
committerEuAndreh <eu@euandre.org>2022-01-04 15:41:32 -0300
commit8b9a649ac05469881e17a63112cef69bdc19ed08 (patch)
tree8d75b443361d9dbb85ca2a26c54c9d32cc019034 /src
parent.gitignore: Remove /cron/generated/ (diff)
downloaddotfiles-8b9a649ac05469881e17a63112cef69bdc19ed08.tar.gz
dotfiles-8b9a649ac05469881e17a63112cef69bdc19ed08.tar.xz
scripts/: Move executables to src/bin/, and add a proper CLI interface to them
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bin/backup91
-rwxr-xr-xsrc/bin/commit-md59
-rwxr-xr-xsrc/bin/fim50
-rwxr-xr-xsrc/bin/gc91
-rwxr-xr-xsrc/bin/open96
l---------src/bin/xdg-open1
-rwxr-xr-xsrc/bin/yt90
7 files changed, 478 insertions, 0 deletions
diff --git a/src/bin/backup b/src/bin/backup
new file mode 100755
index 00000000..1e51d09a
--- /dev/null
+++ b/src/bin/backup
@@ -0,0 +1,91 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ backup [ARCHIVE_TAG [COMMENT]]
+ backup -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ ARCHIVE_TAG defaults to "cronjob".
+ COMMENT defaults to an empty string.
+
+ Options:
+ -h, --help show this message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+set -x
+
+finish() {
+ STATUS=$?
+ printf '\n>>>\n>>> exit status: %s\n>>>\n\n' "$STATUS" >&2
+}
+trap finish EXIT
+
+R='16686@ch-s010.rsync.net'
+export BORG_REMOTE_PATH='borg1'
+export BORG_PASSCOMMAND='pass show Usurpador/borg/passphrase'
+SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
+export SSH_AUTH_SOCK
+
+borg init -e repokey-blake2 $R:usurpador-borg ||:
+borg key export $R:usurpador-borg ~/archive/usurpador-borg-key.txt
+
+borg create \
+ --stats \
+ --compression lzma,9 \
+ --comment "${2:-}" \
+ "$R:usurpador-borg::{hostname}-{now}-${1:-cronjob}" \
+ ~/
+
+borg check \
+ --verbose \
+ --last 3 \
+ $R:usurpador-borg
+
+borg prune \
+ --verbose \
+ --list \
+ --keep-within=6m \
+ --keep-weekly=52 \
+ --keep-monthly=24 \
+ $R:usurpador-borg
+
+ssh $R quota
diff --git a/src/bin/commit-md b/src/bin/commit-md
new file mode 100755
index 00000000..3d4d5f6a
--- /dev/null
+++ b/src/bin/commit-md
@@ -0,0 +1,59 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ commit-md [COMMIT]
+ commit-md -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+COMMIT="${1:-$(git rev-parse HEAD)}"
+REPOSITORY="$(basename "$PWD")"
+
+LINK="$(printf 'https://euandreh.xyz/%s.git/commit/?id=%s' "$REPOSITORY" "$COMMIT")"
+# shellcheck disable=2016
+MD="$(printf '[`%s`](%s)' "$COMMIT" "$LINK")"
+
+xdg-open "$LINK"
+printf ' Done in\n%s.' "$MD" | xclip -sel clip
+printf 'Copied %s to the clipboard!\n' "$MD" >&2
diff --git a/src/bin/fim b/src/bin/fim
new file mode 100755
index 00000000..7a21a513
--- /dev/null
+++ b/src/bin/fim
@@ -0,0 +1,50 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ fim
+ fim -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+play "$DOTFILES/sh/Positive.ogg" 2> /dev/null
diff --git a/src/bin/gc b/src/bin/gc
new file mode 100755
index 00000000..0fd2ca78
--- /dev/null
+++ b/src/bin/gc
@@ -0,0 +1,91 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ gc
+ gc -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+set -x
+before="$(df -h .)"
+
+PROFILES='
+per-user/root/channels
+per-user/andreh/profile
+per-user/andreh/channels
+system
+'
+
+for p in $PROFILES; do
+ doas nix-env --delete-generations old -p "/nix/var/nix/profiles/$p"
+done
+nix-env --delete-generations old
+nix-store --gc
+nix-collect-garbage -d
+
+guix gc -d
+
+find ~/ -name 'nohup.out' -exec rm {} \;
+rm -rf ~/.local/share/Trash/files/*
+find /tmp/ -type f -atime +10 -exec rm {} \; ||:
+
+if command -V docker; then
+ echo y | docker system prune -a
+ docker rmi "$(docker images -a -q)" ||:
+ docker rm "$(docker ps -a -f status=exited -q)" ||:
+ docker stop "$(docker ps -a -q)" ||:
+ docker rm "$(docker ps -a -q)" ||:
+ echo y | docker volume prune
+ echo y | docker container prune
+fi
+
+notmuch search --output=files --exclude=false tag:deleted | xargs -I{} rm "{}"
+notmuch new
+
+after="$(df -h .)"
+
+set +x
+echo 'Disk space before and after:'
+echo " before: $before"
+echo " after: $after"
diff --git a/src/bin/open b/src/bin/open
new file mode 100755
index 00000000..8ede1b7a
--- /dev/null
+++ b/src/bin/open
@@ -0,0 +1,96 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ open FILE...
+ open -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+
+ Examples:
+
+ Open an HTML file on the current $BROWSER:
+ open index.html
+
+ Open multiple PDF files (with zathura):
+ open *.pdf
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if [ -z "${1:-}" ]; then
+ usage >&2
+ exit 2
+fi
+
+for f in "$@"; do
+ case "$f" in
+ *.ico|*.jpg|*.jpeg|*.png)
+ feh "$f"
+ ;;
+ https://www.youtube.com/watch*)
+ nohup mpv "$f" 1>&2 2>/dev/null &
+ ;;
+ *.flac|*.ogg|*.mkv|*.avi|*.mp4)
+ nohup mpv "$f" 1>&2 2>/dev/null &
+ ;;
+ http*|*.svg|*.html)
+ "$BROWSER" "$f"
+ ;;
+ gopher://*)
+ amfora "$f"
+ ;;
+ gemini://*)
+ amfora "$f"
+ ;;
+ *.pdf|*.djvu|*.ps|*.epub)
+ nohup zathura "$f" 1>&2 2>/dev/null &
+ ;;
+ *.txt)
+ less "$f"
+ ;;
+ *.midi)
+ timidity "$f"
+ ;;
+ *)
+ /run/current-system/sw/bin/xdg-open "$f"
+ ;;
+ esac
+done
diff --git a/src/bin/xdg-open b/src/bin/xdg-open
new file mode 120000
index 00000000..ce4a72b8
--- /dev/null
+++ b/src/bin/xdg-open
@@ -0,0 +1 @@
+open \ No newline at end of file
diff --git a/src/bin/yt b/src/bin/yt
new file mode 100755
index 00000000..0ef5932c
--- /dev/null
+++ b/src/bin/yt
@@ -0,0 +1,90 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ yt [-f] URL... [PLAYLIST_COUNT:-15]
+ yt [-f] FILE... [PLAYLIST_COUNT:-15]
+ yt -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -f force to download a video already
+ in the archive
+ -h, --help show this message
+EOF
+}
+
+mkstemp() {
+ echo 'mkstemp(template)' | m4 -D template="${TMPDIR:-/tmp}/m4-tmpname."
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'fh:' flag; do
+ case "$flag" in
+ f)
+ FORCE=1
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if [ -z "${1:-}" ]; then
+ echo 'Missing URL|FILE argument' >&2
+ usage >&2
+ exit 2
+fi
+
+
+if [ ! -e "$1" ]; then
+ F="$(mkstemp)"
+ printf '%s\n' "$1" > "$F"
+else
+ F="$1"
+fi
+
+
+DEFAULT_PLAYLIST_END=15
+YT_TEMPLATE="$HOME/Downloads/yt-dl/%(uploader)s/%(upload_date)s %(title)s.%(ext)s"
+
+if [ -z "${FORCE:-}" ]; then
+ ARCHIVE_OPTION="--download-archive $HOME/archive/youtube-dl-seen.conf"
+fi
+
+youtube-dl \
+ --batch-file "$F" \
+ --format best \
+ --prefer-free-formats \
+ --playlist-end "${2:-$DEFAULT_PLAYLIST_END}" \
+ --write-description \
+ --output "$YT_TEMPLATE" \
+ ${ARCHIVE_OPTION:-}