|
ru.linux- RU.LINUX --------------------------------------------------------------------- From : Mike Novikoff 2:5020/1665.73 17 Oct 2007 13:13:13 To : All Subject : ~/.bashrc_mp3 -------------------------------------------------------------------------------- # # This is formerly the fragment of the main 'lo:~mn/.bashrc', # now split into the separate file for easier maintenance. # # The most often directly used functions are mp3() and mp3s(). # mp3 - plays its cmdline args || all files in current dir. # mp3s - wraps it into the `screen` session. # ############################################################## mp3 stuff #### # #alias mp3s='screen "mpg123 *.mp3"' #alias mp3s='screen mpg123 *.mp3' # 09.09.2006 # mp3s () { # 07.03.2007 # For filenames with spaces (and certain other escaped chars, e.g. [']): # 1) output the cmdline using ANOTHER field separator (other than space) # 2) restore the escaping backslashes (that were lost during expansion) # where they are needed, i.e. before spaces and those "other chars" # 3) change "another separator" back to the normal space (NOT escaped!) local ARGS=$( (IFS="|"; echo "$*") \ |sed "s/\([ '()#]\)/\\\\\1/g" |sed "s/|/ /g" ) ####screen bash -c "mp3 $ARGS" screen -ln bash -c "mp3 $ARGS" # 21.12.2006 # ^^^ # do NOT write "logins" to utmp/wtmp (wtmp becomes cluttered very quickly) } # ############################################################################# mp3list () { # 07.03.2007 echo # # Beware of the spaces in dirnames! `basename $(pwd)` would fail! # #echo \"$(pwd)\" |xargs basename \ # # Instead of the rather costly above (subshell, pipeline, forks), # get it more simply: $PWD is a bash internal var [bashref.info], # and use the parameter substitution for substring removal on it # ${var##Pattern} (remove the longest part of $Pattern from $var) # [xref: "Advanced Bash-Scripting" by M.Cooper] -- mn, 01.12.2006 # echo ${PWD##*/} \ \ |sed "s/^#\?[0-9]\{1,3\}[[:space:]_-]\+//" \ |sed "s/^\(\(19\|20\)[0-9][0-9]\)[[:space:]_-]*/\1 - /" \ |sed "s/_/ /g" \ |sed "s/^/\t/" echo /bin/ls -1U --indicator-style=none "$@" \ |sed "s/\.\(mp\|MP\)3$//g" \ |sed "s/^#\?\([0-9]*[[:space:]_.-]\+\)\{1,2\}//g" \ |sed "s/_/ /g" \ |nl -s") " echo } ############################################################################# mp3recode () { # 29.11.2006 # # SIGINT [^C] will be received ONLY by mpg123 (as usual) # trap "" SIGINT \ && mpg123 "$@" 2>&1 \ |while read; do # Suppress egrep's own output, but use its exit code echo "$REPLY" \ |egrep '^(Title|Album|Comment) *:' > /dev/null \ && echo "$REPLY" |recode 1251/ \ || echo "$REPLY" \ |egrep -v '^Junk at the beginning [0-9]+$' done } ############################################################################# mp3 () { # 29.11.2006 # ( # SUBSHELL to make sure that the _global_ $IFS is NOT affected # (Also implies that $ARGS is local, thus no "local ARGS" here) # Set IFS to something that will hardly ever appear in filenames IFS="|" # IFS="?" if [ "$*" ]; then ARGS="$*" # If any filenames are given, use them else # or try '*.mp3' (lowercase) || '*.MP3' # (`ls` is used for testing, because `test` would not accept wildcards) # if /bin/ls *.mp3 >/dev/null 2>&1; then ARGS="*.mp3"; else if /bin/ls *.MP3 >/dev/null 2>&1; then ARGS="*.MP3"; else echo -n "Neither '*.mp3' nor '*.MP3' found, and " echo "no filenames given on the command line!"; return 1 fi fi fi [ "$#" != "1" ] && mp3list $ARGS # don't if JUST ONE from cmdline mp3recode $ARGS ) } ############################################################################# # Redefine 'screen()' from /etc/profile.d/screen.sh (screen-3.9.8-3mdk), # correcting the eggog: "$@" must be in quotes! Still, define $SCREENDIR # here (screen.sh was executed on login, the function was *defined*, but # wasn't yet *run*, thus the variable is not set). -- mn@lo, 03.09.2006 # screen () { SCREENDIR=$HOME/tmp /usr/bin/screen "$@"; } * Originally in MINDO.LOCAL * Crossposted in RU.LINUX --- * Origin: Linux 2.4.35-mn i686 (2:5020/1665.73) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.linux/46504715d9cf.html, оценка из 5, голосов 10
|