Mercurial > ec-dotfiles
view bin/moedump @ 525:1dd96a55b7ac
Invoke nocompatible earliest so it doesn't override anything preceeded it.
author | edogawaconan <me@myconan.net> |
---|---|
date | Mon, 14 Jul 2014 01:20:57 +0900 |
parents | 5bafb912837e |
children |
line wrap: on
line source
#!/bin/sh safe_mv() { mv -- "$@"; } safe_ln() { ln -s -- "$1" "$2"; } safe_basename() { basename -- "$1"; } get_md5() { ${MD5} -- "$1" | cut -d' ' -f1; } get_filename() { safe_basename "${1%.*}"; } eod() { "$@" || errx "$@"; } errx() { echo "Error executing: $@"; exit 1; } MD5="md5sum" [ "$(safe_basename "${PWD}")" = ".all" ] || { echo "Wrong working directory. This script must be run in .all directory. Aborting."; exit 1; } [ -d "../.trash" ] || eod mkdir ../.trash echo "Total files: $(find ../* -type f | wc -l) files." num=0 for i in ../*/* do if [ -h "$i" ] then [ -f "$i" ] || { eod safe_mv "$i" "../.trash" && echo "Broken file: $(safe_basename "$i"). Moved to trash."; } else if [ "$(get_md5 "$i")" = "$(get_filename "$i")" ] then eod safe_mv "$i" . eod safe_ln "../.all/$(safe_basename "$i")" "$i" else eod safe_mv "$i" "../.trash" && echo "Broken file: $(get_filename "$i"). Moved to .trash." fi printf "%s" "." num=$((num+1)) [ "$((num%100))" -eq 0 ] && printf "${num}" fi done echo "done"