2019-04-19 13:34:20 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2020-05-03 14:56:06 +00:00
|
|
|
# Description: Update nnn plugins to installed nnn version
|
2019-04-19 13:34:20 +00:00
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
2020-05-06 05:12:29 +00:00
|
|
|
# Authors: Arun Prakash Jana, KlzXS
|
2019-04-19 13:34:20 +00:00
|
|
|
|
2019-06-20 13:40:47 +00:00
|
|
|
CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/
|
|
|
|
PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
|
|
|
|
|
2020-04-20 16:49:35 +00:00
|
|
|
# is_cmd_exists () {
|
|
|
|
# which "$1" > /dev/null 2>&1
|
|
|
|
# echo $?
|
|
|
|
# }
|
2019-10-23 10:04:12 +00:00
|
|
|
|
2019-11-17 14:22:36 +00:00
|
|
|
merge () {
|
2020-04-20 16:49:35 +00:00
|
|
|
if which nvim >/dev/null 2>&1; then
|
|
|
|
nvim -d "$1" "$2"
|
|
|
|
else
|
|
|
|
vimdiff +0 "$1" "$2"
|
|
|
|
fi
|
2019-11-17 14:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prompt () {
|
2020-04-20 16:49:35 +00:00
|
|
|
printf "%s\n" "Plugin $1 already exists and is different."
|
2019-11-21 20:44:25 +00:00
|
|
|
printf "Keep (k), merge (m), overwrite (o) [default: k]? "
|
|
|
|
read -r operation
|
2019-11-17 14:22:36 +00:00
|
|
|
|
|
|
|
if [ "$operation" = "m" ]; then
|
|
|
|
op="merge"
|
|
|
|
elif [ "$operation" = "o" ]; then
|
|
|
|
op="cp -vRf"
|
|
|
|
else
|
|
|
|
op="true"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-12-08 19:04:53 +00:00
|
|
|
# if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
|
|
|
# sucmd=sudo
|
|
|
|
# elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
|
|
|
# sucmd=doas
|
|
|
|
# else
|
|
|
|
# sucmd=: # noop
|
|
|
|
# fi
|
2019-10-23 10:04:12 +00:00
|
|
|
|
2020-05-06 17:06:19 +00:00
|
|
|
if [ "$1" = "master" ] ; then
|
|
|
|
VER="master"
|
|
|
|
ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz
|
|
|
|
elif which nnn >/dev/null 2>&1; then
|
2020-05-03 14:56:06 +00:00
|
|
|
VER=$(nnn -V)
|
2020-05-06 17:06:19 +00:00
|
|
|
ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
|
2020-05-03 14:56:06 +00:00
|
|
|
else
|
|
|
|
echo "nnn is not installed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-06-05 12:22:33 +00:00
|
|
|
# backup any earlier plugins
|
2019-11-21 20:44:25 +00:00
|
|
|
if [ -d "$PLUGIN_DIR" ]; then
|
|
|
|
tar -C "$CONFIG_DIR" -czf "$CONFIG_DIR""plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
|
2019-06-05 12:22:33 +00:00
|
|
|
fi
|
|
|
|
|
2019-11-21 20:44:25 +00:00
|
|
|
mkdir -p "$PLUGIN_DIR"
|
|
|
|
cd "$CONFIG_DIR" || exit 1
|
2020-05-06 17:06:19 +00:00
|
|
|
curl -Ls "$ARCHIVE_URL" -o nnn-"$VER".tar.gz
|
|
|
|
tar -zxf nnn-"$VER".tar.gz
|
2019-11-17 14:22:36 +00:00
|
|
|
|
2020-05-03 14:56:06 +00:00
|
|
|
cd nnn-"$VER"/plugins || exit 1
|
2019-12-06 03:20:23 +00:00
|
|
|
|
2019-12-06 13:27:53 +00:00
|
|
|
# shellcheck disable=SC2044
|
|
|
|
# We do not use obnoxious names for plugins
|
2019-12-06 03:20:23 +00:00
|
|
|
for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do
|
2019-11-21 20:44:25 +00:00
|
|
|
if [ -f ../../plugins/"$f" ]; then
|
|
|
|
if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then
|
|
|
|
prompt "$f"
|
|
|
|
$op "$f" ../../plugins/
|
2019-11-17 14:22:36 +00:00
|
|
|
fi
|
|
|
|
else
|
2019-11-21 20:44:25 +00:00
|
|
|
cp -vRf "$f" ../../plugins/
|
2019-11-17 14:22:36 +00:00
|
|
|
fi
|
|
|
|
done
|
2019-11-21 20:44:25 +00:00
|
|
|
cd ../.. || exit 1
|
2019-11-17 14:22:36 +00:00
|
|
|
|
2020-05-06 17:06:19 +00:00
|
|
|
rm -rf nnn-"$VER"/ nnn-"$VER".tar.gz
|