Patch-ID: bash41-003
[bash.git] / examples / functions / keep
blob4433b35318d5637c75331ea5a0204c3fd1d4c474
1 # From: Seth Chaiklin <psykseth@aau.dk>
2 # To: chet@ins.CWRU.Edu
3 # Subject: bash functions (sorta)
6 # keep:
7 # usage: keep program
8 # declare the a program should be "kept".  i.e. try to fg a stopped one
9 # and only when that fails start a fresh program.
12 keep()
14         case $# in
15         1|2)    ;;
16         *) echo "usage: keep [alias] program" 1>&2 ; return 1;;
17         esac
19         # progname
20         pn=${1##*/}
22         # set up an alias for the kept program
23         if [ $# = 1 ]; then
24                 alias "$pn=fg $1 2>/dev/null || $1"
25         else
26                 alias "$1=fg $2 2>/dev/null || $2"
27         fi
31 # unkeep:
32 # usage: unkeep program
33 # unset the alias set up by the keep function
36 unkeep()
38         if [ $# != 1 ]; then
39                 echo "usage: unkeep program"
40                 return 2
41         fi
43         # unset the alias for the kept program
44         unalias "${1##*/}"
48 # kept:
49 # lists all kept programs in 'alias: program' form
52 kept()
54         alias | grep "fg.*2>" | sed "s/alias \(.*\)='fg.*||\(.*\)'$/\1:\2/"
58 # some things that should be kept
59 #keep /usr/local/bin/emacs
60 #keep e ${EDITOR:-/usr/local/bin/emacs}
61 #keep edit ${EDITOR:-/usr/local/bin/emacs}
62 #keep /usr/local/bin/emm