Initial commit
This commit is contained in:
92
src/main.sh
Executable file
92
src/main.sh
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
# Load helper methods
|
||||
. "sh/info.sh"
|
||||
|
||||
# Load helper methods
|
||||
. "sh/helper.sh"
|
||||
|
||||
# Load MusicBrainz methods
|
||||
. "sh/mb.sh"
|
||||
|
||||
if [ "${1:-}" = "--internal-reload" ]; then
|
||||
sleep 2
|
||||
while [ -f "$LOCKFILE" ]; do
|
||||
sleep 1
|
||||
done
|
||||
cat "$RESULTS"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--internal-search" ]; then
|
||||
printf "" >"$RESULTS"
|
||||
if [ -f "$PIDFILE" ]; then
|
||||
pid=$(cat "$PIDFILE")
|
||||
rm -f "$PIDFILE"
|
||||
kill -9 "$pid" >/dev/null 2>&1 || true
|
||||
fi
|
||||
[ ! "${2}" ] && exit 0
|
||||
# Save current pid
|
||||
echo "$$" >"$PIDFILE"
|
||||
sleep 1
|
||||
touch "$LOCKFILE"
|
||||
mb_browse_artists "$2" |
|
||||
$JQ -r '.artists[] | [.id, .type, .name, .disambiguation, .["life-span"].begin, .["life-span"].end] | join("\t")' |
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v format_person="$FORMAT_PERSON" \
|
||||
-v format_group="$FORMAT_GROUP" \
|
||||
-v format_disambiguation="$FORMAT_DISAMBIGUATION" \
|
||||
"$AWK_ARTISTS" |
|
||||
tee "$RESULTS" ||
|
||||
true
|
||||
rm -f "$LOCKFILE" "$PIDFILE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Load theme
|
||||
. "sh/theme.sh"
|
||||
|
||||
# Load AWK scripts
|
||||
. "sh/awk.sh"
|
||||
|
||||
# Load tools
|
||||
. "sh/tools.sh"
|
||||
|
||||
if [ "${1:-}" = "--help" ]; then
|
||||
$CAT <<EOF
|
||||
Usage: \`$0\` [ \`--help\` ]
|
||||
|
||||
Options:
|
||||
\`--help\`: Show this help and exit.
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Generate filenames for temporary files
|
||||
tmpdir=$(mktemp -d)
|
||||
LOCKFILE="$tmpdir/lock"
|
||||
RESULTS="$tmpdir/results"
|
||||
PIDFILE="$tmpdir/pid"
|
||||
export LOCKFILE RESULTS PIDFILE
|
||||
|
||||
if [ "${1:-}" = "--search" ]; then
|
||||
$0 --internal-search "$2"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while true; do
|
||||
sel=$(
|
||||
printf "" |
|
||||
$FZF \
|
||||
--ansi \
|
||||
--no-sort \
|
||||
--disabled \
|
||||
--delimiter="\t" \
|
||||
--with-nth="{2}" \
|
||||
--bind="change:execute-silent($0 --internal-search \$FZF_QUERY &)+reload($0 --internal-reload)"
|
||||
)
|
||||
echo "$sel"
|
||||
done
|
Reference in New Issue
Block a user