source: trunk/third/bash/examples/functions/keep @ 12959

Revision 12959, 1.0 KB checked in by tb, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12958, which included commits to RCS files with non-trunk default branches.
Line 
1# From: Seth Chaiklin <psykseth@aau.dk>
2# To: chet@ins.CWRU.Edu
3# Subject: bash functions (sorta)
4
5#
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.
10#
11
12keep()
13{
14        case $# in
15        1|2)    ;;
16        *) echo "usage: keep [alias] program" 1>&2 ; return 1;;
17        esac
18
19        # progname
20        pn=${1##*/}
21
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
28}
29
30#
31# unkeep:
32# usage: unkeep program
33# unset the alias set up by the keep function
34#
35
36unkeep()
37{
38        if [ $# != 1 ]; then
39                echo "usage: unkeep program"
40                return 2
41        fi
42
43        # unset the alias for the kept program
44        unalias "${1##*/}"
45}
46
47#
48# kept:
49# lists all kept programs in 'alias: program' form
50#
51
52kept()
53{
54        alias | grep "fg.*2>" | sed "s/alias \(.*\)='fg.*||\(.*\)'$/\1:\2/"
55}
56
57
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
Note: See TracBrowser for help on using the repository browser.