(bin): create bookmark generation script

This commit is contained in:
frosty 2024-07-29 04:15:47 -04:00
parent 91a7f1ce67
commit 1a57123ba1

35
.local/bin/bookmarks-gen Executable file
View file

@ -0,0 +1,35 @@
#!/bin/sh
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
EDITOR="${EDITOR:-vim}"
BM_DIRS="$XDG_CONFIG_HOME/bookmarks/directories"
BM_FILES="$XDG_CONFIG_HOME/bookmarks/files"
OUTPUT_FILE="$XDG_CONFIG_HOME/shell/10-bookmarks.sh"
cleanup_file() {
while IFS= read -r line; do
[ -z "$line" ] && continue
while IFS='#' read -r content _; do
[ -n "$content" ] && printf '%s\n' "$content"
done <<EOF
$line
EOF
done <"$1"
}
{
while IFS=' ' read -r name value; do
printf "alias %s='cd %s'\n" "$name" "$value"
done <<EOF
$(cleanup_file "$BM_DIRS")
EOF
# TODO(frosty): Support other applications per line, instead of only using $EDITOR.
while IFS=' ' read -r name value; do
printf "alias %s='%s %s'\n" "$name" "$EDITOR" "$value"
done <<EOF
$(cleanup_file "$BM_FILES")
EOF
} >"$OUTPUT_FILE"