Add 'dots/' from commit 'f64b634dd8fbb2c8a2898c3b9d0acc9452e4d966'
git-subtree-dir: dots git-subtree-mainline:2ad98cde17git-subtree-split:f64b634dd8
This commit is contained in:
26
dots/.bin/README.md
Normal file
26
dots/.bin/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Scripts
|
||||
|
||||
Mostly tiny helper scripts & experiments, some more useful than others.
|
||||
|
||||
## Setup
|
||||
|
||||
Make sure the scripts are in your `$PATH` and executable.
|
||||
|
||||
To add the complete directory of scripts to your `$PATH`:
|
||||
|
||||
```bash
|
||||
export PATH=~/.bin:$PATH
|
||||
```
|
||||
|
||||
To make a any script `<script>` executable:
|
||||
```bash
|
||||
chmod +x <script>
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
Statusbar scripts are prefixed with `sb` under the assumption you're using
|
||||
`polybar` (scripts my need changes to be used with different statusbars).
|
||||
|
||||
Some scripts have dependencies (e.g. `fzf`, `jq`, `xclip`, ...), make sure you
|
||||
have them installed.
|
||||
6
dots/.bin/aurpac
Executable file
6
dots/.bin/aurpac
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Tiny AUR clone helper
|
||||
# aurpac <package-name>
|
||||
|
||||
git clone "https://aur.archlinux.org/$1.git"
|
||||
3
dots/.bin/calc
Executable file
3
dots/.bin/calc
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/env/bin bash
|
||||
|
||||
ipython -i /home/h/.bin/calc.py
|
||||
5
dots/.bin/cam
Executable file
5
dots/.bin/cam
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Open webcam window
|
||||
|
||||
ffplay -f v4l2 -x 640 -y 480 -i /dev/video0 >/dev/null 2>&1 & disown
|
||||
7
dots/.bin/count-json-objects.js
Executable file
7
dots/.bin/count-json-objects.js
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
|
||||
const objLength = obj => Object.keys(obj).length
|
||||
|
||||
fs.readFile(process.argv[2], (err, data) => (err ? console.error(err) : console.log(objLength(JSON.parse(data)))))
|
||||
3
dots/.bin/devdocs
Executable file
3
dots/.bin/devdocs
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
xdg-open https://devdocs.io/offline
|
||||
10
dots/.bin/dmenu-bluetooth
Executable file
10
dots/.bin/dmenu-bluetooth
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
options="Mouse\nHeadphones"
|
||||
|
||||
selected="$(echo -e "$options" | dmenu -i)"
|
||||
|
||||
case "$selected" in
|
||||
"Mouse") toggle-bt-device E4:19:21:56:C8:70;;
|
||||
"Headphones") toggle-bt-device 38:18:4C:D4:74:42;;
|
||||
esac
|
||||
13
dots/.bin/dmenu-read
Executable file
13
dots/.bin/dmenu-read
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Open pdf by title
|
||||
# Note: does not handle incorrect metadata
|
||||
|
||||
dir=/home/h/doc/books
|
||||
|
||||
ag -g ".pdf$" $dir \
|
||||
| xargs -n1 -d '\n' pdfinfo 2> /dev/null \
|
||||
| grep "Title: " \
|
||||
| awk '{for (i=2; i<NF; i++) printf $i " "; printf $NF; printf "\n"}' \
|
||||
| grep -v "Title:"\
|
||||
| dmenu -i -p "Read:"
|
||||
12
dots/.bin/dmenu-spot
Executable file
12
dots/.bin/dmenu-spot
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
options="Play\nPause\nNext\nPrevious"
|
||||
|
||||
selected=$(echo -e "$options" | dmenu -i)
|
||||
|
||||
case "$selected" in
|
||||
"Play") playerctl --player=ncspot play;;
|
||||
"Pause") playerctl --player=ncspot pause;;
|
||||
"Next") playerctl --player=ncspot next;;
|
||||
"Previous") playerctl --player=ncspot previous;;
|
||||
esac
|
||||
10
dots/.bin/fzf-bluetooth
Executable file
10
dots/.bin/fzf-bluetooth
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
options="Mouse\nHeadphones"
|
||||
|
||||
selected="$(echo -e "$options" | fzf)"
|
||||
|
||||
case "$selected" in
|
||||
"Mouse") toggle-bt-device E4:19:21:56:C8:70;;
|
||||
"Headphones") toggle-bt-device 38:18:4C:D4:74:42;;
|
||||
esac
|
||||
30
dots/.bin/fzf-book
Executable file
30
dots/.bin/fzf-book
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Generate menu of book filenames and save paths
|
||||
# Preview window contains metadata
|
||||
|
||||
function get_book_paths {
|
||||
find /home/h/doc/books/ -regex '.*\.\(pdf\|epub\|djvu\)' -type f | sort
|
||||
}
|
||||
|
||||
function select_file {
|
||||
get_book_paths | fzf --delimiter=/ --with-nth=-1
|
||||
}
|
||||
|
||||
function open {
|
||||
if [ -n "$1" ]; then
|
||||
echo "Opening \"$1\""
|
||||
zathura "$1" --fork
|
||||
else
|
||||
echo "No file selected"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--open) open "$(select_file)" ;;
|
||||
--help) printf "open \n" >&2 ;;
|
||||
*) open "$(select_file)" ;;
|
||||
esac
|
||||
|
||||
[[ -n "$selected" ]] && xdg-open "$selected" &> /dev/null & disown
|
||||
30
dots/.bin/fzf-fontnames
Executable file
30
dots/.bin/fzf-fontnames
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
fn="/tmp/fontnames.txt"
|
||||
|
||||
contains_dash() {
|
||||
[[ "$1" =~ - ]]
|
||||
}
|
||||
|
||||
update() {
|
||||
echo "" > "$fn"
|
||||
|
||||
font_list=$(fc-list -f "%{fullname}\n")
|
||||
|
||||
echo "$font_list" | while read line ; do
|
||||
|
||||
first="$(echo "$line" | cut -d',' -f1)"
|
||||
last="$(echo "$line" | cut -d',' -f2)"
|
||||
|
||||
if $(contains_dash "$first"); then
|
||||
echo "$last" >> "$fn"
|
||||
else
|
||||
echo "$first" >> "$fn"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--update) update;;
|
||||
*) cat "$fn" | sort | uniq | awk 'NF' | fzf;;
|
||||
esac
|
||||
3
dots/.bin/fzf-ssh
Executable file
3
dots/.bin/fzf-ssh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ssh "$(ssh-hosts | fzf)"
|
||||
3
dots/.bin/get-anki-decks
Executable file
3
dots/.bin/get-anki-decks
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
curl 127.0.0.1:8765 -X POST -d '{"action": "deckNames", "version": 6}' | jq '.result[]' -r
|
||||
12
dots/.bin/get-anki-reviews-status
Executable file
12
dots/.bin/get-anki-reviews-status
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Get Anki review status from exit code
|
||||
|
||||
num_reviews="$(cat /tmp/anki-reviews)"
|
||||
|
||||
if [ "$num_reviews" -ge "400" ]
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
90
dots/.bin/git-cb
Executable file
90
dots/.bin/git-cb
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
types=(
|
||||
"feature For new features"
|
||||
"bugfix For bug fixes"
|
||||
"hotfix For urgent fixes"
|
||||
"release For preparing releases"
|
||||
"chore For non-code tasks"
|
||||
)
|
||||
|
||||
selected=$(printf '%s\n' "${types[@]}" | fzf --prompt="Select branch type: ") || exit 1
|
||||
type=${selected%% *}
|
||||
|
||||
echo "Fetching Jira tickets..."
|
||||
jira_data=$(jira issue list --assignee=hektor.misplon@rightcrowd.com --order-by=priority --plain --no-headers 2>/dev/null)
|
||||
|
||||
if [[ $? -ne 0 || -z "$jira_data" ]]; then
|
||||
echo "Warning: Could not fetch Jira tickets or no tickets found."
|
||||
echo "Proceeding without ticket ID..."
|
||||
ticket_id=""
|
||||
else
|
||||
# Create formatted list for fzf: "TICKET-123 - Issue description"
|
||||
formatted_tickets=$(echo "$jira_data" | awk '{
|
||||
ticket_id = $2
|
||||
$1 = $2 = ""
|
||||
description = $0
|
||||
gsub(/^[ \t]+/, "", description)
|
||||
if (length(description) > 60) {
|
||||
description = substr(description, 1, 57) "..."
|
||||
}
|
||||
print ticket_id " - " description
|
||||
}')
|
||||
|
||||
if [[ -z "$formatted_tickets" ]]; then
|
||||
echo "No tickets found. Proceeding without ticket ID..."
|
||||
ticket_id=""
|
||||
else
|
||||
# Let user select a ticket or skip
|
||||
echo ""
|
||||
selected_ticket=$(echo -e "SKIP - Create branch without ticket ID\n$formatted_tickets" | \
|
||||
fzf --prompt="Select Jira ticket (or skip): " --height=40%) || exit 1
|
||||
|
||||
if [[ "$selected_ticket" == "SKIP"* ]]; then
|
||||
ticket_id=""
|
||||
else
|
||||
ticket_id=${selected_ticket%% -*}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
editor="${EDITOR:-vi}"
|
||||
tmpfile=$(mktemp)
|
||||
|
||||
if [[ -n "$ticket_id" ]]; then
|
||||
cat > "$tmpfile" << EOF
|
||||
# Selected ticket: $ticket_id
|
||||
# Enter your branch description below in kebab case (e.g. \`my-description\`):
|
||||
# The ticket ID will be automatically included in the branch name.
|
||||
EOF
|
||||
else
|
||||
cat > "$tmpfile" << 'EOF'
|
||||
# Enter your branch description below in kebab case (e.g. `my-description`):
|
||||
EOF
|
||||
fi
|
||||
|
||||
"$editor" "$tmpfile"
|
||||
|
||||
desc=$(grep -v '^#' "$tmpfile" | tr -d '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
rm "$tmpfile"
|
||||
|
||||
if [[ -z "$desc" ]]; then
|
||||
echo "No description provided."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! "$desc" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then
|
||||
echo "Invalid branch description format."
|
||||
echo "Use lowercase letters, numbers, and hyphens only."
|
||||
echo "No trailing or consecutive hyphens allowed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$ticket_id" ]]; then
|
||||
branch="$type/$ticket_id-$desc"
|
||||
else
|
||||
branch="$type/$desc"
|
||||
fi
|
||||
|
||||
echo "Creating branch: $branch"
|
||||
git checkout -b "$branch"
|
||||
2
dots/.bin/jack-to-bt
Executable file
2
dots/.bin/jack-to-bt
Executable file
@@ -0,0 +1,2 @@
|
||||
pactl load-module module-jack-source connect=0
|
||||
pactl load-module module-loopback source=jack_in
|
||||
5
dots/.bin/json-to-yaml
Executable file
5
dots/.bin/json-to-yaml
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import yaml, json, sys
|
||||
|
||||
print(yaml.dump(json.load(open(sys.argv[1])), allow_unicode=True), end='')
|
||||
8
dots/.bin/notify
Executable file
8
dots/.bin/notify
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Pipe into notify-send
|
||||
#
|
||||
# e.g. `echo "Hello world" | notify`
|
||||
|
||||
read -r msg
|
||||
notify-send "$msg" "$@"
|
||||
3
dots/.bin/pacman-remove-unrequired
Executable file
3
dots/.bin/pacman-remove-unrequired
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
sudo pacman -Qtdq | sudo pacman -Rns -
|
||||
3
dots/.bin/pdftitle
Executable file
3
dots/.bin/pdftitle
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
pdfinfo "$1" | head -n 1 | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}'
|
||||
82
dots/.bin/pomo
Executable file
82
dots/.bin/pomo
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: set filetype=python:
|
||||
"""
|
||||
Pomodoro timer
|
||||
|
||||
- Writes pomodoro timer to temporary file so statusbar can read it
|
||||
- Notification on session finish
|
||||
- Notification on break finish
|
||||
"""
|
||||
|
||||
import os
|
||||
import atexit
|
||||
from argparse import ArgumentParser
|
||||
from time import sleep
|
||||
from plyer import notification
|
||||
|
||||
|
||||
@atexit.register
|
||||
def clear():
|
||||
if os.path.exists('/home/h/.local/share/pomo'):
|
||||
os.remove('/home/h/.local/share/pomo')
|
||||
|
||||
def format_mins_secs(mins, secs):
|
||||
return f"{mins:02d}:{secs:02d}"
|
||||
|
||||
|
||||
def make_countdown():
|
||||
def countdown(duration):
|
||||
while duration != 0:
|
||||
mins = duration // 60
|
||||
secs = duration % 60
|
||||
time_str = format_mins_secs(mins, secs)
|
||||
os.system(f'echo -n "{time_str}" > /home/h/.local/share/pomo')
|
||||
sleep(1)
|
||||
duration -= 1
|
||||
return countdown
|
||||
|
||||
|
||||
def main(args):
|
||||
prep_duration = args.prep_duration * 60
|
||||
work_duration = args.work_duration * 60
|
||||
break_duration = args.break_duration * 60
|
||||
repeats = args.repeats
|
||||
|
||||
prep_countdown = make_countdown()
|
||||
work_countdown = make_countdown()
|
||||
break_countdown = make_countdown()
|
||||
|
||||
prep_countdown(prep_duration)
|
||||
|
||||
while repeats != 0:
|
||||
notification.notify(title="Get started")
|
||||
work_countdown(work_duration)
|
||||
if break_duration != 0:
|
||||
notification.notify(title="Time for a break")
|
||||
break_countdown(break_duration)
|
||||
notification.notify(title="Break is over, back to work")
|
||||
repeats -= 1
|
||||
|
||||
|
||||
def handle_signal(signal, frame):
|
||||
# Wait for clear to finish
|
||||
clear()
|
||||
print('Exiting')
|
||||
exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('-w', '--work-duration', type=int,
|
||||
help='Session duration', default=25)
|
||||
parser.add_argument('-b', '--break-duration', type=int,
|
||||
help='Break duration', default=5)
|
||||
parser.add_argument('-r', '--repeats', type=int,
|
||||
help='Numer of sessions', default=1)
|
||||
parser.add_argument('-c', '--clear', action='store_true',
|
||||
help='Clear timer')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args)
|
||||
9
dots/.bin/r5rs
Executable file
9
dots/.bin/r5rs
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
session="r5rs"
|
||||
|
||||
tmux attach-session -t $session || tmux new-session -s $session \; \
|
||||
split-window -h -t $session \; \
|
||||
send-keys -t 0 "vim" C-m \; \
|
||||
send-keys -t 1 "plt-r5rs --no-prim" C-m \; \
|
||||
select-pane -t 0
|
||||
3
dots/.bin/remove-markdown-relative-link-prefix
Executable file
3
dots/.bin/remove-markdown-relative-link-prefix
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
sed -i -r 's/\[*\]\(\.\/([A-z-]*.md)/\]\(\1/g' *.md
|
||||
19
dots/.bin/restore-passwddb
Executable file
19
dots/.bin/restore-passwddb
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Backup existing password databases and
|
||||
# database keys (using date in filename date -u
|
||||
# +%Y-%m-%d_%H-%M-%S)
|
||||
|
||||
RCLONE_REMOTE="proton-drive"
|
||||
|
||||
for f in "$HOME/doc"/*.{kdbx,kdbx.key}; do
|
||||
[ -e "$f" ] || continue
|
||||
echo "Backing up $f to $f-$(date -u +%Y-%m-%d_%H-%M-%S)"
|
||||
cp "$f" "$f-$(date -u +%Y-%m-%d_%H-%M-%S)"
|
||||
done
|
||||
|
||||
echo "Restoring KeePassXC databases and database keys"
|
||||
rclone copyto \
|
||||
"$RCLONE_REMOTE:doc"/ "$HOME/doc/" \
|
||||
--progress \
|
||||
--include "/*.{kdbx,kdbx.key}"
|
||||
23
dots/.bin/reverse-tether-linux-android
Executable file
23
dots/.bin/reverse-tether-linux-android
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function start() {
|
||||
adb start-server
|
||||
nohup gnirehtet autorun &> /dev/null &
|
||||
printf "Started reverse tethering \n"
|
||||
}
|
||||
|
||||
function stop() {
|
||||
adb kill-server
|
||||
gnirehtet stop
|
||||
pkill gnirehtet
|
||||
printf "Stopped reverse tethering \n"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start) start ;;
|
||||
stop) stop ;;
|
||||
restart) stop; start ;;
|
||||
*) printf "start | stop | restart \n" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
13
dots/.bin/rofi-trans
Executable file
13
dots/.bin/rofi-trans
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
options="nl:en\nen:nl\nnl:fr\nfr:nl\nen:fr\nfr:en\nnl:de\nde:nl"
|
||||
|
||||
selected=$(echo -en "$options" | rofi -dmenu -p "source?:target?" -i)
|
||||
|
||||
# notify-send --app-name= -t 3000 "$(trans "$selected" -b "$(rofi -dmenu -p "$selected" &)" \
|
||||
# | tr -d '\n' \
|
||||
# | xclip -sel clip -f)"
|
||||
|
||||
translation="$(trans "$selected" -b "$(rofi -dmenu -p "$selected" &)" | tr -d '\n')"
|
||||
|
||||
echo -e "Copy" | rofi -p "translation" -dmenu -i -mesg "$translation" | xargs -I{} echo -n "$translation" | xclip -selection clipboard
|
||||
25
dots/.bin/save-home
Executable file
25
dots/.bin/save-home
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Back up my $HOME folder to OneDrive using `restic`.
|
||||
#
|
||||
# Adds extra flags needed for using `rclone` with sharepoint WebDav I.e. add
|
||||
# `--ignore-size --ignore-checksum --update` to the default `rclone.args`.
|
||||
#
|
||||
# Select directory in repo using -r rclone:<repo>:<directory>
|
||||
#
|
||||
# Runs `backup` command on $HOME and ignore what is listed in `.resticexclude`
|
||||
#
|
||||
# ```/etc/restic-env
|
||||
# export B2_ACCOUNT_ID=
|
||||
# export B2_ACCOUNT_KEY=
|
||||
# ```
|
||||
#
|
||||
# `restic -r b2:desktop-arch init`
|
||||
|
||||
source /etc/restic-env
|
||||
restic -r "$RESTIC_REPOSITORY:$HOSTNAME" backup \
|
||||
--tag "hektor" \
|
||||
--one-file-system \
|
||||
--files-from="$HOME/.resticinclude" \
|
||||
--exclude-file="$HOME/.resticexclude" \
|
||||
--verbose=3
|
||||
75
dots/.bin/save-passwddb
Executable file
75
dots/.bin/save-passwddb
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Save (encrypted) password database to cloud storage
|
||||
#
|
||||
# Usage:
|
||||
# save-passwddb - Save databases to cloud
|
||||
# save-passwddb init - Restore databases from cloud (with single backup archive)
|
||||
|
||||
RCLONE_REMOTE="proton"
|
||||
SOURCE_DIR="$HOME/doc"
|
||||
TARGET_DIR="$RCLONE_REMOTE:doc"
|
||||
BACKUP_DIR="$HOME/doc/bak"
|
||||
|
||||
function save_databases() {
|
||||
if [ 0 -lt "$(ls $SOURCE_DIR/*.kdbx 2>/dev/null | wc -w)" ]; then
|
||||
echo "[save] Saving KeePassXC databases and database keys"
|
||||
rclone copy "$SOURCE_DIR" "$TARGET_DIR" \
|
||||
--include "/*.{kdbx,kdbx.key}" \
|
||||
--progress
|
||||
echo "[save] Done"
|
||||
else
|
||||
echo "[save] No password database found, restore with:"
|
||||
echo ""
|
||||
echo " $0 init"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_existing() {
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
local timestamp=$(date +%Y%m%d-%H%M%S)
|
||||
local backup_file="$BACKUP_DIR/passwddb_backup_${timestamp}.tar.gz"
|
||||
|
||||
echo "[backup] Creating backup archive: ${backup_file}"
|
||||
tar -czf "$backup_file" -C "$SOURCE_DIR" $(find "$SOURCE_DIR" -maxdepth 1 -type f \( -name "*.kdbx" -o -name "*.kdbx.key" \) -printf "%f ")
|
||||
echo "[backup] Backup complete"
|
||||
}
|
||||
|
||||
function restore_databases() {
|
||||
echo "[init] Checking for existing files..."
|
||||
|
||||
local existing_files=$(find "$SOURCE_DIR" -maxdepth 1 -type f \( -name "*.kdbx" -o -name "*.kdbx.key" \) -print)
|
||||
|
||||
if [ -n "$existing_files" ]; then
|
||||
echo "[init] Found existing database files:"
|
||||
echo "$existing_files" | while read -r file; do
|
||||
echo " - $file"
|
||||
done
|
||||
read -p "[init] Create backup archive of existing files? [y/N] " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
backup_existing
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "[init] Restoring KeePassXC databases and database keys"
|
||||
mkdir -p "$SOURCE_DIR"
|
||||
rclone copy "$TARGET_DIR" "$SOURCE_DIR" \
|
||||
--include "*.{kdbx,kdbx.key}" \
|
||||
--progress
|
||||
echo "[init] Done"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
""|save)
|
||||
save_databases
|
||||
;;
|
||||
init)
|
||||
restore_databases
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [init|save]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
12
dots/.bin/save-ssh-host
Executable file
12
dots/.bin/save-ssh-host
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
selected_hosts="$(ssh-hosts | fzf -m)"
|
||||
|
||||
for host in $selected_hosts; do
|
||||
echo "Saving $host"
|
||||
directories="$(ssh "$host" ls | fzf -m)"
|
||||
for directory in $directories; do
|
||||
echo "Saving $host:$directory"
|
||||
ssh "$host" "(tar cvzf - ~/$directory)" > "${host}_${directory}.tar.gz"
|
||||
done
|
||||
done
|
||||
4
dots/.bin/save-zk
Executable file
4
dots/.bin/save-zk
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$ZK_PATH" || echo "No zettelkasten directory found"
|
||||
git a . && git commit -m "Update" && git push
|
||||
22
dots/.bin/sb-anki
Executable file
22
dots/.bin/sb-anki
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Anki review percentage for statusbar
|
||||
|
||||
num_to_review=200
|
||||
|
||||
# Get current card count from Anki
|
||||
count=$(curl -s 127.0.0.1:8765 -X POST -d '{"action": "getNumCardsReviewedToday", "version": 6}' | jq '.result')
|
||||
|
||||
if [ -z "$count" ]
|
||||
then
|
||||
if [ -s /tmp/anki-reviews ]; then
|
||||
true
|
||||
else
|
||||
echo "-1" > /tmp/anki-reviews
|
||||
fi
|
||||
else
|
||||
echo "$count" > /tmp/anki-reviews
|
||||
fi
|
||||
|
||||
num_reviews=$(cat /tmp/anki-reviews)
|
||||
echo -n -e " Reviews: $(python3 -c "print('{:.2%}'.format($num_reviews/$num_to_review))") "
|
||||
13
dots/.bin/sb-battery
Executable file
13
dots/.bin/sb-battery
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cap="$(cat /sys/class/power_supply/BAT0/capacity)"
|
||||
|
||||
if [ "$cap" -ge 33 ];then
|
||||
color="\x01"
|
||||
elif [ "$cap" -ge 10 ]; then
|
||||
color="\x03"
|
||||
else
|
||||
color="\x04"
|
||||
fi
|
||||
|
||||
echo -n -e "$color $cap% \x01"
|
||||
3
dots/.bin/sb-date
Executable file
3
dots/.bin/sb-date
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo -n -e "Week $(date '+%V') $(date '+%a %d %b %H:%M') "
|
||||
7
dots/.bin/sb-internet
Executable file
7
dots/.bin/sb-internet
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
if grep -xq 'up' /sys/class/net/w*/operstate 2>/dev/null ; then
|
||||
wifiicon="$(awk '/^\s*w/ { print "WiFi", int($3 * 100 / 70) "% " }' /proc/net/wireless)"
|
||||
fi
|
||||
|
||||
printf " %s%s%s" "$wifiicon" "$(sed "s/down//;s/up/Ethernet/" /sys/class/net/e*/operstate 2>/dev/null)"
|
||||
3
dots/.bin/sb-pomo
Executable file
3
dots/.bin/sb-pomo
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
[ -f "/tmp/pomo" ] && cat /tmp/pomo || echo ""
|
||||
4
dots/.bin/sb-project
Executable file
4
dots/.bin/sb-project
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Render contents of $HOME/.project if present
|
||||
[ -f "$HOME/.project" ] && cat "$HOME/.project" || echo ""
|
||||
7
dots/.bin/sb-tasks
Executable file
7
dots/.bin/sb-tasks
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
num_done="$(task end.after:today status:completed count)"
|
||||
num_pending="$(($(task count status:pending) + $num_done))"
|
||||
num_waiting="$(($(task count status:waiting)))"
|
||||
|
||||
echo -e "Tasks: $num_done/$num_pending+$num_waiting"
|
||||
12
dots/.bin/sb-wg
Executable file
12
dots/.bin/sb-wg
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Reference: https://github.com/mil-ad/polybar-wireguard
|
||||
|
||||
connected_interfaces=$(networkctl | grep -P "\d+ .* wireguard routable" -o | cut -d" " -f2)
|
||||
|
||||
if [ -n "$connected_interfaces" ];
|
||||
then
|
||||
for interface in $connected_interfaces; do echo "$interface"; done
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
51
dots/.bin/screen-temperature
Executable file
51
dots/.bin/screen-temperature
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
DEFAULT_TEMPERATURE = 3500
|
||||
|
||||
try:
|
||||
with open('/tmp/temperature', 'r') as temp_file:
|
||||
current_temperature = int(temp_file.read())
|
||||
except FileNotFoundError:
|
||||
current_temperature = DEFAULT_TEMPERATURE
|
||||
|
||||
# If no argument is given print the current temperature
|
||||
if len(sys.argv) == 1:
|
||||
print(current_temperature)
|
||||
sys.exit(0)
|
||||
elif len(sys.argv) != 2:
|
||||
print("""
|
||||
Usage:
|
||||
|
||||
screen-temperature
|
||||
print current temperature
|
||||
|
||||
screen-temperature <temperature>
|
||||
set screen temperature to <temperature>
|
||||
|
||||
screen-temperature <+|-><temperature>
|
||||
increase or decrease screen temperature by <temperature>
|
||||
""")
|
||||
sys.exit(1)
|
||||
|
||||
temperature_change = sys.argv[1]
|
||||
|
||||
if temperature_change.startswith("+"):
|
||||
new_temperature = current_temperature + int(temperature_change[1:])
|
||||
elif temperature_change.startswith("-"):
|
||||
new_temperature = current_temperature - int(temperature_change[1:])
|
||||
else:
|
||||
new_temperature = int(temperature_change)
|
||||
|
||||
try:
|
||||
subprocess.run(["redshift", "-O", str(new_temperature), "-P"], check=True)
|
||||
with open('/tmp/temperature', 'w') as temp_file:
|
||||
temp_file.write(str(new_temperature) + '\n')
|
||||
# Send notification
|
||||
subprocess.run(
|
||||
["notify-send", str(new_temperature) + "K"])
|
||||
except subprocess.CalledProcessError:
|
||||
print("Error: could not set screen temperature.")
|
||||
sys.exit(1)
|
||||
25
dots/.bin/script
Executable file
25
dots/.bin/script
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Script to create script
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: script <scriptname>"
|
||||
exit
|
||||
fi
|
||||
|
||||
path="$HOME/.bin/$1"
|
||||
|
||||
# Prevent overwriting existing script
|
||||
set -o noclobber
|
||||
|
||||
# Create script
|
||||
cat > "$path" << EOF
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
EOF
|
||||
|
||||
chmod +x "$path"
|
||||
|
||||
# Open script in editor on line 3
|
||||
"$EDITOR" +3 "$path"
|
||||
208
dots/.bin/setup
Executable file
208
dots/.bin/setup
Executable file
@@ -0,0 +1,208 @@
|
||||
#!/bin/bash
|
||||
|
||||
pac_list=(
|
||||
at
|
||||
automake
|
||||
autopep8
|
||||
base
|
||||
base-devel
|
||||
bash-completion
|
||||
bash-language-server
|
||||
bc
|
||||
brightnessctl
|
||||
chromium
|
||||
dmidecode
|
||||
entr
|
||||
eslint_d
|
||||
feh
|
||||
firefox-developer-edition
|
||||
firefox-tridactyl
|
||||
firefox-tridactyl-native
|
||||
firefox-tridactyl-native-debug
|
||||
fzf
|
||||
gcc
|
||||
git
|
||||
haskell-language-server
|
||||
haskell-ormolu
|
||||
hsetroot
|
||||
htop
|
||||
httpie
|
||||
jq
|
||||
keepassxc
|
||||
kitty
|
||||
lua-language-server
|
||||
make
|
||||
man-db
|
||||
man-pages
|
||||
neovim
|
||||
nmap
|
||||
nodejs-lts-jod
|
||||
pacman-contrib
|
||||
pandoc-cli
|
||||
pandoc-crossref
|
||||
parallel
|
||||
pass
|
||||
pkgbuild-language-server
|
||||
pnpm
|
||||
ripgrep
|
||||
sshfs
|
||||
stylelint
|
||||
svelte-language-server
|
||||
tailwindcss-language-server
|
||||
task
|
||||
tldr
|
||||
tmux
|
||||
tmuxp
|
||||
tree
|
||||
tree-sitter-cli
|
||||
ts-node
|
||||
typescript-language-server
|
||||
unzip
|
||||
vim-language-server
|
||||
wget
|
||||
xclip
|
||||
yaml-language-server
|
||||
)
|
||||
|
||||
aurpac_list=(
|
||||
hadolint-bin
|
||||
nvm
|
||||
nvimpager
|
||||
paru
|
||||
tmux-bash-completion-git
|
||||
ttf-iosevka-term-ss08
|
||||
vim-plug
|
||||
vtsls
|
||||
xbanish
|
||||
)
|
||||
|
||||
install() {
|
||||
local package="$1"
|
||||
if pacman -Qi "$package" &> /dev/null; then
|
||||
echo "$package is already installed"
|
||||
else
|
||||
echo "Installing " "$package"
|
||||
sudo pacman -S --noconfirm --needed "$package"
|
||||
fi
|
||||
}
|
||||
|
||||
aurpac() {
|
||||
git clone "https://aur.archlinux.org/$1.git" "$HOME/.build/$1"
|
||||
}
|
||||
|
||||
install_packages() {
|
||||
announce "Installing packages"
|
||||
local count
|
||||
for pac in "${pac_list[@]}" ; do
|
||||
count=$((count+1))
|
||||
install "$pac";
|
||||
done
|
||||
echo "$count packages installed"
|
||||
}
|
||||
|
||||
install_dotfiles() {
|
||||
announce "Installing dotfiles"
|
||||
origin="https://git.hektormisplon.xyz/hektor/dots"
|
||||
git clone "$origin" "$HOME/dots"
|
||||
cp -r "$HOME/dots/.git" "$HOME/.git"
|
||||
git --git-dir="$HOME/.git" config --local status.showUntrackedFiles no
|
||||
git --git-dir="$HOME/.git" stash -m "[dots]"
|
||||
git --git-dir="$HOME/.git" stash apply
|
||||
git --git-dir="$HOME/.git" restore "$HOME"
|
||||
}
|
||||
|
||||
install_aur_packages() {
|
||||
announce "Installing AUR packages"
|
||||
local count
|
||||
for package in "${aurpac_list[@]}" ; do
|
||||
if pacman -Qi "$1" &> /dev/null; then
|
||||
echo "$1 is already installed"
|
||||
else
|
||||
count=$((count+1))
|
||||
aurpac "$package" && makepkg -si -D "$HOME/.build/$package"
|
||||
fi
|
||||
done
|
||||
echo "$count AUR packages installed"
|
||||
}
|
||||
|
||||
setup_neovim() {
|
||||
announce "Setting up NeoVim"
|
||||
git clone --depth=1 https://github.com/savq/paq-nvim.git \
|
||||
"${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/paqs/start/paq-nvim
|
||||
}
|
||||
|
||||
setup_keyboard() {
|
||||
announce "Setting up keyboard"
|
||||
install "interception-tools"
|
||||
install "interception-caps2esc"
|
||||
udevmon_config_contents="\
|
||||
- JOB: intercept -g \$DEVNODE | caps2esc -m 1 | uinput -d \$DEVNODE
|
||||
DEVICE:
|
||||
EVENTS:
|
||||
EV_KEY: [KEY_CAPSLOCK]"
|
||||
if [ -f /etc/interception/udevmon.yaml ] && diff -q <(echo "$udevmon_config_contents") /etc/interception/udevmon.yaml; then
|
||||
echo "udevmon config already exists"
|
||||
echo "$udevmon_config_contents"
|
||||
elif [ -f /etc/interception/udevmon.yaml ]; then
|
||||
echo "interception udevmon.yaml already exists"
|
||||
cat /etc/interception/udevmon.yaml
|
||||
echo "verify if this config matches the one below"
|
||||
echo "$udevmon_config_contents"
|
||||
else
|
||||
echo "interception udevmon.yaml does not exist, creating one"
|
||||
sudo bash -c "echo '$udevmon_config_contents' > /etc/interception/udevmon.yaml"
|
||||
fi
|
||||
|
||||
sudo systemctl enable --now udevmon.service
|
||||
|
||||
if pgrep -x caps2esc > /dev/null; then
|
||||
echo "caps2esc is already running"
|
||||
else
|
||||
caps2esc -m 1
|
||||
fi
|
||||
}
|
||||
|
||||
configure_gnome() {
|
||||
announce "Configuring Gnome"; setup-gnome
|
||||
}
|
||||
|
||||
setup_firewall() {
|
||||
announce "Configuring firewalld"
|
||||
install firewalld
|
||||
sudo systemctl enable --now firewalld
|
||||
}
|
||||
|
||||
setup_docker() {
|
||||
announce "Setting up Docker"
|
||||
install docker
|
||||
install docker-compose
|
||||
sudo systemctl enable --now docker.socket
|
||||
sudo usermod -aG docker "$USER"
|
||||
echo "User added to docker group, please restart your session"
|
||||
}
|
||||
|
||||
announce() {
|
||||
local message="$1"
|
||||
echo " "
|
||||
echo "[dots] $message"
|
||||
echo " "
|
||||
}
|
||||
|
||||
confirm() {
|
||||
local question="$1"
|
||||
read -r -p "[dots] $question? [y/N]" -n 1
|
||||
case "$REPLY" in y|Y ) "$2";; * ) echo "Skipping"; esac
|
||||
}
|
||||
|
||||
printf '%s\n' "${pac_list[@]}"
|
||||
confirm "Install these packages? " install_packages
|
||||
printf '%s\n' "${aurpac_list[@]}"
|
||||
confirm "Install these AUR packages? " install_aur_packages
|
||||
confirm "Setup NeoVim? " setup_neovim
|
||||
confirm "Install dotfiles? " install_dotfiles
|
||||
confirm "Setup keyboard? " setup_keyboard
|
||||
if pacman -Qi "gdm" &> /dev/null; then
|
||||
confirm "Configure Gnome? " configure_gnome
|
||||
fi
|
||||
confirm "Setup firewall? " setup_firewall
|
||||
confirm "Setup Docker? " setup_docker
|
||||
37
dots/.bin/setup-gnome
Executable file
37
dots/.bin/setup-gnome
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
gsettings set org.gnome.desktop.background primary-color "#555555"
|
||||
|
||||
gsettings set org.gnome.desktop.wm.preferences workspace-names "['sh', 'www', 'dev', 'info', 'etc']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings close "['<Shift><Super>Delete']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings switch-applications "['<Super>j']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings switch-applications-backward "['<Super>k']"
|
||||
gsettings set org.gnome.shell.keybindings toggle-application-view "['<Super>p']"
|
||||
gsettings set org.gnome.mutter center-new-windows true
|
||||
gsettings set org.gnome.shell.keybindings toggle-quick-settings []
|
||||
|
||||
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-1 "['<Super>a']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-2 "['<Super>s']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-3 "['<Super>d']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-4 "['<Super>f']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-5 "['<Super>g']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-1 "['<Super><Shift>a']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-2 "['<Super><Shift>s']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-3 "['<Super><Shift>d']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-4 "['<Super><Shift>f']"
|
||||
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-5 "['<Super><Shift>g']"
|
||||
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/']"
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ name "Kitty"
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ command "kitty"
|
||||
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ binding "<Shift><Super>Return"
|
||||
|
||||
gsettings set org.gnome.shell.keybindings screenshot "['Print']"
|
||||
|
||||
gsettings set org.gnome.desktop.wm.preferences num-workspaces "5"
|
||||
gsettings set org.gnome.mutter dynamic-workspaces "false"
|
||||
gsettings set org.gnome.shell.extensions.window-list display-all-workspaces "true"
|
||||
gsettings set org.gnome.shell.app-switcher current-workspace-only "true"
|
||||
|
||||
gsettings set org.gnome.login-screen logo ''
|
||||
gsettings set org.gnome.shell favorite-apps "['firefox-developer-edition.desktop']"
|
||||
20
dots/.bin/setup-zk
Executable file
20
dots/.bin/setup-zk
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -d ~/.zk ]; then
|
||||
echo "[zk] Setting up zettelkasten"
|
||||
gh repo clone zk ~/.zk
|
||||
else
|
||||
echo "[zk] Zettelkasten already set up."
|
||||
fi
|
||||
|
||||
read -p "Would you like open your zettelkasten? [y/N] " -n 1 -r
|
||||
echo
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
if [ -x "$(command -v zk)" ]; then
|
||||
zk
|
||||
else
|
||||
echo "Error: 'zk' command not found or not executable"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
5
dots/.bin/ssh-hosts
Executable file
5
dots/.bin/ssh-hosts
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ssh_hosts="$(grep -E 'Host [a-z0-9\-]*$' ~/.ssh/config | awk '{print $2}')"
|
||||
|
||||
echo "$ssh_hosts"
|
||||
144
dots/.bin/taskdeps
Executable file
144
dots/.bin/taskdeps
Executable file
@@ -0,0 +1,144 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import subprocess
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def get_task_data():
|
||||
command = (
|
||||
"task +PENDING or +WAITING -COMPLETED -DELETED export | "
|
||||
"jq '[.[] | {uuid: .uuid, id, depends: .depends, description: .description, status: .status }]'"
|
||||
)
|
||||
output = subprocess.check_output(command, shell=True)
|
||||
return json.loads(output)
|
||||
|
||||
|
||||
def parse_task_data(data):
|
||||
dependency_graph = defaultdict(list)
|
||||
task_details = {}
|
||||
dependent_tasks = set()
|
||||
|
||||
for task in data:
|
||||
task_id = task["uuid"]
|
||||
task_details[task_id] = {
|
||||
"id": task.get("id", "?"),
|
||||
"description": task.get("description", "No description"),
|
||||
"status": task.get("status", "Unknown status"),
|
||||
}
|
||||
if task["depends"]:
|
||||
for dependency in task["depends"]:
|
||||
dependency_graph[dependency].append(task_id)
|
||||
dependent_tasks.add(task_id)
|
||||
|
||||
root_tasks = set(task_details.keys()) - dependent_tasks
|
||||
return task_details, dependency_graph, root_tasks
|
||||
|
||||
|
||||
def get_all_parents(task_id, dependency_graph):
|
||||
return [
|
||||
parent for parent, children in dependency_graph.items() if task_id in children
|
||||
]
|
||||
|
||||
|
||||
def build_ascii_dag(
|
||||
task_id,
|
||||
task_details,
|
||||
dependency_graph,
|
||||
prefix="",
|
||||
is_last=True,
|
||||
show_id=True,
|
||||
visited=None,
|
||||
):
|
||||
if visited is None:
|
||||
visited = set()
|
||||
|
||||
if task_id in visited:
|
||||
return [f"{prefix}{'└── ' if is_last else '├── '}... (cycle detected)"]
|
||||
|
||||
visited.add(task_id)
|
||||
|
||||
task_info = task_details[task_id]
|
||||
task_line = f"{prefix}{'└── ' if is_last else '├── '}{task_info['id'] + ': ' if show_id else ''}{task_info['description']} ({task_info['status']})"
|
||||
lines = [task_line]
|
||||
|
||||
children = dependency_graph.get(task_id, [])
|
||||
for idx, child in enumerate(children):
|
||||
child_is_last = idx == len(children) - 1
|
||||
child_prefix = prefix + (" " if is_last else "│ ")
|
||||
lines.extend(
|
||||
build_ascii_dag(
|
||||
child,
|
||||
task_details,
|
||||
dependency_graph,
|
||||
child_prefix,
|
||||
child_is_last,
|
||||
show_id,
|
||||
visited.copy(),
|
||||
)
|
||||
)
|
||||
|
||||
return lines
|
||||
|
||||
|
||||
def render_dependency_dag(task_details, dependency_graph, root_tasks, show_id):
|
||||
dag_lines = []
|
||||
global_visited = set()
|
||||
|
||||
def dfs(task_id, prefix="", is_last=True, visited=None):
|
||||
if visited is None:
|
||||
visited = set()
|
||||
|
||||
if task_id in visited:
|
||||
return
|
||||
|
||||
visited.add(task_id)
|
||||
global_visited.add(task_id)
|
||||
|
||||
task_info = task_details[task_id]
|
||||
task_line = f"{prefix}{'└── ' if is_last else '├── '}{str(task_info['id']) + ': ' if show_id else ''}{task_info['description']} ({task_info['status']})"
|
||||
dag_lines.append(task_line)
|
||||
|
||||
children = dependency_graph.get(task_id, [])
|
||||
for idx, child in enumerate(children):
|
||||
child_is_last = idx == len(children) - 1
|
||||
child_prefix = prefix + (" " if is_last else "│ ")
|
||||
dfs(child, child_prefix, child_is_last, visited.copy())
|
||||
|
||||
root_tasks_with_children = [
|
||||
root for root in root_tasks if dependency_graph.get(root, [])
|
||||
]
|
||||
for root in sorted(
|
||||
root_tasks_with_children,
|
||||
key=lambda x: len(dependency_graph.get(x, [])),
|
||||
reverse=True,
|
||||
):
|
||||
if root not in global_visited:
|
||||
dfs(root)
|
||||
dag_lines.append("")
|
||||
|
||||
return "\n".join(dag_lines).rstrip()
|
||||
|
||||
|
||||
def main(args):
|
||||
data = get_task_data()
|
||||
task_details, dependency_graph, root_tasks = parse_task_data(data)
|
||||
ascii_dag = render_dependency_dag(
|
||||
task_details, dependency_graph, root_tasks, show_id=args.show_id
|
||||
)
|
||||
print(ascii_dag)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generates a task dependency DAG for Taskwarrior tasks."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--show-id",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Include task IDs in the output.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
main(args)
|
||||
26
dots/.bin/tidalcycles
Executable file
26
dots/.bin/tidalcycles
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euf -o pipefail
|
||||
|
||||
VIM=${VIM:-"vim"}
|
||||
TMUX=${TMUX:-"tmux"}
|
||||
|
||||
FILE=${FILE:-"$(date +%F).tidal"}
|
||||
SESSION=${SESSION:-"tidal"}
|
||||
|
||||
TIDAL_BOOT_PATH=${TIDAL_BOOT_PATH:-""}
|
||||
GHCI=${GHCI:-""}
|
||||
|
||||
args=${*:-$FILE}
|
||||
|
||||
# attach if session else create
|
||||
$TMUX attach-session -t "$SESSION" || $TMUX new-session -s "$SESSION" \; \
|
||||
split-window -h -t "$SESSION" \; \
|
||||
send-keys -t 0 "$VIM $args" C-m \; \
|
||||
send-keys -t 1 "TIDAL_BOOT_PATH=$TIDAL_BOOT_PATH GHCI=$GHCI tidal" C-m \; \
|
||||
new-window -t "$SESSION":2 -n SuperDirt \; \
|
||||
send-keys -t 0 "jack_control start && sclang ~/dev/live/scripts/start.scd" C-m \; \
|
||||
select-window -t 1 \; \
|
||||
resize-pane -t 1 -x 100 \; \
|
||||
resize-pane -t 0 -x 125 \; \
|
||||
select-pane -t 0
|
||||
13
dots/.bin/tmux-workspace
Executable file
13
dots/.bin/tmux-workspace
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
session="main"
|
||||
|
||||
tmux attach-session -t $session || tmux new-session -s $session \; \
|
||||
rename-window task \; \
|
||||
send-keys -t 1 "task" C-m \; \
|
||||
new-window -n zk \; \
|
||||
send-keys -t 2 "nvim $ZK_PATH/index.md" C-m \; \
|
||||
new-window -n term \; \
|
||||
new-window -n music \; \
|
||||
send-keys -t 4 "echo 'TODO: open music player'" C-m \; \
|
||||
select-window -t 1 \;
|
||||
11
dots/.bin/toggle-bt-device
Executable file
11
dots/.bin/toggle-bt-device
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
status="$(bluetoothctl info "$1" | grep Connected | cut -f 2 -d ':' | cut -f 2 -d ' ')"
|
||||
|
||||
if [ "$status" == "yes" ]
|
||||
then
|
||||
bluetoothctl disconnect "$1"
|
||||
else
|
||||
trust "$1"
|
||||
bluetoothctl connect "$1"
|
||||
fi
|
||||
3
dots/.bin/update
Executable file
3
dots/.bin/update
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
sudo pacman -Syu
|
||||
5
dots/.bin/update-vim
Executable file
5
dots/.bin/update-vim
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Tiny Vim update helper
|
||||
|
||||
nvim +PlugUpgrade +PlugUpdate +CocUpdate
|
||||
33
dots/.bin/zk
Executable file
33
dots/.bin/zk
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ "$TERM_PROGRAM" = tmux ]; then
|
||||
cd ~/.zk && $EDITOR "$(cat ~/.zk/current-zettel.txt)"
|
||||
else
|
||||
echo 'Not in tmux'
|
||||
echo 'Choose an option:'
|
||||
echo '1. Open in tmux'
|
||||
echo '2. Open in current terminal'
|
||||
read -r -p 'Enter your choice: ' choice
|
||||
case $choice in
|
||||
1)
|
||||
# Check if a tmux session is running with a window named zk
|
||||
if tmux list-windows -F '#{window_name}' | grep -q zk; then
|
||||
# Attach to the session containing the 'zk' window
|
||||
session="$(tmux list-windows -F '#{window_name} #{session_name}' | grep zk | head -n 1 | awk '{ print $2 }')"
|
||||
tmux attach -t "$session"
|
||||
else
|
||||
# Create session with a window named 'zk' and start nvim
|
||||
tmux new-session -s zk -n zk -d
|
||||
tmux send-keys -t zk:zk "cd ~/.zk && $EDITOR \"\$(cat ~/.zk/current-zettel.txt)\"" Enter
|
||||
tmux attach -t zk
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
cd ~/.zk && $EDITOR "$(cat ~/.zk/current-zettel.txt)"
|
||||
;;
|
||||
*)
|
||||
echo 'Not opening Zettelkasten'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
Reference in New Issue
Block a user