Mercurial > ec-dotfiles
changeset 248:fbb03c862b63
Awesome merge.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Tue, 08 Nov 2011 11:59:49 +0700 |
parents | 53b39ca5a6ea (current diff) 3d57990fe9d1 (diff) |
children | 68b765e9cf76 |
files | bin/ren |
diffstat | 9 files changed, 545 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgtags Tue Nov 08 11:59:49 2011 +0700 @@ -0,0 +1,2 @@ +04af8306398e3a30b325f9ea799ac3b2d522a632 0.2.1 +417968e2d5a73e72df4e08ac21e06382b29335ae 0.2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Tue Nov 08 11:59:49 2011 +0700 @@ -0,0 +1,13 @@ +Copyright (c) 2010-2011, Edho Arief <edho@myconan.net> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/moefetch.sh Tue Nov 08 11:59:49 2011 +0700 @@ -0,0 +1,420 @@ +#!/bin/sh + +# Copyright (c) 2009, edogawaconan <me@myconan.net> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# Lots of bugs here. Use with care +# USE WITH CARE +# +# what it does: fetch every picture that has the specified TAGS. +# requirement: wget, libxslt, openssl + +# program additional paths for: cut, sed, wc, openssl, wget, xsltproc, grep +ADDITIONAL_PATH= + +# default server address. Danbooru only! I do not take responsibility of stupidity. +DEFAULT_SITE="moe.imouto.org" + +# base directory. make sure it's writeable. I do not take responsibility if you don't own the folder and files as no check is done for this one. +# Structure is ${BASE_DIR}/<TAGS> +# Absolute path only. +# Leave empty to use whatever folder you're running this at +BASE_DIR= + +# not user modifiable from here + +# useless welcome message. Also version +msg_welcome() { + echo "moefetch ${_version} +Copyright (c) 2009 edogawaconan <me@myconan.net> +" +} + +# Sanitize path. Totally safe. Usage: cmd "$(safe_path "${filename}")" +safe_path() +{ + # It all depends on the first character. + start=$(printf "%s" "$*" | cut -c 1) + path= + case "${start}" in + .|/) path="$*";; # . and / is safe. No change. + *) path="./$*";; # Anything else must be prefixed with ./ + esac + printf "%s" "${path}" # Return. +} + +# Checks md5. OpenSSL should be available on anything usable. +get_md5() { cat "$(safe_path "${1}")" | openssl dgst -md5 | tail -n 1 | sed -e 's/.*\([[:xdigit:]]\{32\}\).*/\1/'; } + +# Safely get basename. +get_basename() { basename "$(safe_path "${1}")"; } + +# Safely get filename (basename without the extension). +get_filename() { get_basename "${1%.*}"; } + +# Transformation for tag url. +get_cleantags() { printf "%s " "$*" | sed -e 's/\&/%26/g;s/=/%3D/g'; } + +# Returns something if not an md5 value. +is_not_md5() { get_filename "$1" | sed -e 's/\([0-9a-f]\{32\}\)//g'; } + + +# fatal error handler +Err_Fatal() { + echo " +Fatal error: ${1}" + exit 1 +} + +Err_Impossible() { + echo " +Impossible error. Or you modified content of the working directories when the script is running. +Please report to moefetch.googlecode.com if you see this message (complete with entire run log)" + exit 1 +} + +# help message +Err_Help() { + echo "moefetch.sh COMMAND [-n] [-p PASSWORD] [-s SITE_URL] [-u USERNAME] TAGS + +COMMAND: + (quick)fetch: + Do a complete update. Add prefix quick to skip file checking + check: + Get list of new files, clean up local folder and print total new files + +OPTIONS: + -n: + Skip checking repository directory. + -p PASSWORD: + Specifies password for login. + -s SITE_URL: + Specify URL of the Danbooru powered site you want to leech from. Default is ${DEFAULT_SITE}. + -u USERNAME: + Specifies username for login. + TAGS: + Tags you want to download. Separated by spaces. Tag name follows standard Danbooru tagging scheme." + exit 2 +} + +# generate link by transforming xml +Generate_Link() { + echo " +Fetching XML file" + tempnum=1000 + iternum=1 + > "${TEMP_PREFIX}-list" + while [ "${tempnum}" -ge 1000 ]; do + url="http://${SITE}/post/index.xml?tags=$(get_cleantags "${TAGS}")&offset=0&limit=1000&page=${iternum}" + [ ${_use_login} -eq 1 ] && url="${url}&login=${LOGIN_USER}&password_hash=${LOGIN_PASS}" + wget --quiet "${url}" -O "${TEMP_PREFIX}-xml" -e continue=off || Err_Fatal "Failed download catalog file" + printf "Processing XML file... " + # xslt evilry + xsltproc - "${TEMP_PREFIX}-xml" <<EOF | sed 's/.*\(http.*\)\(\/[a-f0-9]\{32\}\).*\.\([^\.]*\)/\1\2.\3/g' | grep ^http > "${TEMP_PREFIX}-templist" +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> +<xsl:output method="xml" indent="yes"/> +<xsl:template match="post"> +<xsl:value-of select="@file_url" /> +</xsl:template> +</xsl:stylesheet> +EOF + tempnum=$(grep -c . "${TEMP_PREFIX}-templist") + iternum=$((iternum + 1)) + cat "${TEMP_PREFIX}-templist" >> "${TEMP_PREFIX}-list" + echo "${tempnum} file(s) available" + done + numfiles=$(grep -c . "${TEMP_PREFIX}-list") + echo "${numfiles} file(s) available on server" + [ "${numfiles}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site." +} + + +progress_init() { + _last="-" + printf "${_last}" +} + +progress_anim() { + case "${_last}" in + /) _last="-";; + -) _last=\\;; + \\) _last=\|;; + \|) _last="/";; + esac + printf "\b${_last}" +} + +progress_done() { printf "\bdone\n"; } + +# getting rid of ls (as per suggestion) +Count_Files() { + numfiles=0 + for dircontent in "${*}/"* "${*}/".*; do + if [ "${dircontent}" != "${*}/*" ] || [ -e "${dircontent}" ]; then + numfiles=$((numfiles + 1)) + fi + done + echo $((numfiles - 2)) +} + +# check tools availability +Check_Tools() { + # verify all programs required do indeed exist + commands="cut sed wc wget xsltproc xargs rm mkdir chown comm grep date openssl" + for cmd in ${commands} + do + [ "$(command -v "${cmd}")" ] || Err_Fatal "${cmd} doesn't exist in ${PATH}" + done +} + +# verify required folders exist and writeable +Check_Folders(){ + [ -O "${BASE_DIR}" ] || Err_Fatal "You don't own ${BASE_DIR}. Please fix ${BASE_DIR} or run this script in your own directory." + for directory in temp trash deleted "${SITE_DIR}/${TARGET_DIR}"; do + if [ ! -d "${BASE_DIR}/${directory}" ]; then + mkdir -p "${BASE_DIR}/${directory}" || Err_Impossible + fi + if [ ! -O "${BASE_DIR}/${directory}" ]; then + echo "You don't own the ${BASE_DIR}/${directory}, applying globally writeable permission on it" + chmod -R u=rwX,g=rwX,o=rwX "${BASE_DIR}/${directory}" || Err_Impossible + fi + done + [ "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}")" -eq 0 ] && ISNEW=1 + for i in error ok list newlist templist; do + touch "${TEMP_PREFIX}-${i}" || Fatal_Err "Error creating ${TEMP_PREFIX}-${i}. This shouldn't happen" + done + # +} + +# Do some cleanup +Cleanup_Repository() { + # current dir: ${BASE_DIR}/${SITE_DIR}/${TARGET_DIR} + printf "Cleaning up repository folder... " + progress_init + trash_dir="${BASE_DIR}/trash/${trash_dir}/$(date -u "+${SITE_DIR}-${TARGET_DIR}-%Y%m%d-%H.%M")" + trashes="These files have been moved to ${trash_dir}:" + has_trash= + if [ ! -d "${trash_dir}" ]; then + mkdir -p "${trash_dir}" || Err_Impossible + else + if [ ! -O "${trash_dir}" ]; then + chmod -R u=rwX,g=rwX,o=rwX "${BASE_DIR}/${directory}" || Err_Impossible + fi + fi + for trash in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"* + do + is_trash= + if [ -d "${trash}" ] || [ -n "$(is_not_md5 "${trash}")" ] || [ -z "$(grep "$(get_basename "${trash}")" "${TEMP_PREFIX}-list")" ]; then + is_trash=1 + has_trash=1 + mv -f -- "${trash}" "${trash_dir}" || Err_Impossible + trashes="${trashes} + $(get_basename "${trash}")" + fi + progress_anim + done + rmdir "${trash_dir}" 2>/dev/null + progress_done + [ -n "${has_trash}" ] && echo "${trashes}" +} + +# check files correctness +Check_Files() { + if [ ! -n "${ISNEW}" ]; then + [ -z "${NOCLEAN}" ] && Cleanup_Repository + printf "Checking for errors... " + progress_init + files_error="These files do not match its md5:" + files_notdanbooru="These files are not checked:" + has_err_filename= + has_err_md5= + > "${TEMP_PREFIX}-error" + > "${TEMP_PREFIX}-ok" + for file in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"* + do + if [ "${file}" != "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/*" ]; then + if [ -n "$(is_not_md5 "${file}")" ] || [ -d "${file}" ]; then + files_notdanbooru="${files_notdanbooru} + $(get_basename "${file}")" + has_err_filename=1 + else + if [ "$(get_md5 "${file}")" = "$(get_filename "${file}")" ]; then + echo "$(get_basename "${file}")" >> "${TEMP_PREFIX}-ok" + else + rm "${file}" || Err_Fatal "Error removing ${file}" + echo "$(get_basename "${file}")" >> "${TEMP_PREFIX}-error" + files_error="${files_error} + $(get_basename "${file}")" + has_err_md5=1 + fi + fi + fi + progress_anim + done + progress_done + if [ ! -n "${has_err_md5}" ] && [ ! -n "${has_err_filename}" ]; then + echo "All files OK" + else + if [ -n "${has_err_md5}" ]; then + echo "${files_error}" + echo "$(grep -c . "${TEMP_PREFIX}-error") file(s) removed" + fi + [ -n "${has_err_filename}" ] && echo "${files_notdanbooru}" + fi + echo "$(grep -c . "${TEMP_PREFIX}-ok") file(s) available locally" + + printf "Generating list of new files... " + progress_init + cp -f "${TEMP_PREFIX}-list" "${TEMP_PREFIX}-templist" + while read -r is_ok; do + grep -v "${is_ok}" "${TEMP_PREFIX}-templist" > "${TEMP_PREFIX}-newlist" + cp -f "${TEMP_PREFIX}-newlist" "${TEMP_PREFIX}-templist" || Err_Impossible + progress_anim + done < "${TEMP_PREFIX}-ok" + progress_done + echo "$(grep -c . "${TEMP_PREFIX}-newlist") file(s) to be downloaded" + else + if [ -n "${ISQUICK}" ]; then + echo "Quick mode selected. Skipping check" + else + echo "Empty local repository" + fi + cat "${TEMP_PREFIX}-list" > "${TEMP_PREFIX}-newlist" + fi +} + +# start downloading the images +Fetch_Images() { + if [ "$(grep -c . "${TEMP_PREFIX}-newlist")" -eq 0 ]; then + echo "No new file" + else + printf "Downloading files... " + cd "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" + wget -e continue=on -i "${TEMP_PREFIX}-newlist" -o "${TEMP_PREFIX}.log" + fi +} + +# initialize base variables and initial command check +init() +{ + # path initialization + # check if additional path is specified + if [ -n "${ADDITIONAL_PATH}" ] + then + # insert the additional path + PATH="${ADDITIONAL_PATH}:${PATH}" + export PATH + fi + + # misc variables + ISQUICK= + ISNEW= + + # minimum number of arguments: 2 (command and tag). If less than two, exit and print help message + [ $# -lt 2 ] && Err_Help + case "$1" in + check|fetch|quickfetch) + echo "Starting..." + JOB="$1" + ;; + *) + Err_Help + ;; + esac + shift + SITE= + TAGS= + has_pass=0 + has_user=0 + x=1 + while getopts "s:nu:p:" opt + do + case "$opt" in + s) SITE="$OPTARG";; + n) NOCLEAN=1;; + p) + LOGIN_PASS=$(printf "%s" "$OPTARG" | openssl dgst -sha1 | sed -e 's/.*\([[:xdigit:]]\{40\}\).*/\1/') + has_pass=1 + ;; + u) + LOGIN_USER="$OPTARG" + has_user=1 + ;; + esac + x=$OPTIND + done + shift $(($x-1)) + if [ "$1" = -- ]; then shift; fi + TAGS="$@" + [ -n "${SITE}" ] || SITE=${DEFAULT_SITE} + [ -n "${TAGS}" ] || Err_Fatal "No tag specified" + # Get base folder - default, current folder or fallback to ${HOME} + [ -n "${BASE_DIR}" ] || BASE_DIR=${PWD} + [ -n "${BASE_DIR}" ] || BASE_DIR=${HOME} + [ -n "$(echo "${BASE_DIR}" | cut -c1 | grep \/)" ] || BASE_DIR="/${BASE_DIR}" + # see if both pass and use are set. If they're set, switch _use_login variable content to 1. + [ ${has_pass} -eq 1 -a ${has_user} -eq 1 ] && _use_login=1 + + echo "Tags: ${TAGS}" + # slash is not wanted for folder name + TARGET_DIR=$(echo "${TAGS}" | sed -e 's/\//_/g') + SITE_DIR=$(echo "${SITE}" | sed -e 's/\/$//g;s/\//_/g') + TEMP_PREFIX="${BASE_DIR}/temp/${SITE_DIR}-${TARGET_DIR}" +} + +# global variables goes here +init_globals() +{ + _version="1.0-rc2" # version of this script + _use_login=0 # variable to check whether a login is used or not +} + +main() +{ + # removing GNU-ism as much as possible + POSIXLY_CORRECT=1 + #initialize global variables + init_globals + #print welcome message + msg_welcome + # initialization + init "$@" + Check_Tools + Check_Folders + + + # let's do the job! + case "${JOB}" in + check) + Generate_Link + Check_Files + ;; + fetch) + Generate_Link + Check_Files + Fetch_Images + ;; + quickfetch) + ISNEW=1 + ISQUICK=1 + Generate_Link + Check_Files + Fetch_Images + ;; + esac +} + +# call the main routine! +main "$@" +
--- a/bin/ren Tue Nov 08 11:56:49 2011 +0700 +++ b/bin/ren Tue Nov 08 11:59:49 2011 +0700 @@ -16,7 +16,7 @@ $newname =~ s/\[t-n\]/[T-N]/i; #TITLE AND NAMES $newname =~ s/^(\(|\[)W B(\)|\])/[W_B]/; - if ($newname =~ m/\[Doremi/) { + if ($newname =~ m/\[(Doremi|Elysium)/) { $newname =~ s/\.([a-z0-9]+)$/,$1/i; $newname =~ s/\./ /g; $newname =~ s/,([a-z0-9]+)$/.$1/i; @@ -41,6 +41,8 @@ $newname =~ s/\] *Pocket Monsters - (\d+) - .*\[(H264 |)SUB\]/] Pokemon - $1 /i; $newname =~ s/\] Fafner - /] Soukyuu no Fafner - /; $newname =~ s/\] Mashiro iro symphony - /] Mashiro-iro Symphony - /i; + $newname =~ s/\] To Aru Kagaku no Railgun /] Toaru Kagaku no Railgun /i; + $newname =~ s/\] To Aru Majutsu no Index /] Toaru Majutsu no Index /i; $newname =~ s/\] Shakugan no Shana III /] Shakugan no Shana Final /i; $newname =~ s/\] Boku Ha Tomodachi Ga Sukunai - /] Boku wa Tomodachi ga Sukunai - /i; $newname =~ s/\] Seikon no Qwaser II BD - (\d+) \[720p\]/] Seikon no Qwaser II - $1 [720p BD]/i; @@ -57,6 +59,7 @@ $newname =~ s/\] Maji de Watashi ni Koi Shinasai!! /] Maji de Watashi ni Koi Shinasai! /i; $newname =~ s/\] Sei Juushi Bismarck /] Sei Juushi Bismark /i; $newname =~ s/\] Tamayura - hitotose - /] Tamayura ~hitotose~ - /i; + $newname =~ s/\] Yumekui Merry /] Dream Eater Merry /i; $newname =~ s/^Arigatou\.Tsubasa\.Chronicles\.(|2\.)(\d{2})(|v2)\./[Arigatou] Tsubasa Chronicles $1 - $2$3/; $newname =~ s/^Niea\.Under\.Seven\.(\d+)\.\(Dual\.Audio\)\.XVID\.\[AM\]/[AM] Niea Under Seven - $1/; $newname =~ s/ Tsubasa Chronicles 2\. - / Tsubasa Chronicles 2 /; @@ -206,7 +209,7 @@ $newname =~ s/Naruto (\d+-\d+) /Naruto - $1 /; $newname =~ s/Lupin III Series 1 - (\d+) - .+ \[neo1024\]/[neo1024] Lupin III - $1 /; $newname =~ s/Mitsudomoe Picture Drama - 0/Mitsudomoe Picture Drama - /; - $newname =~ s/^(Star Driver .*)(\[AtsA\])/$2 $1 /i; + $newname =~ s/^(Fullmetal Alchemist Brotherhood .*|Star Driver .*)(\[AtsA\])/$2 $1 /i; $newname =~ s/(Sora no Woto|Ichiban Ushiro no Daimaou|Mayoi Neko Overrun!) - ([^ ]+|OP Clean|ED Clean|Theater [a-z0-9]+) \[BD 1080p\]\[AtsA\]/[AtsA] $1 - $2 [1080p BD]/; $newname =~ s/(Sora no Woto|Ichiban Ushiro no Daimaou|Mayoi Neko Overrun!) ([^ ]+|Opening Clean|Ending Clean|Theater - [a-z0-9]+) \[1080p BD\]\[AtsA\]/[AtsA] $1 - $2 [1080p BD]/; $newname =~ s/Battle\.Programmer\.Shirase\./Battle Programmer Shirase /; @@ -262,7 +265,7 @@ $newname =~ s/ OP(\d+[a-z]*)/ - Opening $1 /i; $newname =~ s/ ED / - Ending /; $newname =~ s/ Clean (Opening|Ending) v2/ - $1 (Clean) [v2]/i; - $newname =~ s/ Creditless Opening (\d+) / - Opening $1 (Clean) /i; + $newname =~ s/ Creditless (Opening|Ending) (\d+) / - $1 $2 (Clean) /i; $newname =~ s/ Ep(\d+) Creditless Ending / - Ending $1 (Clean) /i; $newname =~ s/ (NCED|Ending Clean) / - Ending (Clean) /i; $newname =~ s/ NCED(\d+) / - Ending $1 (Clean) /i; @@ -278,7 +281,8 @@ $newname =~ s/(\(|\[) *(DVD H264 640x480|DVD H264 720x480 AAC|DVD 704x480 H264 AC3|DVD 704x480|DVDRip\.Xvid\.864x480\.Vorbis|DVD H264 848x480|DVD 720x480|DVD H264 720x480|DVD, wmv, mp3) *(\)|\])/[DVD]/i; $newname =~ s/(\(|\[) *(BD\]\[1080p-FLAC|1920x1080 Hi10p h264 AAC|BD 1920x1080 x264 AAC|BD 1080p Hi10P|BDRip 1080p x264 FLAC|BD-1080p-|BD-1080p-FLAC|1920x1038 Blu-Ray FLAC|1920x1080 Blu-Ray FLAC|1920x1080 h264 BD FLAC|1920x1080 BD|BD\.1080p\.FLAC|BD 1080p H\.264 AAC 5\.1|BD 1080p) *(\)|\])/[1080p BD]/i; $newname =~ s/(\(|\[) *(Hi10P 1280x720 H264|Hi10P 1280x720|1280x720 Hi10P|1280x720 5\.1|1280x720 x264 AAC|1280x720 H264 AAC|720p H264 AAC|1280x720|1280x720 H\.?264 AAC) *(\)|\])/[720p]/i; - $newname =~ s/(\(|\[) *(BD 1280x720 H264 AAC|BD, 720p,|BD 720p H264-AAC|BDRip 720p|BD, 720p, ,|1280x720 BD|BD 1280x720 H264 AAC|BD 720p|BD 720p FLAC|BD 1280x720 H264 AAC) *(\)|\])/[720p BD]/i; + $newname =~ s/(\(|\[) *(BDrip 720p Vorbis|BD 720p Hi10P AAC|BD, 720p,|BD 720p H264-AAC|BDRip 720p|BD, 720p, ,|1280x720 BD|BD 1280x720 H264 AAC|BD 720p|BD 720p FLAC|BD 1280x720 H264 AAC) *(\)|\])/[720p BD]/i; + $newname =~ s/(\(|\[) *(BD 540p) *(\)|\])/[BD]/i; $newname =~ s/(\(|\[) *(1024x576|H264 1024x576) *(\)|\])/[576p]/i; $newname =~ s/(\(|\[) *(1920x1080) *(\)|\])/[1080p]/i; ##SLICED BREAD pt.2 @@ -429,6 +433,8 @@ $newname =~ s/ SP0/ - Special /; $newname =~ s/ SP(\d+) / - Special $1 /; $newname =~ s/ Special - / - Special /; + $newname =~ s/ Animated Commentary - / - Animated Commentary /; + $newname =~ s/ Fullmetal Alchemist Brotherhood (- |)Skit - / Fullmetal Alchemist Brotherhood - Skit /i; $newname =~ s/ - Picture Drama - / - Picture Drama /; $newname =~ s/ (Mayoi Neko Overrun! - Theater) - / $1 /; $newname =~ s/ Opening - / Opening /; @@ -461,6 +467,7 @@ $newname =~ s/^Naruto - (\d{2}) /Naruto - 0$1 /; $newname =~ s/^Fairy Tail - (\d{2}) /Fairy Tail - 0$1 /; $newname =~ s/^Naruto - (\d{2})-(\d{2}) /Naruto - 0$1-0$2 /; + if ($^O eq "MSWin32") { $newname =~ s/ *\\ */\\/g; } print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname; if ($_ eq $newname) { print("$_: no need to rename, skipping\n");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/termcolors.sh Tue Nov 08 11:59:49 2011 +0700 @@ -0,0 +1,47 @@ +#!/bin/sh + +# Usage: +# _c [bold_|]<color> <text> +# +# <color> can be one of: +# black, blue, green, cyan, red, purple, brown, gray +# Prefix the color with bold_ to use bold style/light color. +# +# Example: +# To print word "Hello" in bold blue: +# _c bold_blue "Hello" +# +# To print text with only one word colored: +# echo "Hello, $(c green world)." +# +# To do: +# Support for background color, underline, etc. +# +# Reference: +# Colours, http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html +# + +_c() { + color_name="${1}" + shift + text="${*}" + esq="\033[" + r="${esq}0m" # r for reset + case "${color_name}" in + bold_*) color="1;";; + *) color="0;";; + esac + case "${color_name}" in + *black) color="${color}30";; + *blue) color="${color}34";; + *green) color="${color}32";; + *cyan) color="${color}36";; + *red) color="${color}31";; + *purple) color="${color}35";; + *brown) color="${color}33";; + *gray) color="${color}37";; + esac + color="${esq}${color}m" + printf "${color}%s${r}" "${text}" +} +
--- a/rc/bash Tue Nov 08 11:56:49 2011 +0700 +++ b/rc/bash Tue Nov 08 11:59:49 2011 +0700 @@ -1,5 +1,10 @@ #!/usr/bin/env bash +case "${-}" in + *i*) ;; + *) return;; +esac + if [ "${ECOS_BASH_LOADED}" != "yes" ]; then ECOS_BASH_LOADED="yes" else @@ -35,6 +40,7 @@ _has_rm_I= _has_gnu_ls= _has_gnu_grep= +_ls="ls" case "$(uname -s)" in Linux) _has_rm_I=y @@ -45,10 +51,11 @@ [ -x /usr/gnu/bin/rm ] && _has_rm_I=y [ -x /usr/gnu/bin/ls ] && _has_gnu_ls=y [ -x /usr/gnu/bin/grep ] && _has_gnu_grep=y - [ -d /usr/xpg4/bin ] && PATH="/usr/xpg4/bin:${PATH}" [ -d /opt/csw/bin ] && PATH="/opt/csw/bin:${PATH}" [ -d /opt/csw/sbin ] && PATH="/opt/csw/sbin:${PATH}" [ -d /usr/gnu/bin ] && PATH="/usr/gnu/bin:${PATH}" + [ -d /usr/sfw/bin ] && PATH="${PATH}:/usr/sfw/bin" + [ -d /usr/xpg4/bin ] && PATH="${PATH}:/usr/xpg4/bin" export PATH alias ping="ping -s" alias ping6="ping -A inet6" @@ -59,8 +66,12 @@ export LSCOLORS=ExGxFxdxCxegedabagExEx ;; OpenBSD) - if command -v colorls > /dev/null 2>&1; then + if command -v gls > /dev/null 2>&1; then + _has_gnu_ls=y + _ls="gls" + elif command -v colorls > /dev/null 2>&1; then export CLICOLOR= + export LSCOLORS=ExGxFxdxCxegedabagExEx alias ls='colorls -F' fi ;; @@ -70,17 +81,18 @@ esac [ "${_has_rm_I}" = y ] && alias rm="rm -I" -[ "${_has_gnu_ls}" = y ] && alias ls="ls -F --color=auto" +[ "${_has_gnu_ls}" = y ] && alias ls="${_ls} -F --color=auto" [ "${_has_gnu_grep}" = y ] && alias grep="grep --color=auto" unset _has_rm_I unset _has_gnu_ls unset _has_gnu_grep +unset _ls case "${TERM}" in xterm*|screen*|dtterm) - PROMPT_COMMAND='echo -ne "\033]0;${LOGNAME}@${HOSTNAME}: ${PWD}\007"' + PROMPT_COMMAND='echo -ne "\033]0;${LOGNAME}@${HOSTNAME}: ${PWD}\007";'"${PROMPT_COMMAND}" ;; esac
--- a/rc/hg Tue Nov 08 11:56:49 2011 +0700 +++ b/rc/hg Tue Nov 08 11:59:49 2011 +0700 @@ -1,5 +1,5 @@ [ui] -username = Edho Prima Arief <edho@myconan.net> +username = Edho Arief <edho@myconan.net> merge = vimdiff verbose = true @@ -14,3 +14,5 @@ [hostfingerprints] bitbucket.org = 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe +[defaults] +addremove = --similarity 100
--- a/rc/tcsh Tue Nov 08 11:56:49 2011 +0700 +++ b/rc/tcsh Tue Nov 08 11:59:49 2011 +0700 @@ -1,5 +1,23 @@ #!/usr/bin/env tcsh -[ -e "${HOME}/.ecos_tcsh.before" ] && source "${HOME}/.ecos_tcsh.before" + +# Ensures it's tcsh +if ( ! $?tcsh ) then + exit +endif + +# Ensures this script is running on terminal. Otherwise exit immediately. +if ( ! $?prompt ) then + exit +endif + +# Ensures we're not loading this script again. +if ( ! $?ecos_tcsh_loaded ) then + set ecos_tcsh_loaded="yes" +else + exit +endif + +test -f "${HOME}/.ecos_tcsh.before" && source "${HOME}/.ecos_tcsh.before" umask 22 limit coredumpsize 0 @@ -78,7 +96,7 @@ case OpenBSD: set path=(${path} /usr/local/{bin,sbin}) setenv LSCOLORS ExGxFxdxCxegedabagExEx - [ "${iscolor}" -eq 1 ] && setenv TERM xterm-256color + test "${iscolor}" -eq 1 && setenv TERM xterm-256color ( which colorls ) > /dev/null && alias ls colorls -FG breaksw case DragonFly: @@ -88,7 +106,7 @@ breaksw case SunOS: set path=(${path} /usr/{gnu,csw,xpg4}/{bin,sbin}) - [ -x /usr/gnu/bin/ls ] && alias ls /usr/gnu/bin/ls ${gnuls_opts} + test -x /usr/gnu/bin/ls && alias ls /usr/gnu/bin/ls ${gnuls_opts} breaksw case Linux: alias ls ls ${gnuls_opts} @@ -99,6 +117,6 @@ ( which vim ) > /dev/null && alias vi vim && setenv EDITOR vim -[ -e "${HOME}/.ecos_tcsh.after" ] && source "${HOME}/.ecos_tcsh.after" +test -f "${HOME}/.ecos_tcsh.after" && source "${HOME}/.ecos_tcsh.after" -[ -x "/usr/games/fortune" ] && "/usr/games/fortune" +test -x "/usr/games/fortune" && "/usr/games/fortune"
--- a/setup Tue Nov 08 11:56:49 2011 +0700 +++ b/setup Tue Nov 08 11:59:49 2011 +0700 @@ -19,7 +19,7 @@ case "$1" in uninstall|install) _rc "${1}" "tcsh" ".ecos_tcsh" - _init "${1}" '[ -r "${HOME}/.ecos_tcsh" ] && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' ".cshrc" + _init "${1}" 'test -r "${HOME}/.ecos_tcsh" && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' ".cshrc" ;; esac } @@ -44,17 +44,22 @@ } _rc() { + if test -z "${3}" || test -z "${2}" || test -z "${1}"; then + _echo "Invalid command." + return + fi _srcfile="${rcdir}/${2}" _dstfile="${HOME}/${3}" if test ! -h "${_dstfile}"; then if test -f "${_dstfile}"; then cp "${_dstfile}" "${_dstfile}.bak" + _echo "${_dstfile} backed up to ${_dstfile}.bak" elif test -d "${_dstfile}"; then cp -r "${_dstfile}" "${_dstfile}.bak" + _echo "Directory ${_dstfile} backed up to ${_dstfile}.bak" fi - _echo "${_dstfile} backed up to ${_dstfile}.bak" fi - rm -f "${_dstfile}" + rm -rf "${_dstfile}" case "${1}" in install) ln -fs "${_srcfile}" "${_dstfile}" @@ -71,7 +76,7 @@ _scripttmp="${HOME}/.tmp.${3}" _data="${2}" if [ -f "${_script}" ]; then - grep -v "${_data}" "${_script}" > "${_scripttmp}" + grep -v "`printf "%s\n" "${_data}" | sed 's/.*#//'`" "${_script}" > "${_scripttmp}" mv -f "${_scripttmp}" "${_script}" fi case "${1}" in @@ -106,3 +111,4 @@ _help ;; esac +