diff options
author | LAN-TW <lantw44@gmail.com> | 2011-12-06 22:44:37 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2011-12-06 22:44:37 +0800 |
commit | fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da (patch) | |
tree | 4b937b34fd832403afb054fc816c72f0c1ce2a48 | |
parent | c874ba435abffd67c3ae0c6f78fa9d7e37fe47e0 (diff) | |
download | configfile-fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da.tar configfile-fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da.tar.gz configfile-fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da.tar.bz2 configfile-fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da.tar.lz configfile-fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da.tar.xz configfile-fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da.tar.zst configfile-fc261d4e96dcd005ecfdb5f03d3e14f6bde8e5da.zip |
bash_include: 加入基本的回收筒功能、sudo 支援bash_include-20111206
-rw-r--r-- | bash_include | 75 |
1 files 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 |