Add sandbox error message for invalid commands
This commit is contained in:
parent
02abb0960c
commit
501353a534
@ -44,14 +44,11 @@ usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset git
|
unset git
|
||||||
|
|
||||||
[[ -z "$name" ]] && \
|
[[ -z "$name" ]] && \
|
||||||
error "missing argument <name>\n$usage" && return 1
|
error "missing argument <name>\n$usage" && return 1
|
||||||
|
|
||||||
local sandbox=$SANDBOX_ROOT/$name
|
local sandbox=$SANDBOX_ROOT/$name
|
||||||
[[ -d "$sandbox" ]] && \
|
[[ -d "$sandbox" ]] && \
|
||||||
error "sandbox already exists $name" && return 1
|
error "sandbox already exists $name" && return 1
|
||||||
|
|
||||||
if [[ -n "$repo" ]]; then
|
if [[ -n "$repo" ]]; then
|
||||||
mkdir -p $SANDBOX_ROOT &> /dev/null
|
mkdir -p $SANDBOX_ROOT &> /dev/null
|
||||||
git clone $repo $sandbox
|
git clone $repo $sandbox
|
||||||
@ -61,55 +58,49 @@ usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
|
|||||||
cd $sandbox
|
cd $sandbox
|
||||||
git init &> /dev/null
|
git init &> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $sandbox/.enter
|
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $sandbox/.enter
|
||||||
echo "SANDBOX_NAME=$name" >> $sandbox/.enter
|
echo "SANDBOX_NAME=$name" >> $sandbox/.enter
|
||||||
_autoenv_authorized $sandbox/.enter yes
|
_autoenv_authorized $sandbox/.enter yes
|
||||||
|
|
||||||
echo "unset SANDBOX_NAME" >> $sandbox/.exit
|
echo "unset SANDBOX_NAME" >> $sandbox/.exit
|
||||||
echo "unset SANDBOX_HOME" >> $sandbox/.exit
|
echo "unset SANDBOX_HOME" >> $sandbox/.exit
|
||||||
_autoenv_authorized $sandbox/.exit yes
|
_autoenv_authorized $sandbox/.exit yes
|
||||||
|
|
||||||
_autoenv_enter $sandbox
|
_autoenv_enter $sandbox
|
||||||
;;
|
;;
|
||||||
|
|
||||||
rename)
|
rename)
|
||||||
local old_name=$1 new_name=$2
|
local old_name=$1 new_name=$2
|
||||||
[[ -z "$old_name" ]] && \
|
[[ -z "$old_name" ]] && \
|
||||||
error "missing argument <old-name>\n$usage" && return 1
|
error "missing argument <old-name>\n$usage" && return 1
|
||||||
[[ -z "$new_name" ]] && \
|
[[ -z "$new_name" ]] && \
|
||||||
error "missing argument <new-name>\n$usage" && return 1
|
error "missing argument <new-name>\n$usage" && return 1
|
||||||
|
|
||||||
local old=$SANDBOX_ROOT/$old_name new=$SANDBOX_ROOT/$new_name
|
local old=$SANDBOX_ROOT/$old_name new=$SANDBOX_ROOT/$new_name
|
||||||
[[ ! -d "$old" ]] && \
|
[[ ! -d "$old" ]] && \
|
||||||
error "sandbox does not exist $old_name" && return 1
|
error "sandbox does not exist $old_name" && return 1
|
||||||
[[ -d "$new" ]] && \
|
[[ -d "$new" ]] && \
|
||||||
error "sandbox already exists $new_name" && return 1
|
error "sandbox already exists $new_name" && return 1
|
||||||
|
|
||||||
[[ "$PWD" = "$old"* ]] && _autoenv_exit $PWD
|
[[ "$PWD" = "$old"* ]] && _autoenv_exit $PWD
|
||||||
|
|
||||||
mv $old $new
|
mv $old $new
|
||||||
sed -i "s/$old_name/$new_name/g" $new/.enter
|
sed -i "s/$old_name/$new_name/g" $new/.enter
|
||||||
_autoenv_authorized $new/.enter yes
|
_autoenv_authorized $new/.enter yes
|
||||||
_autoenv_authorized $new/.exit yes
|
_autoenv_authorized $new/.exit yes
|
||||||
|
|
||||||
[[ "$PWD" = "$old"* ]] && cd $new
|
[[ "$PWD" = "$old"* ]] && cd $new
|
||||||
;;
|
;;
|
||||||
|
|
||||||
destroy)
|
destroy)
|
||||||
local name=$1
|
local name=$1
|
||||||
[[ -z "$name" ]] && \
|
[[ -z "$name" ]] && \
|
||||||
error "missing argument <name>\n$usage" && return 1
|
error "missing argument <name>\n$usage" && return 1
|
||||||
|
|
||||||
local sandbox=$SANDBOX_ROOT/$name
|
local sandbox=$SANDBOX_ROOT/$name
|
||||||
[[ ! -d $sandbox ]] && \
|
[[ ! -d $sandbox ]] && \
|
||||||
error "sandbox does not exist $name" && return 1
|
error "sandbox does not exist $name" && return 1
|
||||||
|
|
||||||
[[ "$PWD" = "$sandbox"* ]] && cd ~
|
[[ "$PWD" = "$sandbox"* ]] && cd ~
|
||||||
|
|
||||||
rm -rf $sandbox
|
rm -rf $sandbox
|
||||||
;;
|
;;
|
||||||
|
|
||||||
list)
|
list)
|
||||||
ls -1 $SANDBOX_ROOT | less -F -K -R -X
|
ls -1 $SANDBOX_ROOT | less -F -K -R -X
|
||||||
;;
|
;;
|
||||||
|
|
||||||
enable)
|
enable)
|
||||||
local name=$1
|
local name=$1
|
||||||
[[ -z "$name" ]] && \
|
[[ -z "$name" ]] && \
|
||||||
@ -118,16 +109,19 @@ usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
|
|||||||
local sandbox=$SANDBOX_ROOT/$name
|
local sandbox=$SANDBOX_ROOT/$name
|
||||||
[[ ! -d $sandbox ]] && \
|
[[ ! -d $sandbox ]] && \
|
||||||
error "sandbox does not exist $name" && return 1
|
error "sandbox does not exist $name" && return 1
|
||||||
|
|
||||||
export SANDBOX_RETURN=$PWD
|
export SANDBOX_RETURN=$PWD
|
||||||
cd $sandbox
|
cd $sandbox
|
||||||
;;
|
;;
|
||||||
|
|
||||||
disable)
|
disable)
|
||||||
[[ -z "$SANDBOX_RETURN" ]] && \
|
[[ -z "$SANDBOX_RETURN" ]] && \
|
||||||
error "sandbox is not currently active" && return 1
|
error "sandbox is not currently active" && return 1
|
||||||
|
|
||||||
cd $SANDBOX_RETURN
|
cd $SANDBOX_RETURN
|
||||||
unset SANDBOX_RETURN
|
unset SANDBOX_RETURN
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
error "invalid sandbox command: $cmd" && return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user