2024-05-30 09:11:15 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
SONGS_PATH="content/"
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
Usage: $0 <command> [options]
|
|
|
|
|
|
|
|
Commands:
|
2024-05-30 22:17:46 +02:00
|
|
|
help Show this help message and exit
|
|
|
|
new [name] Create a new song [with the specified name]
|
|
|
|
edit <name> Edit song with $EDITOR (taken from the EDITOR env var)
|
|
|
|
iedit <name> Interactive edit with PDF preview
|
2024-05-30 09:11:15 +02:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
$0 help
|
|
|
|
$0 new [song-name]
|
2024-05-30 21:08:39 +02:00
|
|
|
$0 edit <song-name>
|
2024-05-30 22:17:46 +02:00
|
|
|
$0 iedit <song-name>
|
2024-05-30 09:11:15 +02:00
|
|
|
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
create_new_song() {
|
|
|
|
if [ -z "$name" ]; then
|
|
|
|
read -p "Song name (file-name-in-path): " name
|
|
|
|
fi
|
|
|
|
read -p "Song title: " title
|
|
|
|
read -p "Artist: " artist
|
|
|
|
read -p "Category: " category
|
|
|
|
|
|
|
|
mkdir -p "$SONGS_PATH/$name"
|
|
|
|
echo -e "{title: $title}\n{artist: $artist}" > "$SONGS_PATH/$name/$name.cho"
|
|
|
|
echo -e "+++\ntitle = \"$title\"\n[taxonomies]\ncategory = [\"$category\"]\nartist = [\"$artist\"]\n+++" > "$SONGS_PATH/$name/index.md"
|
|
|
|
echo "Song $name created."
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$#" -lt 1 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
new)
|
|
|
|
if [ "$#" -eq 2 ]; then
|
|
|
|
name="$2"
|
|
|
|
fi
|
|
|
|
create_new_song
|
|
|
|
;;
|
2024-05-30 21:08:39 +02:00
|
|
|
edit)
|
|
|
|
if [ "$#" -eq 2 ]; then
|
|
|
|
$EDITOR "content/$2/$2.cho"
|
|
|
|
else
|
|
|
|
echo -e "Missing song name\n"
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
;;
|
2024-05-30 22:17:46 +02:00
|
|
|
iedit)
|
|
|
|
if [ "$#" -eq 2 ]; then
|
|
|
|
touch "content/$2/$2.pdf"
|
|
|
|
zathura "content/$2/$2.pdf" & # I don't give a fuck; use Zathura or send a patch
|
|
|
|
$EDITOR "content/$2/$2.cho"
|
|
|
|
else
|
|
|
|
echo -e "Missing song name\n"
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
;;
|
2024-05-30 09:11:15 +02:00
|
|
|
help)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo -e "Invalid argument: $1\n"
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|