dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

commit db842788210e95168d41ab8b49011f29c2ee3c6c
parent bb84cc7c9830075bb0040a45ae3aa133e330f6cd
Author: Chris Noxz <chris@noxz.tech>
Date:   Sun, 29 Mar 2020 18:48:46 +0200

[bin] fix dmenu_main workflow

Diffstat:
Mbin/.local/bin/dmenu_bookmarks | 2++
Mbin/.local/bin/dmenu_main | 104+++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Mbin/.local/bin/dmenu_passmenu | 2+-
Mbin/.local/bin/dmenu_power | 2++
Mbin/.local/bin/dmenu_radio | 13+++++++++++--
Mbin/.local/bin/dmenu_sscw | 8+++-----
Mbin/.local/bin/dmenu_todo | 4+---
Mbin/.local/bin/dmenu_yt_search | 3++-
Mbin/.local/bin/operations | 2++
9 files changed, 88 insertions(+), 52 deletions(-)

diff --git a/bin/.local/bin/dmenu_bookmarks b/bin/.local/bin/dmenu_bookmarks @@ -20,6 +20,8 @@ done < "$filename" # get url based on choice choice=$(printf "$options" | sort | dmenu_vtc${args}) +[ "$choice" = "" ] && exit 1 + choice=$(printf "$data" | grep "$choice") choice="${choice##*\ }" diff --git a/bin/.local/bin/dmenu_main b/bin/.local/bin/dmenu_main @@ -1,19 +1,6 @@ #!/bin/sh -args=" -p main: -l 20" -options=" - bookmarks - radio - man - operations - pass - power - soundcloud - todo - youtube -" - -get_fm_key () { +get_fm_key() { local key_location="/tmp/.di.fm.key" local key_pass="di.fm/listen-key" [ ! -f "$key_location" ] \ @@ -23,29 +10,66 @@ get_fm_key () { echo $(cat "$key_location") } -while :; do - case "$(printf "$options" \ - | sed -e '/^$/d' -e 's/^[ \t]*//' \ - | sort \ - | dmenu_vtc${args})" in - bookmarks) - dmenu_bookmarks "$XDG_DATA_HOME/bookmarks" ${args} -i -p bookmark:;; - radio) - dmenu_radio "$(get_fm_key)" ${args} -i -p provider:;; - man) - dmenu_man${args} -i -p man:;; - operations) - operations dmenu${args} -i -p operations:;; - pass) - dmenu_passmenu ${args} -i -p pass:;; - power) - dmenu_power${args} -i;; - soundcloud) - dmenu_sscw${args} -i;; - todo) - dmenu_todo "$XDG_DATA_HOME/todo" ${args} -i -p todo:;; - youtube) - dmenu_yt_search${args} -i;; - *) break;; - esac -done +main_menu() { + local args=" -p main: -l 20" + local options=" + bookmarks + radio + man + operations + pass + power + soundcloud + todo + youtube + " + while :; do + case "$(printf "$options" \ + | sed -e '/^$/d' -e 's/^[ \t]*//' \ + | sort \ + | dmenu_vtc${args})" in + bookmarks) + dmenu_bookmarks \ + "$XDG_DATA_HOME/bookmarks" \ + ${args} -i -p bookmark: \ + && break;; + radio) + dmenu_radio \ + "$(get_fm_key)" \ + ${args} -i -p provider: \ + && break;; + man) + dmenu_man \ + ${args} -i -p man: \ + && break;; + operations) + operations dmenu \ + ${args} -i -p operations: \ + && break;; + pass) + dmenu_passmenu \ + ${args} -i -p pass: \ + && break;; + power) + dmenu_power \ + ${args} -i \ + && break;; + soundcloud) + dmenu_sscw \ + ${args} -i \ + && break;; + todo) + dmenu_todo \ + "$XDG_DATA_HOME/todo" \ + ${args} -i -p todo: \ + && break;; + youtube) + dmenu_yt_search \ + ${args} -i \ + && break;; + *) break;; + esac + done +} + +main_menu diff --git a/bin/.local/bin/dmenu_passmenu b/bin/.local/bin/dmenu_passmenu @@ -13,7 +13,7 @@ password_files="$( )" password=$(echo "$password_files" | dmenu_vtc ${args}) -[ "$password" = "" ] && return +[ "$password" = "" ] && exit 1 if [ $typeit -eq 0 ]; then pass show -c "$password" 2>/dev/null diff --git a/bin/.local/bin/dmenu_power b/bin/.local/bin/dmenu_power @@ -23,4 +23,6 @@ shutdown) sudo runit-init 0;; reboot) sudo runit-init 6;; +"") + exit 1;; esac diff --git a/bin/.local/bin/dmenu_radio b/bin/.local/bin/dmenu_radio @@ -7,16 +7,25 @@ key="$1"; shift options="" args=" $@" quality="premium_high" # premium_low, premium_medium, premium, premium_high +providers=" + di.fm + radiotunes.com + rockradio.com + jazzradio.com +" [ "$key" = "" ] && exit 1 # choose provider provider="$( \ - printf "di.fm\nradiotunes.com\nrockradio.com\njazzradio.com" \ + printf "$providers" \ + | sed -e '/^$/d' -e 's/^[ \t]*//' \ | sort \ | dmenu_vtc${args} \ )" +[ "$provider" = "" ] && exit 1 + # download list of available channels data="$( \ curl -s "http://listen.$provider/$quality/" \ @@ -46,4 +55,4 @@ curl -s "$choice" | sed "s/\(File[0-9].*$\)/\1?$key/g" > "$tmp" mpvc load "$tmp" # remove playlist after 60 seconds -sleep 60 && rm "$tmp" +(sleep 60 && rm "$tmp") & diff --git a/bin/.local/bin/dmenu_sscw b/bin/.local/bin/dmenu_sscw @@ -7,9 +7,9 @@ options="" term="" term="$(echo -n | dmenu_vtc${args} -l 0)" -[ "$term" = "" ] && exit 0 +[ "$term" = "" ] && exit 1 options="$(printf "$term" | sscw-search -s)" -[ "$options" = "" ] && exit 0 +[ "$options" = "" ] && exit 1 titles="$(echo "$options" | \ cut -d "$(printf '\t')" -f 1,2 --output-delimiter=" - " | \ awk '{ print FNR " " $0 }')" @@ -18,8 +18,6 @@ urls="$(echo "$options" | \ awk '{ print FNR " " $0 }')" title="$(printf "$titles" | dmenu_vtc${args} -l 20 -p "soundcloud > $term:")" # get -p from input and append "\b > $term:" -[ "$title" = "" ] && exit 0 +[ "$title" = "" ] && exit 1 url="$(printf "$urls" | grep "^${title%% *} ")" dmenu_url_open "${url#* }" "${title#* }" - -exit 0 diff --git a/bin/.local/bin/dmenu_todo b/bin/.local/bin/dmenu_todo @@ -14,9 +14,7 @@ while true; do # get choice choice="$(printf "$options" | dmenu_vtc${args})" - - # check if choice was made - [ ! -n "$choice" ] && exit + [ "$choice" = "" ] && exit 1 # get existing record existing="$(printf "$options" | grep "^${choice}$")" diff --git a/bin/.local/bin/dmenu_yt_search b/bin/.local/bin/dmenu_yt_search @@ -5,6 +5,7 @@ search_phrase="$(echo -n | dmenu_vtc${args} \ | sed 's/\ /+/g' \ | hexdump -v -e '/1 "%02x"' \ | sed 's/\(..\)/%\1/g')" +[ "$search_phrase" = "" ] && exit 1 search_results="$(curl 2>/dev/null \ "https://www.youtube.com/results?search_query=$search_phrase" \ @@ -52,7 +53,7 @@ done choice="$(echo $options | sed '/^\s*$/d' | sort | dmenu_vtc${args})" -[ "$choice" = "" ] && exit 0 +[ "$choice" = "" ] && exit 1 choice="$(printf "$data" | grep ^${choice%% *})" dmenu_url_open "https://www.youtube.com/watch?v=${choice#* }" diff --git a/bin/.local/bin/operations b/bin/.local/bin/operations @@ -49,6 +49,8 @@ dmenu|"") option="$(operations list | dmenu_vtc${@#dmenu})" if [ "$option" != "" ]; then operations "$option" "${@#dmenu}" + else + exit 1 fi ;; *)