|
|
@ -1,5 +1,8 @@ |
|
|
|
#!/bin/sh |
|
|
|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Vim plugin manager |
|
|
|
|
|
|
|
# Depends: git |
|
|
|
|
|
|
|
|
|
|
|
#---- |
|
|
|
#---- |
|
|
|
BASE="$XDG_CONFIG_HOME/vim/pack" |
|
|
|
BASE="$XDG_CONFIG_HOME/vim/pack" |
|
|
|
#---- |
|
|
|
#---- |
|
|
@ -10,34 +13,59 @@ OPT="$DIR/opt" |
|
|
|
|
|
|
|
|
|
|
|
help() { |
|
|
|
help() { |
|
|
|
B=$(tput bold) |
|
|
|
B=$(tput bold) |
|
|
|
|
|
|
|
U=$(tput smul) |
|
|
|
N=$(tput sgr0) |
|
|
|
N=$(tput sgr0) |
|
|
|
|
|
|
|
|
|
|
|
cat << EOF |
|
|
|
cat << EOF |
|
|
|
${B}NAME${N} |
|
|
|
${B}NAME${N} |
|
|
|
vimplugin - vim plugin manager |
|
|
|
vimplugin.sh - vim plugin manager |
|
|
|
|
|
|
|
|
|
|
|
${B}SYNOPSIS${N} |
|
|
|
${B}SYNOPSIS${N} |
|
|
|
./vimplugin.sh <command> [<arg1> <arg2>] |
|
|
|
${B}vimplugin.sh${N} [${U}OPTION${N}] [${U}COMMAND${N}] [<${U}ARG${N}>...] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${B}OPTIONS${N} |
|
|
|
|
|
|
|
${B}-h${N} Display usage message and exit. |
|
|
|
|
|
|
|
|
|
|
|
${B}COMMANDS${N} |
|
|
|
${B}COMMANDS${N} |
|
|
|
${B}init${N} |
|
|
|
${B}init${N} |
|
|
|
Creates all the required directories/files. |
|
|
|
Creates all the required directories/files. |
|
|
|
|
|
|
|
|
|
|
|
${B}install <url> ["start"/"opt"]${N} |
|
|
|
${B}install${N} ${U}URL${N} <${U}LOCATION${N}> |
|
|
|
Install a new plugin, <url> need to be a valid GitHub URL, |
|
|
|
Install a new plugin from a valid GitHub ${U}URL${N}. |
|
|
|
start/opt to install the plugin in the start/opt directory |
|
|
|
Store this plugin in <${U}LOCATION${N}> (start/opt), default to start. |
|
|
|
(default: start). |
|
|
|
|
|
|
|
|
|
|
|
${B}list${N} <${U}NUMBER${N}> |
|
|
|
|
|
|
|
Print all the installed plugins. |
|
|
|
|
|
|
|
If <${U}NUMBER${N}> is provided, print only the plugin in that position. |
|
|
|
|
|
|
|
|
|
|
|
${B}list <number>${N} |
|
|
|
|
|
|
|
Prints all the installed plugins, |
|
|
|
|
|
|
|
<number> prints just the plugin in that position. |
|
|
|
|
|
|
|
${B}remove${N} |
|
|
|
${B}remove${N} |
|
|
|
Remove plugin, script will prompt a selection menu. |
|
|
|
Remove plugin, pick from selection menu. |
|
|
|
|
|
|
|
|
|
|
|
${B}update${N} |
|
|
|
${B}update${N} |
|
|
|
Installs/updates all plugins from the config file. |
|
|
|
Install/update all plugins stored in the config file. |
|
|
|
EOF |
|
|
|
EOF |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Exit if no option is provided |
|
|
|
|
|
|
|
[ "$#" -eq 0 ] && help && exit 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SCRIPT="$(basename "$0")" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Option handling |
|
|
|
|
|
|
|
while getopts ':h?' opt; do |
|
|
|
|
|
|
|
case $opt in |
|
|
|
|
|
|
|
h) |
|
|
|
|
|
|
|
help |
|
|
|
|
|
|
|
exit 0 |
|
|
|
|
|
|
|
;; |
|
|
|
|
|
|
|
\?) |
|
|
|
|
|
|
|
echo "$SCRIPT: invalid option '$OPTARG'" |
|
|
|
|
|
|
|
echo "Try '$SCRIPT -h' for more information." |
|
|
|
|
|
|
|
exit 1 |
|
|
|
|
|
|
|
;; |
|
|
|
|
|
|
|
esac |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
init() { |
|
|
|
init() { |
|
|
|
sudo mkdir -p "$START" |
|
|
|
sudo mkdir -p "$START" |
|
|
|
sudo mkdir -p "$OPT" |
|
|
|
sudo mkdir -p "$OPT" |
|
|
@ -49,30 +77,11 @@ init() { |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
list() { |
|
|
|
|
|
|
|
if [ -z "$1" ]; then |
|
|
|
|
|
|
|
echo "Listing all installed plugins.." |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PLUGIN="$(find "$DIR" -mindepth 2 -maxdepth 2 \ |
|
|
|
|
|
|
|
| sort | awk -F '/' '{ print $(NF-1)"/"$NF }')" |
|
|
|
|
|
|
|
NUM=0 |
|
|
|
|
|
|
|
for p in $PLUGIN; do |
|
|
|
|
|
|
|
NUM=$(( NUM + 1 )) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then |
|
|
|
|
|
|
|
echo "$NUM) $p" |
|
|
|
|
|
|
|
elif [ "$NUM" = "$1" ]; then |
|
|
|
|
|
|
|
echo "$p" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
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 |
|
|
@ -110,26 +119,28 @@ install() { |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
update() { |
|
|
|
list() { |
|
|
|
echo "Updating.." |
|
|
|
if [ -z "$1" ]; then |
|
|
|
|
|
|
|
echo "Listing all installed plugins.." |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
init |
|
|
|
PLUGIN="$(find "$DIR" -mindepth 2 -maxdepth 2 \ |
|
|
|
|
|
|
|
| sort | awk -F '/' '{ print $(NF-1)"/"$NF }')" |
|
|
|
|
|
|
|
NUM=0 |
|
|
|
|
|
|
|
for p in $PLUGIN; do |
|
|
|
|
|
|
|
NUM=$((NUM + 1)) |
|
|
|
|
|
|
|
|
|
|
|
cd "$START" || exit |
|
|
|
if [ -z "$1" ]; then |
|
|
|
while read -r l; do |
|
|
|
echo "$NUM) $p" |
|
|
|
if [ "$l" = "start:" ]; then |
|
|
|
elif [ "$NUM" = "$1" ]; then |
|
|
|
cd "$START" || exit |
|
|
|
echo "$p" |
|
|
|
elif [ "$l" = "opt:" ]; then |
|
|
|
|
|
|
|
cd "$OPT" || exit |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
install "$l" "script" |
|
|
|
|
|
|
|
fi |
|
|
|
fi |
|
|
|
done < "$LIST" |
|
|
|
done |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
remove() { |
|
|
|
remove() { |
|
|
|
list |
|
|
|
list |
|
|
|
echo -n "Enter the number to remove: " |
|
|
|
printf "Enter the number to remove: " |
|
|
|
read -r OPTION |
|
|
|
read -r 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 |
|
|
@ -139,13 +150,37 @@ remove() { |
|
|
|
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" |
|
|
|
|
|
|
|
echo "Removed plugin: $TO_REMOVE" |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if type "$1" 2> /dev/null | grep -q "function"; then |
|
|
|
update() { |
|
|
|
"$@" |
|
|
|
echo "Updating.." |
|
|
|
else |
|
|
|
|
|
|
|
help |
|
|
|
init |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
cd "$START" || exit |
|
|
|
|
|
|
|
while read -r l; do |
|
|
|
|
|
|
|
if [ "$l" = "start:" ]; then |
|
|
|
|
|
|
|
cd "$START" || exit |
|
|
|
|
|
|
|
elif [ "$l" = "opt:" ]; then |
|
|
|
|
|
|
|
cd "$OPT" || exit |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
install "$l" "script" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
done < "$LIST" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Command handling |
|
|
|
|
|
|
|
shift $((OPTIND - 1)) |
|
|
|
|
|
|
|
case "$1" in |
|
|
|
|
|
|
|
init | install | list | remove | update) |
|
|
|
|
|
|
|
"$1" "$2" "$3" |
|
|
|
|
|
|
|
;; |
|
|
|
|
|
|
|
*) |
|
|
|
|
|
|
|
echo "$SCRIPT: invalid command '$1'" |
|
|
|
|
|
|
|
echo "Try '$SCRIPT -h' for more information." |
|
|
|
|
|
|
|
exit 1 |
|
|
|
|
|
|
|
;; |
|
|
|
|
|
|
|
esac |
|
|
|