Browse Source

Optimize vimplugin script

master
Riyyi 7 years ago
parent
commit
75fe28991f
  1. 67
      .scripts/vimplugin.sh

67
.scripts/vimplugin.sh

@ -1,9 +1,12 @@
#!/bin/sh #!/bin/sh
DIR="/etc/vim/pack/plugins" #----
BASE="/etc/vim/pack"
#----
DIR="$BASE/plugins"
LIST="$BASE/list"
START="$DIR/start" START="$DIR/start"
OPT="$DIR/opt" OPT="$DIR/opt"
LIST="/etc/vim/pack/list"
help() { help() {
BOLD=$(tput bold) BOLD=$(tput bold)
@ -16,9 +19,8 @@ help() {
echo " ./vimplugin.sh <command> [<arg1> <arg2>]" echo " ./vimplugin.sh <command> [<arg1> <arg2>]"
echo "" echo ""
echo "${BOLD}COMMANDS${NORMAL}" echo "${BOLD}COMMANDS${NORMAL}"
echo " list <number>" echo " init"
echo " Prints all the installed plugins, <number> prints \ echo " Creates all the required directories/files."
just the plugin in that position."
echo "" echo ""
echo " install <url> [\"start\"/\"opt\"]" echo " install <url> [\"start\"/\"opt\"]"
echo " Install a new plugin, <url> need to be a valid \ echo " Install a new plugin, <url> need to be a valid \
@ -26,11 +28,25 @@ GitHub URL,
start/opt to install the plugin in the start/opt directory \ start/opt to install the plugin in the start/opt directory \
(default: start)." (default: start)."
echo "" echo ""
echo " update" echo " list <number>"
echo " Installs/updates all plugins from the config file." echo " Prints all the installed plugins, <number> prints \
echo "" just the plugin in that position."
echo " remove" echo " remove"
echo " Remove plugin, script will prompt a selection menu." echo " Remove plugin, script will prompt a selection menu."
echo " update"
echo " Installs/updates all plugins from the config file."
echo ""
}
init() {
sudo mkdir -p $START
sudo mkdir -p $OPT
sudo touch $LIST
if [ ! -s $LIST ]; then
# Append to empty file
sudo sh -c 'echo "start:" >> '$LIST
sudo sh -c 'echo "opt:" >> '$LIST
fi
} }
list() { list() {
@ -62,12 +78,10 @@ install() {
if [ -z "$2" ]; then if [ -z "$2" ]; then
# Default is directory 'start' # Default is directory 'start'
cd "$START" cd "$START"
elif [ "$2" != script ]; then elif [ "$2" = "start" ]; then
if [ "$2" = "start" ]; then cd "$START"
cd "$START" elif [ "$2" = "opt" ]; then
elif [ "$2" = "opt" ]; then cd "$OPT"
cd "$OPT"
fi
fi fi
REPO="$(basename $1 .git)" REPO="$(basename $1 .git)"
@ -83,14 +97,12 @@ install() {
if [ -z "$2" ]; then if [ -z "$2" ]; then
# Append before 'opt:' # Append before 'opt:'
sudo sed -i '/opt:/ i '$1 $LIST sudo sed -i '/opt:/ i '$1 $LIST
elif [ "$2" != "script" ]; then elif [ "$2" = "start" ]; then
if [ "$2" = "start" ]; then # Append before 'opt:'
# Append before 'opt:' sudo sed -i '/opt:/ i '$1 $LIST
sudo sed -i '/opt:/ i '$1 $LIST elif [ "$2" = "opt" ]; then
elif [ "$2" = "opt" ]; then # Append at the end of the file
# Append at the end of the file sudo sed -i '$ a '$1 $LIST
sudo sed -i '$ a '$1 $LIST
fi
fi fi
echo "Installed: $REPO" echo "Installed: $REPO"
@ -101,15 +113,8 @@ install() {
update() { update() {
echo "Updating.." echo "Updating.."
sudo mkdir -p $START init
sudo mkdir -p $OPT
sudo touch $LIST
if [ ! -s $LIST ]; then
# Append to empty file
sudo sh -c 'echo "start:" >> '$LIST
sudo sh -c 'echo "opt:" >> '$LIST
fi
cd $START cd $START
while read l; do while read l; do
if [ "$l" = "start:" ]; then if [ "$l" = "start:" ]; then

Loading…
Cancel
Save