7 Usage: $0 [options] <command> [arguments]
10 list List environments
11 clear Delete all environment and revert to flat config/files
12 new <name> Create a new environment
13 switch <name> Switch to a different environment
14 delete <name> Delete an environment
15 rename <newname> Rename the current environment
16 diff Show differences between current state and environment
17 save Save your changes to the environment
18 revert Revert your changes since last save
32 local DEFAULT
="$1"; shift
35 1) def
=0; defstr
="Y/n";;
36 0) def
=1; defstr
="y/N";;
37 *) def
=; defstr
="y/n";;
39 while [ -z "$val" ]; do
42 echo -n "$* ($defstr): "
55 if [ -z "$CREATE" ]; then
56 [ -d "$ENVDIR" ] ||
exit 0
58 [ -x "$(which git 2>/dev/null)" ] || error
"Git is not installed"
59 mkdir
-p "$ENVDIR" || error
"Failed to create the environment directory"
60 cd "$ENVDIR" || error
"Failed to switch to the environment directory"
66 git commit
-q -m "Initial import"
69 error
"Failed to initialize the environment directory"
74 [ \
! -L "$BASEDIR/.config" -a -f "$BASEDIR/.config" ] && mv "$BASEDIR/.config" "$ENVDIR"
82 git commit
-m "${STR:-Update} at $(date)"
86 rm -f "$BASEDIR/.config"
87 ln -s env
/.config
"$BASEDIR/.config"
88 mkdir
-p "$ENVDIR/files"
89 [ -L "$BASEDIR/files" ] ||
ln -s env
/files
"$BASEDIR/files"
99 git branch
--color |
grep -vE '^. master$'
105 git
diff --cached --color
123 LINES
="$(env_diff | wc -l)" # implies env_init
124 [ "$LINES" -gt 0 ] && {
125 if ask_bool
1 "Do you want to save your changes"; then
135 [ -L "$BASEDIR/.config" ] && rm -f "$BASEDIR/.config"
136 [ -L "$BASEDIR/files" ] && rm -f "$BASEDIR/files"
137 [ -f "$ENVDIR/.config" ] ||
( cd "$ENVDIR/files" && find |
grep -vE '^\.$' > /dev
/null
)
139 if ask_bool
1 "Do you want to keep your current config and files"; then
140 mkdir
-p "$BASEDIR/files"
142 cp -a "$ENVDIR/files/"* "$BASEDIR/files" 2>/dev
/null
>/dev
/null
144 cp "$ENVDIR/.config" "$BASEDIR/"
146 rm -rf "$BASEDIR/files" "$BASEDIR/.config"
153 local name
="${1##*/}"
155 [ -z "$name" ] && usage
156 branch
="$(git branch | grep '^\* ' | awk '{print $2}')"
157 [ "$name" = "$branch" ] && error
"cannot delete the currently selected environment"
158 git branch
-D "$name"
162 local name
="${1##*/}"
163 [ -z "$name" ] && usage
167 git checkout
"$name" || error
"environment '$name' not found"
172 local NAME
="${1##*/}"
174 git branch
-m "$NAME"
182 [ -z "$NAME" ] && usage
185 branch
="$(git branch | grep '^\* ' | awk '{print $2}')"
186 if [ -n "$branch" -a "$branch" != "master" ]; then
188 if ask_bool
0 "Do you want to clone the current environment?"; then
191 rm -f "$BASEDIR/.config" "$BASEDIR/files"
193 git checkout
-b "$1" "$from"
194 if [ -f "$BASEDIR/.config" -o -d "$BASEDIR/files" ]; then
195 if ask_bool
1 "Do you want to start your configuration repository with the current configuration?"; then
196 [ -d "$BASEDIR/files" -a \
! -L "$BASEDIR/files" ] && {
197 mkdir
-p "$ENVDIR/files"
199 mv "$BASEDIR/files/"* "$ENVDIR/files/" 2>/dev
/null
201 rmdir "$BASEDIR/files"
205 rm -rf "$BASEDIR/.config" "$BASEDIR/files"
215 list
) env_list
"$@";;
216 clear) env_clear
"$@";;
217 switch
) env_switch
"$@";;
218 delete
) env_delete
"$@";;
219 rename
) env_rename
"$@";;
220 diff) env_diff
"$@";;
221 save
) env_save
"$@";;
222 revert
) env_revert
"$@";;
This page took 0.052402 seconds and 5 git commands to generate.