Actually add sandbox plugin
This commit is contained in:
parent
b61ebc4f7a
commit
e13e70de6b
@ -6,8 +6,7 @@
|
|||||||
- brew:
|
- brew:
|
||||||
- zsh
|
- zsh
|
||||||
- command:
|
- command:
|
||||||
-
|
- install: sudo chsh $USER -s `which zsh`
|
||||||
install: sudo chsh $USER -s `which zsh`
|
|
||||||
remove: sudo chsh $USER -s `which bash`
|
remove: sudo chsh $USER -s `which bash`
|
||||||
- symlink:
|
- symlink:
|
||||||
- {src: zlogin, dst: ~/.zlogin}
|
- {src: zlogin, dst: ~/.zlogin}
|
||||||
@ -15,9 +14,10 @@
|
|||||||
- {src: zprofile, dst: ~/.zprofile}
|
- {src: zprofile, dst: ~/.zprofile}
|
||||||
- {src: zshenv, dst: ~/.zshenv}
|
- {src: zshenv, dst: ~/.zshenv}
|
||||||
- {src: zshrc, dst: ~/.zshrc}
|
- {src: zshrc, dst: ~/.zshrc}
|
||||||
-
|
- src: prompt_fresh_setup
|
||||||
src: prompt_fresh_setup
|
|
||||||
dst: ~/.local/share/zsh/site-functions/prompt_fresh_setup
|
dst: ~/.local/share/zsh/site-functions/prompt_fresh_setup
|
||||||
|
- src: sandbox/_sandbox
|
||||||
|
dst: ~/.local/share/zsh/site-functions/_sandbox
|
||||||
- repo:
|
- repo:
|
||||||
- https://github.com/zsh-users/zsh-autosuggestions.git
|
- https://github.com/zsh-users/zsh-autosuggestions.git
|
||||||
- https://github.com/zsh-users/zsh-history-substring-search.git
|
- https://github.com/zsh-users/zsh-history-substring-search.git
|
||||||
|
49
sandbox/_sandbox
Normal file
49
sandbox/_sandbox
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#compdef sandbox
|
||||||
|
|
||||||
|
__get_sandboxes() {
|
||||||
|
/bin/ls $SANDBOX_ROOT 2> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
__sandboxes() {
|
||||||
|
local -a sandboxes
|
||||||
|
sandboxes=(${(fo)"$(__get_sandboxes)"})
|
||||||
|
_describe 'in' sandboxes
|
||||||
|
}
|
||||||
|
|
||||||
|
_sandbox_cmds() {
|
||||||
|
local commands; commands=(
|
||||||
|
'create:Create a new sandbox'
|
||||||
|
'rename:Rename an existing sandbox'
|
||||||
|
'destroy:Destroy an existing sandbox'
|
||||||
|
'list:Show all existing sandboxes'
|
||||||
|
'enable:Enable an existing sandbox'
|
||||||
|
'disable:Disable the current sandbox'
|
||||||
|
)
|
||||||
|
_describe -t commands 'sandbox command' commands "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
_sandbox() {
|
||||||
|
local context curcontext="$curcontext" state line
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
|
_arguments -C \
|
||||||
|
'1: :_sandbox_cmds' \
|
||||||
|
'*::arg:->args'
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
(args)
|
||||||
|
curcontext="${curcontext%:*:*}:sandbox-cmd-$words[1]:"
|
||||||
|
case $line[1] in
|
||||||
|
(create|list|disable)
|
||||||
|
;;
|
||||||
|
(enable|destroy)
|
||||||
|
_arguments -C '1:: :__sandboxes'
|
||||||
|
;;
|
||||||
|
(rename)
|
||||||
|
_arguments -C '1:: :__sandboxes'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_sandbox "$@"
|
103
sandbox/sandbox.plugin.zsh
Normal file
103
sandbox/sandbox.plugin.zsh
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
if [[ "" == $SANDBOX_ENV_IN_FILE ]]; then
|
||||||
|
export SANDBOX_ENV_IN_FILE=$AUTOENV_IN_FILE
|
||||||
|
fi
|
||||||
|
if [[ "" == $SANDBOX_ENV_OUT_FILE ]]; then
|
||||||
|
export SANDBOX_ENV_OUT_FILE=$AUTOENV_OUT_FILE
|
||||||
|
fi
|
||||||
|
if [[ "" == $SANDBOX_ROOT ]]; then
|
||||||
|
export SANDBOX_ROOT=$HOME/Sandbox
|
||||||
|
fi
|
||||||
|
|
||||||
|
sandbox() {
|
||||||
|
local usage="usage: sandbox {create,destroy,enable,disable} [name]"
|
||||||
|
|
||||||
|
if [[ "" == $1 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
create)
|
||||||
|
if [[ "" == $2 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local sandbox=$SANDBOX_ROOT/$2
|
||||||
|
if [[ -d $sandbox ]]; then
|
||||||
|
echo "Sandbox '$2' already exists"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p $sandbox &> /dev/null
|
||||||
|
begin=$PWD
|
||||||
|
cd $sandbox
|
||||||
|
|
||||||
|
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $SANDBOX_ENV_IN_FILE
|
||||||
|
echo "SANDBOX_NAME=$2" >> $SANDBOX_ENV_IN_FILE
|
||||||
|
|
||||||
|
echo "unset SANDBOX_NAME" >> $SANDBOX_ENV_OUT_FILE
|
||||||
|
echo "unset SANDBOX_HOME" >> $SANDBOX_ENV_OUT_FILE
|
||||||
|
|
||||||
|
git init &> /dev/null
|
||||||
|
|
||||||
|
cd $begin
|
||||||
|
cd $sandbox
|
||||||
|
;;
|
||||||
|
rename)
|
||||||
|
if [[ "" == $2 || "" == $3 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv $SANDBOX_ROOT/$2 $SANDBOX_ROOT/$3
|
||||||
|
sed -i "" "s/$2/$3/g" $SANDBOX_ROOT/$3/.env
|
||||||
|
;;
|
||||||
|
destroy)
|
||||||
|
if [[ "" == $2 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local sandbox=$SANDBOX_ROOT/$2
|
||||||
|
if [[ ! -d $sandbox ]]; then
|
||||||
|
echo "Sandbox '$2' does not exist"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd -
|
||||||
|
if [[ "${SANDBOX_ROOT##$PWD}" = "${SANDBOX_ROOT}" ]]; then
|
||||||
|
cd $HOME
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf $sandbox
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
/bin/ls -1 $SANDBOX_ROOT
|
||||||
|
;;
|
||||||
|
enable)
|
||||||
|
if [[ "" == $2 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local sandbox=$SANDBOX_ROOT/$2
|
||||||
|
if [[ ! -d $sandbox ]]; then
|
||||||
|
echo "Sandbox '$2' does not exist"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
export SANDBOX_RETURN=$PWD
|
||||||
|
cd $sandbox
|
||||||
|
;;
|
||||||
|
disable)
|
||||||
|
if [[ -z $SANDBOX_RETURN ]]; then
|
||||||
|
echo "Sandbox is not currently active"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $SANDBOX_RETURN
|
||||||
|
unset $SANDBOX_RETURN
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user