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 [message] Save your changes to the environment, optionally using
19 the given commit message
20 revert Revert your changes since last save
34 local DEFAULT="$1"; shift
37 1) def=0; defstr="Y/n";;
38 0) def=1; defstr="y/N";;
39 *) def=; defstr="y/n";;
41 while [ -z "$val" ]; do
44 echo -n "$* ($defstr): "
57 if [ -z "$CREATE" ]; then
58 [ -d "$ENVDIR" ] || exit 0
60 [ -x "$(which git 2>/dev/null)" ] || error "Git is not installed"
61 mkdir -p "$ENVDIR" || error "Failed to create the environment directory"
62 cd "$ENVDIR" || error "Failed to switch to the environment directory"
68 git commit -q -m "Initial import"
71 error "Failed to initialize the environment directory"
76 [ \! -L "$BASEDIR/.config" -a -f "$BASEDIR/.config" ] && mv "$BASEDIR/.config" "$ENVDIR"
84 git commit -m "${STR:-Update} at $(date)"
88 rm -f "$BASEDIR/.config"
89 ln -s env/.config "$BASEDIR/.config"
90 mkdir -p "$ENVDIR/files"
91 [ -L "$BASEDIR/files" ] || ln -s env/files "$BASEDIR/files"
101 git branch --color | grep -vE '^. master$'
107 git diff --cached --color
125 LINES="$(env_diff | wc -l)" # implies env_init
126 [ "$LINES" -gt 0 ] && {
127 if ask_bool 1 "Do you want to save your changes"; then
137 [ -L "$BASEDIR/.config" ] && rm -f "$BASEDIR/.config"
138 [ -L "$BASEDIR/files" ] && rm -f "$BASEDIR/files"
139 [ -f "$ENVDIR/.config" ] || ( cd "$ENVDIR/files" && find | grep -vE '^\.$' > /dev/null )
141 if ask_bool 1 "Do you want to keep your current config and files"; then
142 mkdir -p "$BASEDIR/files"
144 cp -a "$ENVDIR/files/"* "$BASEDIR/files" 2>/dev/null >/dev/null
146 cp "$ENVDIR/.config" "$BASEDIR/"
148 rm -rf "$BASEDIR/files" "$BASEDIR/.config"
155 local name="${1##*/}"
157 [ -z "$name" ] && usage
158 branch="$(git branch | grep '^\* ' | awk '{print $2}')"
159 [ "$name" = "$branch" ] && error "cannot delete the currently selected environment"
160 git branch -D "$name"
164 local name="${1##*/}"
165 [ -z "$name" ] && usage
169 git checkout "$name" || error "environment '$name' not found"
174 local NAME="${1##*/}"
176 git branch -m "$NAME"
184 [ -z "$NAME" ] && usage
187 branch="$(git branch | grep '^\* ' | awk '{print $2}')"
188 if [ -n "$branch" -a "$branch" != "master" ]; then
190 if ask_bool 0 "Do you want to clone the current environment?"; then
193 rm -f "$BASEDIR/.config" "$BASEDIR/files"
195 git checkout -b "$1" "$from"
196 if [ -f "$BASEDIR/.config" -o -d "$BASEDIR/files" ]; then
197 if ask_bool 1 "Do you want to start your configuration repository with the current configuration?"; then
198 [ -d "$BASEDIR/files" -a \! -L "$BASEDIR/files" ] && {
199 mkdir -p "$ENVDIR/files"
201 mv "$BASEDIR/files/"* "$ENVDIR/files/" 2>/dev/null
203 rmdir "$BASEDIR/files"
207 rm -rf "$BASEDIR/.config" "$BASEDIR/files"
217 list) env_list "$@";;
218 clear) env_clear "$@";;
219 switch) env_switch "$@";;
220 delete) env_delete "$@";;
221 rename) env_rename "$@";;
222 diff) env_diff "$@";;
223 save) env_save "$@";;
224 revert) env_revert "$@";;