My front end for mpg123 with learning word completion!
-Can play radio streams
-Can repeat/random play any combination of files
-Can support an internal play list
-Not all of these features are even supported by mpg123 itself, so it takes some code.
/def -i _complete_from_list = \
/let _prefix=%1%;\
/shift%;\
/let _len=$[strlen(_prefix)]%;\
/let _match=%;\
/while ({#}) \
/if (strncmp({1}, _prefix, _len) == 0) \
/let _match=%{_match} %{1}%;\
/endif%;\
/shift%;\
/done%;\
/if (_need_unique) \
/let _match=$(/unique %{_match})%;\
/endif%;\
/let _match=$[regmatch('^ *(.*?) *$', _match), {P1}]%;\
/if (_match =~ "") \
/beep 1%;\
/elseif (_match !/ "{*}") \
/beep 1%;\
/@test input(substr($$(/common_prefix %%{_len} %%{_match}), _len))%;\
/if (_match =~ _prev_match) \
/echo - %{_match}%;\
/endif%; \
/set _prev_match=%_match%; \
/else \
/@test _match := strcat(_match, _completion_suffix)%;\
/if (_match =/ "*[A-Za-z0-9_]") \
/@test _match := strcat(_match, " ")%;\
/endif%;\
/@test input(substr(_match, _len))%;\
/endif%;\
/unset _completion_suffix%;\
/unset _need_unique
/def -i complete_user_defined = \
/_complete_from_list %1 %completion_list
/def -i ~input_history_list = \
/let _input=$(/recall -i #1)%;\
/recall -i 1-$[substr(_input, 0, strchr(_input, ":")) - 1]
/def -i complete_input_history = \
/let _need_unique=1%;\
/_complete_from_list %1 $(/~input_history_list)
/def -i complete_dynamic = \
/let _need_unique=1%;\
/_complete_from_list %1 %completion_list $(/~input_history_list)
/def -i complete_filename = \
/quote -S /_complete_from_list $[filename({1})] !\
echo `/bin/ls -dq $[filename({1})]* 2>/dev/null | \
while read f; do \ test -d $$f && echo $$f/ || echo $$f; done`
/def -i complete_hostname = \
/let _need_unique=1%;\
/let _pf=$[substr({1}, strrchr({1}, "@") + 1)]%;\
/quote -S /_complete_from_list %{_pf} !\
echo `cat /etc/hosts %HOME/etc/hosts 2>/dev/null | \
sed -n '/^[^#].*[ ][ ]*\\\\(%{_pf}[^ ]*\\\\).*/s//\\\\1/p'`
/def -i complete_variable = \
/let _part=$[substr({1}, strrchr({1}, '%') + 1)]%;\
/if (strncmp(_part, '{', 1) == 0) \
/let _part=$[substr(_part, 1)]%;\
/let _completion_suffix=}%;\
/endif%;\
/_complete_from_list %_part $(/@listvar -s)
/def -i complete_macroname = \
/let _word=%1%;\
/let _i=$[strrchr({1}, '$')]%;\
/if (_i >= 0) \
/if (substr(_word, _i+1, 1) =~ '{') \
/@test ++_i%;\
/let _completion_suffix=}%;\
/endif%;\
/let _word=$[substr(_word, _i+1)]%;\
/elseif (strncmp(_word, '/', 1) == 0) \
/let _word=$[substr(_word, 1)]%;\
/endif%;\
/_complete_from_list %{_word} $(/quote -S /last `/@list -s -i - %{_word}*)
/def -i complete_worldname = \
/_complete_from_list %1 $(/@listworlds -s %{1}*)
/def -i complete_sockname = \
/_complete_from_list %1 $(/@listsockets -s %{1}*)
/def -i complete_context = \
/let _head=$[kbhead()]%;\
/let _word=%1%;\
/if (strchr(_word, "@") >= 0) \
/complete_hostname %1%;\
/elseif (strchr(_word, "%%") >= 0) \
/complete_variable %1%;\
/elseif (strchr(_word, "$$") >= 0) \
/complete_macroname %1%;\
; /elseif (_head =/ "{/*}") \
; /complete_command %1%;\
/elseif (_head =/ "{/*}") \
/complete_macroname %1%;\
/elseif (regmatch("-w(.+)$$", _head)) \
/complete_worldname %P1%;\
/elseif (_head =/ "*{/[sl]et|/setenv|/unset|/listvar|/edvar} {*}") \
/complete_variable %1%;\
/elseif (_head =/ "*{/load*|/save*|/lcd|/cd|/log} {*}") \
/complete_filename %1%;\
/elseif (_head =/ "*{/def|/edit|/edmac|/reedit|/undef|/list} {*}*") \
/complete_macroname %1%;\
; /elseif (_head =/ "{wh*|page|tel*|kill} {*}") \
; /complete_playername %1%;\
/elseif (regmatch(`/quote .*'("?)(.+)$$`, _head)) \
/let _completion_suffix=%P1%;\
/complete_filename %P2%;\
; /elseif (regmatch('/quote .*`("?)(.+)$$', _head)) \
; /let _completion_suffix=%P1%;\
; /complete_command %P2%;\
/elseif (regmatch('/quote .*`("?)(.+)$$', _head)) \
/let _completion_suffix=%P1%;\
/complete_macroname %P2%;\
/elseif (_head =/ "*{/world|/connect|/edworld} {*}") \
/complete_worldname %1%;\
/elseif (_head =/ "*{/fg} {*}") \
/complete_sockname %1%;\
/elseif (_head =/ "*{/telnet} {*}") \
/complete_hostname %1%;\
/elseif (_head =/ "*/quote *!*") \
/complete_filename %1%;\
/elseif (_head =/ "*{/@test|/expr} *") \
/complete_variable %1%;\
/elseif (_head =/ "*{*/*|.*|tiny.*}") \
/complete_filename %1%;\
/else \
/complete_dynamic %1%;\
/endif
/def -i common_prefix = \
/let _min=%1%;\
/shift%;\
/let _prefix=%1%;\
/let _len=$[strlen(_prefix)]%;\
/while /shift%; /@test {#} & _len > _min%; /do \
/let _i=%_min%;\
/while (_i < _len & strncmp(_prefix, {1}, _i+1) == 0) \
/@test ++_i%;\
/done%;\
/let _len=%_i%;\
/done%;\
/echo - $[substr(_prefix, 0, _len)]
/def -Fp0 -mglob -t'* tells you, \"Music.\"' musicbot=/if (playing =~ 'none') tell %{1} Sadly I'm not listening to anything now!

%;\
/else tell %{1} Music??? I love it! I'm currently listening to: \
$(/idmp3)%;/endif
/def sys_fg = /quote -S -decho \\!!%{*-:} >/dev/null 2>/dev/null</dev/null & :
/def startm = /stopm%;/sys_fg mpg123 /home/perlfu/mp3/%{1}%;/echo *********** Now Playing: %{1} **************%;/set playing=%{1}
/def stopm = /sys killall mpg123%;/set playing=none
/def rp = /stopm%;/sys_fg mpg123 -Z /home/perlfu/mp3/*.mp3
/def radio=/stopm%;/sys_fg cd /home/perlfu && ./rst%;/echo ******************* STARTING RADIO STREAM **************************%;/set playing=Di.Fm
/def rpm=/sys killall mpg123%;/startm %{playing}