diff options
author | cvpcs <root@cvpcs.org> | 2010-06-02 11:02:31 -0500 |
---|---|---|
committer | cvpcs <root@cvpcs.org> | 2010-06-02 11:02:31 -0500 |
commit | 772f20abb0a3a0979c440114bf3a1cff5b3cef03 (patch) | |
tree | 3384b9291d73a12542c526a8557218c7435491b0 /examples/functions/keep | |
download | external_bash-772f20abb0a3a0979c440114bf3a1cff5b3cef03.zip external_bash-772f20abb0a3a0979c440114bf3a1cff5b3cef03.tar.gz external_bash-772f20abb0a3a0979c440114bf3a1cff5b3cef03.tar.bz2 |
initial import of bash 4.1
Diffstat (limited to 'examples/functions/keep')
-rw-r--r-- | examples/functions/keep | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/examples/functions/keep b/examples/functions/keep new file mode 100644 index 0000000..4433b35 --- /dev/null +++ b/examples/functions/keep @@ -0,0 +1,62 @@ +# From: Seth Chaiklin <psykseth@aau.dk> +# To: chet@ins.CWRU.Edu +# Subject: bash functions (sorta) + +# +# keep: +# usage: keep program +# declare the a program should be "kept". i.e. try to fg a stopped one +# and only when that fails start a fresh program. +# + +keep() +{ + case $# in + 1|2) ;; + *) echo "usage: keep [alias] program" 1>&2 ; return 1;; + esac + + # progname + pn=${1##*/} + + # set up an alias for the kept program + if [ $# = 1 ]; then + alias "$pn=fg $1 2>/dev/null || $1" + else + alias "$1=fg $2 2>/dev/null || $2" + fi +} + +# +# unkeep: +# usage: unkeep program +# unset the alias set up by the keep function +# + +unkeep() +{ + if [ $# != 1 ]; then + echo "usage: unkeep program" + return 2 + fi + + # unset the alias for the kept program + unalias "${1##*/}" +} + +# +# kept: +# lists all kept programs in 'alias: program' form +# + +kept() +{ + alias | grep "fg.*2>" | sed "s/alias \(.*\)='fg.*||\(.*\)'$/\1:\2/" +} + + +# some things that should be kept +#keep /usr/local/bin/emacs +#keep e ${EDITOR:-/usr/local/bin/emacs} +#keep edit ${EDITOR:-/usr/local/bin/emacs} +#keep /usr/local/bin/emm |