From fb4dfec3d32623de841dba97e890d127e7b4adc6 Mon Sep 17 00:00:00 2001 From: LAN-TW Date: Fri, 25 Nov 2011 00:30:53 +0800 Subject: bash_include: 加入基本的背景執行輔助函式 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bash_include | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bash_include b/bash_include index 83e57c7..2df4855 100644 --- a/bash_include +++ b/bash_include @@ -101,6 +101,35 @@ function mkscreenacl () done } +function bgrun () +{ + [ "$#" == "0" ] && return 1 + current_time=`date "+%Y%m%d-%H%M%S"` + filename="$HOME/tmp/$1-$current_time" + echo "Writing to $filename" + "$@" &> "$filename" & +} + +function bgout() +{ + if [ "$1" == "" ] + then + yourchoice=1 + fi + rootfilename=`find ~/tmp/ -maxdepth 1 -mindepth 1 | cut -d - -f 2,3 | sort -r | sed -n ${yourchoice}p` + realfilename=`find ~/tmp/ -maxdepth 1 -mindepth 1 | grep "$rootfilename"` + if [ "$PAGER" == "" ] + then + PAGER=less + fi + read -p "View '$realfilename' ? " confirm + if [ "$confirm" == "n" ] || [ "$confirm" == "N" ] + then + return 1 + fi + "$PAGER" "$realfilename" +} + # Starting doing something startcolor -- cgit