Optimize vimplugin script
This commit is contained in:
+26
-21
@@ -1,9 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
DIR="/etc/vim/pack/plugins"
|
||||
#----
|
||||
BASE="/etc/vim/pack"
|
||||
#----
|
||||
DIR="$BASE/plugins"
|
||||
LIST="$BASE/list"
|
||||
START="$DIR/start"
|
||||
OPT="$DIR/opt"
|
||||
LIST="/etc/vim/pack/list"
|
||||
|
||||
help() {
|
||||
BOLD=$(tput bold)
|
||||
@@ -16,9 +19,8 @@ help() {
|
||||
echo " ./vimplugin.sh <command> [<arg1> <arg2>]"
|
||||
echo ""
|
||||
echo "${BOLD}COMMANDS${NORMAL}"
|
||||
echo " list <number>"
|
||||
echo " Prints all the installed plugins, <number> prints \
|
||||
just the plugin in that position."
|
||||
echo " init"
|
||||
echo " Creates all the required directories/files."
|
||||
echo ""
|
||||
echo " install <url> [\"start\"/\"opt\"]"
|
||||
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 \
|
||||
(default: start)."
|
||||
echo ""
|
||||
echo " list <number>"
|
||||
echo " Prints all the installed plugins, <number> prints \
|
||||
just the plugin in that position."
|
||||
echo " remove"
|
||||
echo " Remove plugin, script will prompt a selection menu."
|
||||
echo " update"
|
||||
echo " Installs/updates all plugins from the config file."
|
||||
echo ""
|
||||
echo " remove"
|
||||
echo " Remove plugin, script will prompt a selection menu."
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -62,13 +78,11 @@ install() {
|
||||
if [ -z "$2" ]; then
|
||||
# Default is directory 'start'
|
||||
cd "$START"
|
||||
elif [ "$2" != script ]; then
|
||||
if [ "$2" = "start" ]; then
|
||||
elif [ "$2" = "start" ]; then
|
||||
cd "$START"
|
||||
elif [ "$2" = "opt" ]; then
|
||||
cd "$OPT"
|
||||
fi
|
||||
fi
|
||||
|
||||
REPO="$(basename $1 .git)"
|
||||
if [ -d "$REPO" ]; then
|
||||
@@ -83,15 +97,13 @@ install() {
|
||||
if [ -z "$2" ]; then
|
||||
# Append before 'opt:'
|
||||
sudo sed -i '/opt:/ i '$1 $LIST
|
||||
elif [ "$2" != "script" ]; then
|
||||
if [ "$2" = "start" ]; then
|
||||
elif [ "$2" = "start" ]; then
|
||||
# Append before 'opt:'
|
||||
sudo sed -i '/opt:/ i '$1 $LIST
|
||||
elif [ "$2" = "opt" ]; then
|
||||
# Append at the end of the file
|
||||
sudo sed -i '$ a '$1 $LIST
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Installed: $REPO"
|
||||
fi
|
||||
@@ -101,14 +113,7 @@ install() {
|
||||
update() {
|
||||
echo "Updating.."
|
||||
|
||||
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
|
||||
init
|
||||
|
||||
cd $START
|
||||
while read l; do
|
||||
|
||||
Reference in New Issue
Block a user