8 Usage: $0 [options] <command> [arguments]
11 list List environments
12 clear Delete all environment and revert to flat config/files
13 new <name> Create a new environment
14 switch <name> Switch to a different environment
15 delete <name> Delete an environment
16 rename <newname> Rename the current environment
17 diff Show differences between current state and environment
18 save Save your changes to the environment
19 revert Revert your changes since last save
33 local DEFAULT="$1"; shift
36 1) def=0; defstr="Y/n";;
37 0) def=1; defstr="y/N";;
38 *) def=; defstr="y/n";;
40 while [ -z "$val" ]; do
43 echo -n "$* ($defstr): "
56 if [ -z "$CREATE" ]; then
57 [ -d "$ENVDIR" ] || exit 0
59 [ -x "$(which git 2>/dev/null)" ] || error "Git is not installed"
60 mkdir -p "$ENVDIR" || error "Failed to create the environment directory"
61 cd "$ENVDIR" || error "Failed to switch to the environment directory"
67 git commit -q -m "Initial import"
70 error "Failed to initialize the environment directory"
75 [ \! -L "$BASEDIR/.config" -a -f "$BASEDIR/.config" ] && mv "$BASEDIR/.config" "$ENVDIR"
83 git commit -m "${STR:-Update} at $(date)"
87 rm -f "$BASEDIR/.config"
88 ln -s env/.config "$BASEDIR/.config"
89 mkdir -p "$ENVDIR/files"
90 [ -L "$BASEDIR/files" ] || ln -s env/files "$BASEDIR/files"
100 git branch --color | grep -vE '^. master$'
106 git diff --cached --color
124 LINES="$(env_diff | wc -l)" # implies env_init
125 [ "$LINES" -gt 0 ] && {
126 if ask_bool 1 "Do you want to save your changes"; then
136 [ -L "$BASEDIR/.config" ] && rm -f "$BASEDIR/.config"
137 [ -L "$BASEDIR/files" ] && rm -f "$BASEDIR/files"
138 [ -f "$ENVDIR/.config" ] || ( cd "$ENVDIR/files" && find | grep -vE '^\.$' > /dev/null )
140 if ask_bool 1 "Do you want to keep your current config and files"; then
141 mkdir -p "$BASEDIR/files"
143 cp -a "$ENVDIR/files/"* "$BASEDIR/files" 2>/dev/null >/dev/null
145 cp "$ENVDIR/.config" "$BASEDIR/"
147 rm -rf "$BASEDIR/files" "$BASEDIR/.config"
154 local name="${1##*/}"
156 [ -z "$name" ] && usage
157 branch="$(git branch | grep '^\* ' | awk '{print $2}')"
158 [ "$name" = "$branch" ] && error "cannot delete the currently selected environment"
159 git branch -D "$name"
163 local name="${1##*/}"
164 [ -z "$name" ] && usage
168 git checkout "$name" || error "environment '$name' not found"
173 local NAME="${1##*/}"
175 git branch -m "$NAME"
183 [ -z "$NAME" ] && usage
186 branch="$(git branch | grep '^\* ' | awk '{print $2}')"
187 if [ -n "$branch" -a "$branch" != "master" ]; then
189 if ask_bool 0 "Do you want to clone the current environment?"; then
192 rm -f "$BASEDIR/.config" "$BASEDIR/files"
194 git checkout -b "$1" "$from"
195 if [ -f "$BASEDIR/.config" -o -d "$BASEDIR/files" ]; then
196 if ask_bool 1 "Do you want to start your configuration repository with the current configuration?"; then
197 [ -d "$BASEDIR/files" -a \! -L "$BASEDIR/files" ] && {
198 mkdir -p "$ENVDIR/files"
200 mv "$BASEDIR/files/"* "$ENVDIR/files/" 2>/dev/null
202 rmdir "$BASEDIR/files"
206 rm -rf "$BASEDIR/.config" "$BASEDIR/files"
216 list) env_list "$@";;
217 clear) env_clear "$@";;
218 switch) env_switch "$@";;
219 delete) env_delete "$@";;
220 rename) env_rename "$@";;
221 diff) env_diff "$@";;
222 save) env_save "$@";;
223 revert) env_revert "$@";;