|
|
@ -1,7 +1,7 @@ |
|
|
|
#!/bin/sh |
|
|
|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
#---- |
|
|
|
#---- |
|
|
|
BASE="/etc/vim/pack" |
|
|
|
BASE="/usr/share/vim/vimfiles/pack" |
|
|
|
#---- |
|
|
|
#---- |
|
|
|
DIR="$BASE/plugins" |
|
|
|
DIR="$BASE/plugins" |
|
|
|
LIST="$BASE/list" |
|
|
|
LIST="$BASE/list" |
|
|
@ -9,143 +9,143 @@ START="$DIR/start" |
|
|
|
OPT="$DIR/opt" |
|
|
|
OPT="$DIR/opt" |
|
|
|
|
|
|
|
|
|
|
|
help() { |
|
|
|
help() { |
|
|
|
BOLD=$(tput bold) |
|
|
|
BOLD=$(tput bold) |
|
|
|
NORMAL=$(tput sgr0) |
|
|
|
NORMAL=$(tput sgr0) |
|
|
|
|
|
|
|
|
|
|
|
echo "${BOLD}NAME${NORMAL}" |
|
|
|
echo "${BOLD}NAME${NORMAL}" |
|
|
|
echo " vimplugin - vim plugin manager" |
|
|
|
echo " vimplugin - vim plugin manager" |
|
|
|
echo "" |
|
|
|
echo "" |
|
|
|
echo "${BOLD}SYNOPSIS${NORMAL}" |
|
|
|
echo "${BOLD}SYNOPSIS${NORMAL}" |
|
|
|
echo " ./vimplugin.sh <command> [<arg1> <arg2>]" |
|
|
|
echo " ./vimplugin.sh <command> [<arg1> <arg2>]" |
|
|
|
echo "" |
|
|
|
echo "" |
|
|
|
echo "${BOLD}COMMANDS${NORMAL}" |
|
|
|
echo "${BOLD}COMMANDS${NORMAL}" |
|
|
|
echo " init" |
|
|
|
echo " init" |
|
|
|
echo " Creates all the required directories/files." |
|
|
|
echo " Creates all the required directories/files." |
|
|
|
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 \ |
|
|
|
GitHub URL, |
|
|
|
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 " list <number>" |
|
|
|
echo " list <number>" |
|
|
|
echo " Prints all the installed plugins, <number> prints \ |
|
|
|
echo " Prints all the installed plugins, <number> prints \ |
|
|
|
just the plugin in that position." |
|
|
|
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 " update" |
|
|
|
echo " Installs/updates all plugins from the config file." |
|
|
|
echo " Installs/updates all plugins from the config file." |
|
|
|
echo "" |
|
|
|
echo "" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init() { |
|
|
|
init() { |
|
|
|
sudo mkdir -p $START |
|
|
|
sudo mkdir -p $START |
|
|
|
sudo mkdir -p $OPT |
|
|
|
sudo mkdir -p $OPT |
|
|
|
sudo touch $LIST |
|
|
|
sudo touch $LIST |
|
|
|
if [ ! -s $LIST ]; then |
|
|
|
if [ ! -s $LIST ]; then |
|
|
|
# Append to empty file |
|
|
|
# Append to empty file |
|
|
|
sudo sh -c 'echo "start:" >> '$LIST |
|
|
|
sudo sh -c 'echo "start:" >> '$LIST |
|
|
|
sudo sh -c 'echo "opt:" >> '$LIST |
|
|
|
sudo sh -c 'echo "opt:" >> '$LIST |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
list() { |
|
|
|
list() { |
|
|
|
if [ -z "$1" ]; then |
|
|
|
if [ -z "$1" ]; then |
|
|
|
echo "Listing all installed plugins.." |
|
|
|
echo "Listing all installed plugins.." |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
PLUGIN="$(find $DIR -mindepth 2 -maxdepth 2 \ |
|
|
|
PLUGIN="$(find $DIR -mindepth 2 -maxdepth 2 \ |
|
|
|
| sort | awk -F '/' '{ print $(NF-1)"/"$NF }')" |
|
|
|
| sort | awk -F '/' '{ print $(NF-1)"/"$NF }')" |
|
|
|
NUM=0 |
|
|
|
NUM=0 |
|
|
|
for p in $PLUGIN; do |
|
|
|
for p in $PLUGIN; do |
|
|
|
NUM=$(( NUM + 1 )) |
|
|
|
NUM=$(( NUM + 1 )) |
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then |
|
|
|
if [ -z "$1" ]; then |
|
|
|
echo "$NUM) $p" |
|
|
|
echo "$NUM) $p" |
|
|
|
elif [ "$NUM" = "$1" ]; then |
|
|
|
elif [ "$NUM" = "$1" ]; then |
|
|
|
echo "$p" |
|
|
|
echo "$p" |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
done |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
install() { |
|
|
|
install() { |
|
|
|
# Check if correct git URL |
|
|
|
# Check if correct git URL |
|
|
|
if [ -z "$(echo $1 | sed -nr \ |
|
|
|
if [ -z "$(echo $1 | sed -nr \ |
|
|
|
's/^https:\/\/github\.com\/(.*\/.*).git$/\1/p')" ]; then |
|
|
|
's/^https:\/\/github\.com\/(.*\/.*).git$/\1/p')" ]; then |
|
|
|
echo "script: url invalid: $1" |
|
|
|
echo "script: url invalid: $1" |
|
|
|
else |
|
|
|
else |
|
|
|
# cd to correct directory if called from the CLI |
|
|
|
# cd to correct directory if called from the CLI |
|
|
|
if [ -z "$2" ]; then |
|
|
|
if [ -z "$2" ]; then |
|
|
|
# Default is directory 'start' |
|
|
|
# Default is directory 'start' |
|
|
|
cd "$START" |
|
|
|
cd "$START" |
|
|
|
elif [ "$2" = "start" ]; then |
|
|
|
elif [ "$2" = "start" ]; then |
|
|
|
cd "$START" |
|
|
|
cd "$START" |
|
|
|
elif [ "$2" = "opt" ]; then |
|
|
|
elif [ "$2" = "opt" ]; then |
|
|
|
cd "$OPT" |
|
|
|
cd "$OPT" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
REPO="$(basename $1 .git)" |
|
|
|
REPO="$(basename $1 .git)" |
|
|
|
if [ -d "$REPO" ]; then |
|
|
|
if [ -d "$REPO" ]; then |
|
|
|
cd "$REPO" |
|
|
|
cd "$REPO" |
|
|
|
sudo git pull --force 1> /dev/null |
|
|
|
sudo git pull --force 1> /dev/null |
|
|
|
cd ".." |
|
|
|
cd ".." |
|
|
|
echo "Updated: $REPO" |
|
|
|
echo "Updated: $REPO" |
|
|
|
else |
|
|
|
else |
|
|
|
sudo git clone "$1" 2> /dev/null |
|
|
|
sudo git clone "$1" 2> /dev/null |
|
|
|
|
|
|
|
|
|
|
|
# Add git URL to config file |
|
|
|
# Add git URL to config file |
|
|
|
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" = "start" ]; then |
|
|
|
elif [ "$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 |
|
|
|
|
|
|
|
|
|
|
|
echo "Installed: $REPO" |
|
|
|
echo "Installed: $REPO" |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
update() { |
|
|
|
update() { |
|
|
|
echo "Updating.." |
|
|
|
echo "Updating.." |
|
|
|
|
|
|
|
|
|
|
|
init |
|
|
|
init |
|
|
|
|
|
|
|
|
|
|
|
cd $START |
|
|
|
cd $START |
|
|
|
while read l; do |
|
|
|
while read l; do |
|
|
|
if [ "$l" = "start:" ]; then |
|
|
|
if [ "$l" = "start:" ]; then |
|
|
|
cd "$START" |
|
|
|
cd "$START" |
|
|
|
elif [ "$l" = "opt:" ]; then |
|
|
|
elif [ "$l" = "opt:" ]; then |
|
|
|
cd "$OPT" |
|
|
|
cd "$OPT" |
|
|
|
else |
|
|
|
else |
|
|
|
install $l "script" |
|
|
|
install $l "script" |
|
|
|
fi |
|
|
|
fi |
|
|
|
done < $LIST |
|
|
|
done < $LIST |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
remove() { |
|
|
|
remove() { |
|
|
|
list |
|
|
|
list |
|
|
|
echo -n "Enter the number to remove: " |
|
|
|
echo -n "Enter the number to remove: " |
|
|
|
read OPTION |
|
|
|
read OPTION |
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$(echo $OPTION | sed -nr 's/^([0-9]+)$/\1/p')" ]; then |
|
|
|
if [ -z "$(echo $OPTION | sed -nr 's/^([0-9]+)$/\1/p')" ]; then |
|
|
|
echo "Please select a number" |
|
|
|
echo "Please select a number" |
|
|
|
else |
|
|
|
else |
|
|
|
TO_REMOVE="$(list $OPTION)" |
|
|
|
TO_REMOVE="$(list $OPTION)" |
|
|
|
if [ -n "$TO_REMOVE" ]; then |
|
|
|
if [ -n "$TO_REMOVE" ]; then |
|
|
|
sudo rm -rf $DIR/$TO_REMOVE |
|
|
|
sudo rm -rf $DIR/$TO_REMOVE |
|
|
|
sudo sed -i '/'"$(basename $TO_REMOVE)"'\.git/d' $LIST |
|
|
|
sudo sed -i '/'"$(basename $TO_REMOVE)"'\.git/d' $LIST |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if type "$1" 2> /dev/null | grep -q "function"; then |
|
|
|
if type "$1" 2> /dev/null | grep -q "function"; then |
|
|
|
"$@" |
|
|
|
"$@" |
|
|
|
else |
|
|
|
else |
|
|
|
echo "script: command not found: $1" |
|
|
|
echo "script: command not found: $1" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|