From fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da Mon Sep 17 00:00:00 2001 From: LAN-TW Date: Tue, 6 Dec 2011 22:44:37 +0800 Subject: =?UTF-8?q?bash=5Finclude:=20=E5=8A=A0=E5=85=A5=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=E5=9B=9E=E6=94=B6=E7=AD=92=E5=8A=9F=E8=83=BD=E3=80=81?= =?UTF-8?q?sudo=20=E6=94=AF=E6=8F=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bash_include | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/bash_include b/bash_include index d315069..7b02fea 100644 --- a/bash_include +++ b/bash_include @@ -149,7 +149,7 @@ function bgrun () [ "$#" = "0" ] && return 1 [ '!' -d "$bgrunfiledir" ] && mkdir -p "$bgrunfiledir" local current_time=`date "+%Y%m%d-%H%M%S"` - local cmdname=`echo "$1" | sed -e 's/-/_/g' -e 's/\\//_/g' -e 's/ //g'` + local cmdname=`echo "$1" | sed -e 's/-/_/g' -e 's/\\//_/g' -e 's/ /_/g'` if [ "`echo "$cmdname" | cut -c 1`" == "_" ] then cmdname=`echo "$cmdname" | cut -c 2-` @@ -249,6 +249,11 @@ function bgclean () done } +function bgdu () +{ + du -a "$bgrunfiledir" +} + ########## Background End ########## function check_dmesg () @@ -291,12 +296,61 @@ function prehistory_backup () ########## Trash Manager ########## +alias trash_put=trash_mv + +function split_arguments () +{ + local argcount=$# + local -i i=0 + local prefix_start=0 + while [ "$1" ] + do + if [ "$prefix_start" == "0" ] + then + if [ "$1" = "--" ] + then + prefix_start=1 + i=0 + shift + continue + else + arglist[$i]="$1" + fi + else + prefixlist[$i]="$1" + fi + i=$i+1 + shift + done + i=0 + +} + function trash_mv () { [ "$#" = "0" ] && return 1 [ '!' -d "$trashdir" ] && mkdir -p "$trashdir" - local current_time=`date "+%Y%m%d-%H%M%S"` - + local original_path + local current_time + local -i i=0 + split_arguments "$@" + while [ "${arglist[$i]}" ] + do + original_path="`realpath "${arglist[$i]}"`" + current_time=`date "+%Y%m%d-%H%M%S"` + better_time=`date "+%Y-%m-%d %H:%M:%S"` + dirname="`basename "${arglist[$i]}" | sed -e 's/-/_/g' -e 's/ /_/g'`" + fulldirname="$trashdir/$current_time-$dirname" + mkdir -p "$fulldirname" + echo "Move: ${arglist[$i]} -> $fulldirname" + "${prefixlist[@]}" mv "${arglist[$i]}" "$fulldirname" + echo "$better_time" > "$fulldirname/information.date" + echo "$original_path" > "$fulldirname/information.path" + i=$i+1 + shift + done + unset arglist + unset prefixlist } function trash_rm () @@ -316,7 +370,7 @@ function trash_view () function trash_du () { - echo ee + du -d 1 "$trashdir" } ########## Trash Manager End ########## @@ -328,6 +382,19 @@ function help_function () echo uu } +function help_myself () +{ + echo "argc = $#" + echo "argv[0] = $0" + i=1 + while [ "$1" ] + do + echo "argv[$i] = $1" + i=$(($i+1)) + shift + done +} + ########## Help End ########## # Doing something -- cgit v1.2.3