diff --git a/src/main.sh b/src/main.sh index 8a8d069..014ec84 100755 --- a/src/main.sh +++ b/src/main.sh @@ -50,38 +50,32 @@ set -eu # FZF handlers . "sh/fzf.sh" -if [ "${1:-}" = "--fzf-reload" ]; then +case "${1:-}" in +"--fzf-reload") fzf_handle_reload exit 0 -fi - -if [ "${1:-}" = "--fzf-load" ]; then + ;; +"--fzf-load") fzf_handle_load exit 0 -fi - -if [ "${1:-}" = "--fzf-info" ]; then + ;; +"--fzf-info") fzf_info exit 0 -fi - -if [ "${1:-}" = "--fzf-change-reload" ]; then + ;; +"--fzf-change-reload") fzf_reload_after_change exit 0 -fi - -if [ "${1:-}" = "--fzf-change" ]; then + ;; +"--fzf-change") fzf_handle_change exit 0 -fi - -if [ "${1:-}" = "--fzf-key" ]; then + ;; +"--fzf-key") fzf_handle_key "${2:-}" "${3:-}" "${4:-}" exit 0 -fi - -# Support of local music files -if [ "${1:-}" = "--decorate" ]; then + ;; +"--decorate") [ ! "${2:-}" ] && err "You did not specify a directory." && exit 1 [ ! -d "$2" ] && err "Path $2 does not point to a directory." && exit 1 if ! decorate "$2"; then @@ -89,23 +83,24 @@ if [ "${1:-}" = "--decorate" ]; then exit 1 fi exit 0 -fi - -if [ "${1:-}" = "--reload" ]; then + ;; +"--reload") [ ! "${2:-}" ] && err "Path to decorated music is missing." && exit 1 [ ! -d "$2" ] && err "Path does not point to a directory." && exit 1 info "Reloading information of local music directory $2" load_local "$2" || err "Failed to load local data" info "Done" exit 0 -fi - -if [ "${1:-}" = "--internal-preview-artist" ]; then + ;; +"--internal-preview-artist") __preview_artist "$2" exit 0 -fi - -if [ "${1:-}" = "--help" ]; then + ;; +"--playlist") + list_playlist + exit 0 + ;; +"--help") cat < Decorate directory containing a tagged release - --reload Populate da$KEYS_SWITCH_ARTIST_ALBUMase with decorated local music from + --reload Populate database with decorated local music from EOF exit 0 -fi - -if [ "${1:-}" = "--refresh-view" ]; then + ;; +"--refresh-view") precompute_view exit 0 -fi + ;; +esac # Set window title printf '\033]0;%s\007' "$WINDOW_TITLE" @@ -152,16 +147,6 @@ ARGSFILE_LAST="$statedir/state-args2" touch "$STATEFILE" "$ARGSFILE" "$STATEFILE_LAST" "$ARGSFILE_LAST" export STATEFILE ARGSFILE STATEFILE_LAST ARGSFILE_LAST -if [ "${1:-}" = "--ni-search-artist" ]; then - $0 --internal-search "artist" "$2" - exit 0 -fi - -if [ "${1:-}" = "--ni-search-album" ]; then - $0 --internal-search "releasegroup" "$2" - exit 0 -fi - # Views and modes VIEW_ARTIST="artist" VIEW_RELEASEGROUP="rg" @@ -241,6 +226,7 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \ --no-input \ --margin="2%,10%" \ --bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \ + --bind="r,ctrl-r:reload:$0 --playlist" \ --delimiter="\t" \ --with-nth="{1}" >/dev/null ;; diff --git a/src/sh/helper.sh b/src/sh/helper.sh index e1a3954..aa00e4a 100644 --- a/src/sh/helper.sh +++ b/src/sh/helper.sh @@ -2,15 +2,18 @@ ERR="\033[38;5;196m" INFO="\033[38;5;75m" DBG=$ERR OFF="\033[m" +LOGDIR="$HOME/.local/state/$APPNAME" +[ -d "$LOGDIR" ] || mkdir -p "$LOGDIR" +LOGFILE="$LOGDIR/log" err() { - echo "${ERR}ERROR:${OFF} ${1:-}" >/dev/stderr + echo "${ERR}ERROR:${OFF} ${1:-}" >>"$LOGFILE" } info() { - echo "${INFO}Info:${OFF} ${1:-}" >/dev/stderr + echo "${INFO}Info:${OFF} ${1:-}" >>"$LOGFILE" } debug() { - echo "${DBG}DEBUG${OFF} ${INFO} [$$] $(date)${OFF}: $*" >>"$APP_NAME.debug.log" + echo "${DBG}DEBUG${OFF} ${INFO} [$$] $(date)${OFF}: $*" >>"$LOGFILE" } diff --git a/src/sh/mpv.sh b/src/sh/mpv.sh index d76d53a..1bdd2fa 100644 --- a/src/sh/mpv.sh +++ b/src/sh/mpv.sh @@ -35,6 +35,7 @@ mpv_start() { mpv_play_list() { t=$(mktemp) cat >"$t" + debug "Playing $(cat "$t")" __mpv_command_with_arg "loadlist" "$t" rm -f "$t" }