/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to dev/dev

  • Committer: Tim Marston
  • Date: 2016-12-13 21:40:34 UTC
  • Revision ID: tim@ed.am-20161213214034-nd5t7ztnlrjd627i
fix add command and generic filename expansion/resolution to expend to
homedir-relative filename and absolute filename based on original filename, as
specified, rather than a fully, symlink-resolved filename.  So, e.g., if ~/bob
was a symlink to ~/fred, then ~/bob/a would resolve to the relative filename
bob/a, becuase it is inside the homedir (it would resolve to fred/a otherwise)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
2
 
 
3
# fix up home dir
 
4
if [ ! -d ~/.stdhome -a ! -d ~/.stdhome.dev -a ! -d ~/.stdhome.orig ]; then
 
5
        mkdir ~/.stdhome
 
6
fi
 
7
if [ ! -d ~/.stdhome ]; then
 
8
        echo "ERROR: can't determine current state: no ~/.stdhome"
 
9
        exit 1
 
10
fi
 
11
 
 
12
# current state
3
13
CURRENT=
4
14
if [ -d ~/.stdhome.orig -a ! -d ~/.stdhome.dev ]; then
5
15
        CURRENT=on
6
 
elif [ ! -d ~/.stdhome.orig -a -d ~/.stdhome.dev ]; then
 
16
elif [ ! -d ~/.stdhome.orig ]; then
7
17
        CURRENT=off
8
18
fi
9
 
 
10
19
if [ -z "$CURRENT" ]; then
11
 
        echo "Can't determine current state" >&2
 
20
        echo "ERROR: can't determine current state" >&2
12
21
        exit 1
13
22
fi
14
23
 
 
24
# target
15
25
TARGET=
16
26
if [ "$1" == "on" ]; then
17
27
        TARGET=on
21
31
 
22
32
if [ "$TARGET" == "on" ]; then
23
33
 
 
34
        # already on?
24
35
        if [ "$CURRENT" == "on" ]; then
25
36
                echo already on >& 2
26
37
                exit 0
27
38
        fi
28
39
        echo turning on
29
40
 
 
41
        # create/check rc
 
42
        if [ ! -f ~/.stdhomerc ]; then
 
43
                echo "ERROR: no ~/.stdhomerc, creating..."
 
44
                echo "[stdhome]" >> ~/.stdhomerc
 
45
                echo "#home-dir = ~/tmp/stdhome-dev" >> ~/.stdhomerc
 
46
                mkdir -p ~/tmp/stdhome-dev
 
47
        fi
 
48
        if ! grep -q '^#home-dir \?= \?~/tmp/stdhome-dev' ~/.stdhomerc; then
 
49
                echo "ERROR: no commented home-dir in ~/.stdhomerc"
 
50
                echo "Please add the following to the [stdhome] section:"
 
51
                echo "#home-dir = ~/tmp/stdhome-dev"
 
52
                exit 1
 
53
        fi
 
54
 
 
55
        # turn on
30
56
        mv ~/.stdhome{,.orig}
31
 
        mv ~/.stdhome{.dev,}
32
 
        sed -ie 's/^#\(home-dir\)/\1/' ~/.stdhomerc
 
57
        if [ -d ~/.stdhome.dev ]; then
 
58
                mv ~/.stdhome{.dev,}
 
59
        else
 
60
                mkdir ~/.stdhome
 
61
                echo new dev environment, use stdhome init
 
62
        fi
 
63
        sed -ie 's/^#\(home-dir\)/\1/' ~/.stdhomerc
 
64
        mkdir -p ~/tmp/stdhome-dev
 
65
        DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
 
66
        ln -s "$DIR"/src/stdhome ~/bin/stdhome
33
67
 
34
68
elif [ "$TARGET" == "off" ]; then
35
69
 
 
70
        # already off?
36
71
        if [ "$CURRENT" == "off" ]; then
37
72
                echo already off >& 2
38
73
                exit 0
39
74
        fi
40
75
        echo turning off
41
76
 
 
77
        # check rc
 
78
        if ! grep -q '^home-dir \?= \?~/tmp/stdhome-dev' ~/.stdhomerc; then
 
79
                echo "ERROR: no uncommented home-dir in ~/.stdhomerc"
 
80
                exit 1
 
81
        fi
 
82
 
 
83
        # turn off
42
84
        mv ~/.stdhome{,.dev}
43
85
        mv ~/.stdhome{.orig,}
44
86
        sed -ie 's/^home-dir/#\0/' ~/.stdhomerc
 
87
        rm -f ~/bin/stdhome
45
88
 
46
89
else
47
90
        echo currently $CURRENT