summaryrefslogtreecommitdiffstats
path: root/.bin
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2022-10-08 12:40:19 +0200
committerRomain Gonçalves <me@rgoncalves.se>2022-10-08 12:40:19 +0200
commitce6be946d024aa55a15d576388d05f90be671cf2 (patch)
treefa1053446a3fb06daee8438c1ff664cb36c0abcb /.bin
parent703ed1915c69911a95cab6e1fb6524629c976800 (diff)
downloaddots-ce6be946d024aa55a15d576388d05f90be671cf2.tar.gz
Sat Oct 8 12:40:19 PM CEST 2022
Diffstat (limited to '.bin')
-rwxr-xr-x.bin/_music70
-rwxr-xr-x.bin/ag-status19
-rwxr-xr-x.bin/bck-create21
-rwxr-xr-x.bin/ccurse11
-rwxr-xr-x.bin/ccurse-ical8
-rwxr-xr-x.bin/clear-efi-suspend10
-rwxr-xr-x.bin/create-local-backup24
-rwxr-xr-x.bin/dot-bootstrap30
-rwxr-xr-x.bin/dot-sync10
-rwxr-xr-x.bin/get-mailbox-imap69
-rwxr-xr-x.bin/get-mailbox-local11
-rwxr-xr-x.bin/music174
-rwxr-xr-x.bin/nmutt8
-rwxr-xr-x.bin/pipx-sync12
-rwxr-xr-x.bin/poetry-clean-init12
-rwxr-xr-x.bin/qb4
-rwxr-xr-x.bin/se-plan6
-rwxr-xr-x.bin/start-org25
-rwxr-xr-x.bin/synchronize-pub-dots1
-rwxr-xr-x.bin/x11-config3
-rwxr-xr-x.bin/x11-screen8
-rwxr-xr-x.bin/yubikey-reset20
22 files changed, 274 insertions, 282 deletions
diff --git a/.bin/_music b/.bin/_music
new file mode 100755
index 0000000..6ef5ef8
--- /dev/null
+++ b/.bin/_music
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+
+MUSIC_DIR="${HOME}/music"
+MUSIC_LIST=
+MUSIC_FILE=
+MUSIC_YT_OPTIONS=
+
+log() {
+ echo "[${0} ] ${@}"
+}
+
+main() {
+ # arguments
+ while getopts "c:" arg; do
+ case "${arg}" in
+ c)
+ MUSIC_FILE="${OPTARG}"
+ ;;
+ h)
+ exit 0
+ ;;
+ esac
+ done
+
+ # ensure parameters are correct
+ [ ! -f "${MUSIC_FILE}" ] && exit 1
+
+
+ while read -r line; do
+
+ # skip comments
+ line=$(echo ${line} | grep -v -e "^$" -e "^#")
+ [ -z "${line}" ] && continue
+
+ # retrieve playlist params
+ url=$(echo "${line}" | cut -d " " -f 1)
+ dir=$(echo "${line}" | cut -d " " -f 2)
+
+ dir="${MUSIC_DIR}/${dir}"
+
+ [ -d "${dir}" ] &&
+ log "${dir}: directory already exists" &&
+ continue
+
+ mkdir "${dir}"
+ log "${dir} ${url}: download"
+
+ yt-dlp --rm-cache-dir >/dev/null
+ yt-dlp \
+ --extract-audio \
+ --audio-format mp3 \
+ --prefer-ffmpeg \
+ --audio-quality 0 \
+ --embed-thumbnail \
+ --metadata-from-title "%(artist)s - %(title)s" \
+ --no-warnings \
+ --ignore-errors \
+ --no-overwrites \
+ --continue \
+ --add-metadata \
+ --user-agent "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" \
+ --output "${dir}/'%(title)s.%(ext)s'" \
+ "${url}"
+
+
+ done < "${MUSIC_FILE}"
+}
+
+main ${@}
diff --git a/.bin/ag-status b/.bin/ag-status
index 3970e54..abd2fff 100755
--- a/.bin/ag-status
+++ b/.bin/ag-status
@@ -6,10 +6,13 @@ __cleanup_value() {
uname=$(uname)
+status=""
+
battery=""
battery_status=""
time=""
volume=""
+vpn=""
while true; do
case "${uname}" in
@@ -24,8 +27,9 @@ while true; do
;;
Linux)
battery=$(acpi -b |
- cut -d " " -f 4 |
- cut -d "%" -f 1)
+ tr -s " " "\n" |
+ grep "%" |
+ sed 's/[%,]//g')
battery_status=$(acpi -a |
tr -s " " |
cut -d " " -f 3)
@@ -33,18 +37,25 @@ while true; do
__cleanup_value)
if $(pamixer --get-mute); then
- volume_status="__mute__"
+ volume="%mute"
fi
;;
esac
- time=$(date +%Y-%m-%dT%H:%M:%S)
status="VOL: ${volume}%"
+ vpn=""
+ ! wg && vpn="wireguard"
+ pgrep openvpn && vpn="openvpn"
+ if [ -n "${vpn}" ]; then
+ status="${status} | VPN: ${vpn}"
+ fi
+
if [ -n "${battery}" ]; then
status="${status} | BATTERY ${battery}%"
fi
+ time=$(date +%Y-%m-%dT%H:%M:%S)
status="${status} | DATE: ${time}"
echo "${status}"
diff --git a/.bin/bck-create b/.bin/bck-create
new file mode 100755
index 0000000..9714af6
--- /dev/null
+++ b/.bin/bck-create
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -xe
+
+directories="${HOME}/docs
+ ${HOME}/git.rgoncalves.se
+ ${HOME}/.local/share/gopass
+ ${HOME}/.local/share/mail
+ ${HOME}/.local/share/yadm
+ ${HOME}/.local/share/zk"
+
+pgp_id=$(gpg --list-secret-keys | grep -A 1 sec | tail -n 1 | tr -d " ")
+output_name="$(date -u +"%Y-%m-%dT%H_%M_%S%Z").tar.pgp"
+
+if [ -d "${1}" ]; then
+ output_name="${1}/${output_name}"
+elif [ -f "${1}" ] || [ "${1}" ]; then
+ output_name="${1}"
+fi
+
+tar cvf - ${directories} | lz4 | gpg -e -z 0 -r "${pgp_id}" > "${output_name}"
diff --git a/.bin/ccurse b/.bin/ccurse
deleted file mode 100755
index 6377bb0..0000000
--- a/.bin/ccurse
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-default_calendar="personal"
-data_dir="${HOME}/docs/calendar"
-
-for calendar; do true; done
-args=$(echo ${@} | rev | cut -d " " -f 2- | rev)
-
-exec calcurse -C "${HOME}/.config/calcurse" \
- -D "${data_dir}/${last:-${default_calendar}}" \
- ${args}
diff --git a/.bin/ccurse-ical b/.bin/ccurse-ical
deleted file mode 100755
index d5c6e90..0000000
--- a/.bin/ccurse-ical
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-set -xe
-
-[ "${1}" ]
-[ "${2}" ]
-
-ccurse
diff --git a/.bin/clear-efi-suspend b/.bin/clear-efi-suspend
deleted file mode 100755
index 9086ef3..0000000
--- a/.bin/clear-efi-suspend
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-set -xe
-
-mkdir -p /dev/pstore
-mount -t pstore pstore /dev/pstore
-ls /dev/pstore
-rm -f /dev/pstore/*
-
-rm /sys/firmware/efi/efivars/dump-type0-*
diff --git a/.bin/create-local-backup b/.bin/create-local-backup
deleted file mode 100755
index 4e4cb1b..0000000
--- a/.bin/create-local-backup
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-set -xe
-
-source_directories="./git.rgoncalves.se/
- ./
- "
-
-out_dir=$(readlink -f "${1}")
-
-[ -d "${out_dir}" ]
-
-exit
-rsync -hvrPt \
- --delete-after \
- --fuzzy \
- --prune-empty-dirs \
- --include "*.pdf" \
- --include "*.epub" \
- --include "*.png" \
- --include "*.jpg" \
- --include "*/" \
- --exclude "*" \
- "${src_dir}/" "${out_dir}/"
diff --git a/.bin/dot-bootstrap b/.bin/dot-bootstrap
index 766eaf1..0da52d0 100755
--- a/.bin/dot-bootstrap
+++ b/.bin/dot-bootstrap
@@ -2,17 +2,27 @@
set -x -e
-directories="git \
- downloads \
- .cache/dot \
- .cache/neomutt \
- .local/bin \
- .local/share/dot \
- .mail"
-
+# dotfiles setup
remote=$(yadm remote | head -n 1)
yadm branch --set-upstream-to="${remote}/trunk" trunk
-for directory in ${directories}; do mkdir -p "${HOME}/${directory}"; done
+# directory structure
+for directory in "${HOME}/.cache/dot \
+ ${HOME}/.cache/neomutt \
+ ${HOME}/.local/bin \
+ ${HOME}/.local/share/dot \
+ ${HOME}/.mail
+ ${HOME}/downloads \
+ ${HOME}/git \
+ ${HOME}/mnt \
+ ${HOME}/tmp \
+ ${ZK_NOTEBOOK_DIR}"; do
+ mkdir -p "${directory}"
+done
+
+# default venvs
+venv_root_dir="${HOME}/.local/venv"
+mkdir -p "${venv_root_dir}"
-notmuch new
+python -m venv "${venv_root_dir}/weechat"
+"${venv_root_dir}/weechat/bin/pip" install websocket-client
diff --git a/.bin/dot-sync b/.bin/dot-sync
index 7f4d490..0643086 100755
--- a/.bin/dot-sync
+++ b/.bin/dot-sync
@@ -13,13 +13,21 @@ yadm add \
$HOME/.config/neomutt \
$HOME/.config/newsboat \
$HOME/.config/nvim \
- $HOME/.config/qutebrowser/{*.py,greasemonkey} \
+ $HOME/.config/qutebrowser/*.py \
+ $HOME/.config/qutebrowser/bookmarks \
+ $HOME/.config/qutebrowser/greasemonkey \
+ $HOME/.config/qutebrowser/quickmarks \
+ $HOME/.config/qutebrowser/userscripts/*.py \
$HOME/.config/sway \
+ $HOME/.config/task \
$HOME/.config/yadm \
$HOME/.config/waybar \
+ $HOME/.config/zk \
$HOME/.public-keys
yadm push
+nvim --headless -c "PaqSync" -c "TSInstall all" -c "TSUpdate" -c "qa"
+
yadm commit -m "$(date +%Y-%m-%dT%H:%M:%S)"
yadm push
diff --git a/.bin/get-mailbox-imap b/.bin/get-mailbox-imap
deleted file mode 100755
index b78752d..0000000
--- a/.bin/get-mailbox-imap
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env python3
-
-import imaplib
-import sys
-
-
-def get_boxes(list):
- """ Retrieve and decode all mailboxes. """
- return [box.decode('utf-8').rsplit(' ')[-1] for box in list]
-
-
-def flatten_output(list):
- """ Print all boxes with a flattened output. """
- return ''.join([f"+'{box}' " for box in list])
-
-
-def sort_mailboxes(mailboxes):
- """ Sort boxes list according to a predefined order. """
-
- order = [
- "INBOX",
- "Unread",
- "Drafts",
- "Sent",
- "Spam",
- "Trash",
- "Junk",
- "Archive"
- ]
-
- mailboxes = sorted(mailboxes)
-
- # sort based on predefined order
- output = []
- for exp in order:
- matching = [s for s in mailboxes if exp in s]
- output.extend(matching)
-
- # ensure all retrieved boxes are present
- for box in mailboxes:
- if box not in output:
- output.append(box)
-
- return output
-
-
-def main():
- """
- Retrieve, sort, and pretty print for neomutt
- """
-
- # user information
- remote = sys.argv[1]
- username = sys.argv[2]
- password = sys.argv[3]
-
- # connection
- mail = imaplib.IMAP4_SSL(remote)
- mail.login(username, password)
-
- # parse folders output
- bxs = sort_mailboxes(get_boxes(mail.list()[1]))
-
- # oneline pretty-print for neomutt
- print(flatten_output(bxs), end=' ')
-
-
-if __name__ == "__main__":
- main()
diff --git a/.bin/get-mailbox-local b/.bin/get-mailbox-local
deleted file mode 100755
index b579016..0000000
--- a/.bin/get-mailbox-local
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-root_dir=$(readlink -f ${1})
-
-mailboxes=$(find "${1}" -name "cur" |
- xargs dirname |
- sed "s@$root_dir/@+@g" |
- grep "${2:-.*}" |
- sort)
-
-echo ${mailboxes}
diff --git a/.bin/music b/.bin/music
index 6ef5ef8..a14aae9 100755
--- a/.bin/music
+++ b/.bin/music
@@ -1,70 +1,104 @@
-#!/bin/sh
-
-
-MUSIC_DIR="${HOME}/music"
-MUSIC_LIST=
-MUSIC_FILE=
-MUSIC_YT_OPTIONS=
-
-log() {
- echo "[${0} ] ${@}"
-}
-
-main() {
- # arguments
- while getopts "c:" arg; do
- case "${arg}" in
- c)
- MUSIC_FILE="${OPTARG}"
- ;;
- h)
- exit 0
- ;;
- esac
- done
-
- # ensure parameters are correct
- [ ! -f "${MUSIC_FILE}" ] && exit 1
-
-
- while read -r line; do
-
- # skip comments
- line=$(echo ${line} | grep -v -e "^$" -e "^#")
- [ -z "${line}" ] && continue
-
- # retrieve playlist params
- url=$(echo "${line}" | cut -d " " -f 1)
- dir=$(echo "${line}" | cut -d " " -f 2)
-
- dir="${MUSIC_DIR}/${dir}"
-
- [ -d "${dir}" ] &&
- log "${dir}: directory already exists" &&
- continue
-
- mkdir "${dir}"
- log "${dir} ${url}: download"
-
- yt-dlp --rm-cache-dir >/dev/null
- yt-dlp \
- --extract-audio \
- --audio-format mp3 \
- --prefer-ffmpeg \
- --audio-quality 0 \
- --embed-thumbnail \
- --metadata-from-title "%(artist)s - %(title)s" \
- --no-warnings \
- --ignore-errors \
- --no-overwrites \
- --continue \
- --add-metadata \
- --user-agent "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" \
- --output "${dir}/'%(title)s.%(ext)s'" \
- "${url}"
-
-
- done < "${MUSIC_FILE}"
-}
-
-main ${@}
+#!/usr/bin/python3
+
+import os
+import sys
+import yt_dlp
+from dataclasses import dataclass
+
+
+def _match_filter(info: dict, *, incomplete) -> str | None:
+ _duration = info.get("duration")
+ _duration_min = 60
+
+ if _duration and int(_duration) < _duration_min:
+ return "Duration too short: < _duration_min"
+
+ return None
+
+
+@dataclass(frozen=True)
+class Collection:
+ """A music collection."""
+
+ title: str
+ links: frozenset[str]
+
+ def __eq__(self, other) -> bool:
+ if isinstance(other, Collection):
+ return self.title == other.title
+ raise NotImplementedError
+
+
+def parse_raw_to_collections(raw_data: list[str]) -> frozenset[Collection]:
+ collections: set[Collection] = set()
+ _collection_data: list[str] = []
+
+ for index, line in enumerate(raw_data):
+ if line.startswith("#"):
+ continue
+ elif line == "" or index + 1 == len(raw_data):
+ if len(_collection_data) == 0:
+ continue
+
+ collections.add(
+ Collection(_collection_data[0], frozenset(_collection_data[1:]))
+ )
+ _collection_data.clear()
+ else:
+ _collection_data.append(line)
+
+ return frozenset(collections)
+
+
+def get_ytdlp_options(output_dir: str) -> dict:
+ return {
+ "format": "bestaudio/best",
+ "match_filter": _match_filter,
+ "postprocessors": [
+ {
+ "key": "FFmpegExtractAudio",
+ #"preferredcodec": "m4a",
+ },
+ {
+ "key": "FFmpegMetadata",
+ "add_metadata": True,
+ },
+ {
+ "key": "EmbedThumbnail",
+ "already_have_thumbnail": False,
+ },
+ ],
+ "outtmpl": f"{output_dir}/%(title)s.%(ext)s",
+ "restrictfilenames": True,
+ "ignoreerrors": True,
+ }
+
+
+def download_collection(collection: Collection, parent_dir: str) -> None:
+ output_dir = os.path.join(parent_dir, collection.title)
+
+ if os.path.isdir(output_dir):
+ return
+
+ os.makedirs(output_dir, exist_ok=True)
+
+ with yt_dlp.YoutubeDL(get_ytdlp_options(output_dir)) as downloader:
+ downloader.download(collection.links)
+
+
+def main() -> int:
+ # input handling
+ if len(sys.argv) != 2:
+ return 1
+
+ with open(sys.argv[1], "r") as file:
+ filedata = file.read().splitlines()
+
+ for collection in parse_raw_to_collections(filedata):
+ download_collection(collection, os.getcwd())
+
+ return 0
+
+
+if __name__ == "__main__":
+ exit(main())
diff --git a/.bin/nmutt b/.bin/nmutt
index 0ee2822..a45d33f 100755
--- a/.bin/nmutt
+++ b/.bin/nmutt
@@ -1,6 +1,6 @@
#!/bin/sh
-NMUTT_CONFIGURATION_FILE="${HOME}/.config/neomutt/personal"
+NMUTT_CONFIGURATION_FILE="${HOME}/.config/neomutt/credentials-personal"
get_param() {
grep "${2}" "${1}" |
@@ -15,5 +15,7 @@ export MAIL_SERVER=$(get_param "${NMUTT_CONFIGURATION_FILE}" "my_server")
export MAIL_USERNAME=$(get_param "${NMUTT_CONFIGURATION_FILE}" "my_user")
export MAIL_PASSWORD=$(get-pass "mailbox")
-#notmuch new
-exec neomutt ${@}
+notmuch new >/dev/null 2>&1 &
+neomutt ${@}
+
+notmuch new >/dev/null 2>&1 &
diff --git a/.bin/pipx-sync b/.bin/pipx-sync
deleted file mode 100755
index 181768e..0000000
--- a/.bin/pipx-sync
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-set -x -e
-
-packages="pywal
- ipython"
-
-pipx upgrade-all
-
-for package in ${packages}; do
- pipx install "${package}" || true
-done
diff --git a/.bin/poetry-clean-init b/.bin/poetry-clean-init
new file mode 100755
index 0000000..ad7da81
--- /dev/null
+++ b/.bin/poetry-clean-init
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -xe
+
+
+poetry env info -p
+test -x "${1}"
+
+rm -r $(poetry env info -p) poetry.lock
+poetry env use "${1}"
+poetry update --dry-run
+poetry install
diff --git a/.bin/qb b/.bin/qb
index 3caf57e..dd30091 100755
--- a/.bin/qb
+++ b/.bin/qb
@@ -109,11 +109,11 @@ def main():
QB_PROFILE_TAG = QB_PROFILE[0].lower()
# Ensure directory existence
- for dir in [QB_PROFILES_DIR, QB_PROFILE_DIR, QB_PROFILE_DIR_CONFIG]:
+ for dir in (QB_PROFILES_DIR, QB_PROFILE_DIR, QB_PROFILE_DIR_CONFIG):
bypass_file_exists(os.mkdir, dir)
# Ensure common files are shared with other profiles
- for file in ['config.py', 'bookmarks', 'greasemonkey']:
+ for file in ('config.py', 'bookmarks', 'greasemonkey', 'userscripts'):
bypass_file_exists(os.symlink,
f'{QB_DIR}/{file}',
f'{QB_PROFILE_DIR_CONFIG}/{file}')
diff --git a/.bin/se-plan b/.bin/se-plan
new file mode 100755
index 0000000..f16a2f7
--- /dev/null
+++ b/.bin/se-plan
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+T=$(mktemp)
+curl -so $T https://plan.cat/~rgoncalves
+$EDITOR $T
+curl -su "rgoncalves:$(get-pass plan.cat)" -F "plan=<$T" https://plan.cat/stdin
diff --git a/.bin/start-org b/.bin/start-org
deleted file mode 100755
index c32b99e..0000000
--- a/.bin/start-org
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-set -xe
-
-session_name="org"
-windows="wchat:weechat
- nmutt:neomutt
- calcurse:calcurse"
-
-if [ "${1}" = "-f" ]; then
- tmux kill-session -t "${session_name}"
-fi
-
-tmux new-session -s "${session_name}" -d
-
-for window in ${windows}; do
- window_cmd=$(echo "${window}" | cut -d ":" -f 1)
- window_name=$(echo "${window}" | cut -d ":" -f 2)
-
- tmux new-window -n "${window_name}"
- tmux send-keys -t "${session_name}:${window_name}" \
- "${window_cmd} "
-done
-
-tmux a -t "${session_name}"
diff --git a/.bin/synchronize-pub-dots b/.bin/synchronize-pub-dots
index ae018b2..b1f2e7b 100755
--- a/.bin/synchronize-pub-dots
+++ b/.bin/synchronize-pub-dots
@@ -3,6 +3,7 @@
set -e
command -v yadm git
+git rev-parse --is-inside-work-tree
allowed_patterns="-e ^.bin
-e ^.config/alacritty/
diff --git a/.bin/x11-config b/.bin/x11-config
index 5230c13..efd47d7 100755
--- a/.bin/x11-config
+++ b/.bin/x11-config
@@ -11,7 +11,8 @@ synclient_options="TapButton1=1 \
# synaptic
if command -v syndaemon; then
- pkill syndaemon && syndaemon -RKd -i 0.2
+ pkill syndaemon && true
+ syndaemon -RKd -i 0.1
synclient ${synclient_options}
fi
diff --git a/.bin/x11-screen b/.bin/x11-screen
index ccccda7..ea9e08d 100755
--- a/.bin/x11-screen
+++ b/.bin/x11-screen
@@ -22,6 +22,12 @@ fi
if [ "${hostname}" = "ws-xps01" ]; then
xrandr --output eDP1 --mode 3200x1800
- echo a
__hidpi
fi
+
+if [ "${hostname}" = "work-01" ]; then
+ xrandr --output eDP1 --mode 1920x1080
+ xrandr --output DP3 --off
+ xrandr --addmode DP3 1920x1080
+ xrandr --output DP3 --mode 1920x1080 --same-as eDP1
+fi
diff --git a/.bin/yubikey-reset b/.bin/yubikey-reset
deleted file mode 100755
index 4824bc8..0000000
--- a/.bin/yubikey-reset
+++ /dev/null
@@ -1,20 +0,0 @@
-echo "DESTRUCTIVE !!!"
-
-sleep 60
-
-gpg-connect-agent <<EOF
-/hex
-scd serialno
-scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
-scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
-scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
-scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
-scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
-scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
-scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
-scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
-scd apdu 00 e6 00 00
-scd apdu 00 44 00 00
-/echo Yubikey has been successfully reset.
-/echo The factory default PINs are 123456 (user) and 12345678 (admin).
-EOF
remember that computers suck.