1
0
Fork 0
mirror of https://github.com/jarun/nnn.git synced 2025-02-18 23:34:37 +00:00
nnn/plugins/getplugs

71 lines
1.6 KiB
Text
Raw Normal View History

2019-04-19 19:04:20 +05:30
#!/usr/bin/env sh
2020-05-03 20:26:06 +05:30
# Description: Update nnn plugins to installed nnn version
2019-04-19 19:04:20 +05:30
#
# Shell: POSIX compliant
2020-05-06 10:42:29 +05:30
# Authors: Arun Prakash Jana, KlzXS
2019-04-19 19:04:20 +05:30
2019-06-20 19:10:47 +05:30
CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/
PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
merge () {
if type nvim >/dev/null 2>&1; then
nvim -d "$1" "$2"
else
vimdiff +0 "$1" "$2"
fi
}
prompt () {
printf "%s\n" "Plugin $1 already exists and is different."
2019-11-22 02:14:25 +05:30
printf "Keep (k), merge (m), overwrite (o) [default: k]? "
read -r operation
if [ "$operation" = "m" ]; then
op="merge"
elif [ "$operation" = "o" ]; then
op="cp -vRf"
else
op="true"
fi
}
if [ "$1" = "master" ] ; then
VER="master"
ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz
elif type nnn >/dev/null 2>&1; then
2020-05-03 20:26:06 +05:30
VER=$(nnn -V)
ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
2020-05-03 20:26:06 +05:30
else
echo "nnn is not installed"
exit 1
fi
2019-06-05 17:52:33 +05:30
# backup any earlier plugins
2019-11-22 02:14:25 +05:30
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 17:52:33 +05:30
fi
2019-11-22 02:14:25 +05:30
mkdir -p "$PLUGIN_DIR"
cd "$CONFIG_DIR" || exit 1
curl -Ls "$ARCHIVE_URL" -o nnn-"$VER".tar.gz
tar -zxf nnn-"$VER".tar.gz
2020-05-03 20:26:06 +05:30
cd nnn-"$VER"/plugins || exit 1
2019-12-06 08:50:23 +05:30
2019-12-06 18:57:53 +05:30
# shellcheck disable=SC2044
# We do not use obnoxious names for plugins
2019-12-06 08:50:23 +05:30
for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do
2019-11-22 02:14:25 +05:30
if [ -f ../../plugins/"$f" ]; then
if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then
prompt "$f"
$op "$f" ../../plugins/
fi
else
2019-11-22 02:14:25 +05:30
cp -vRf "$f" ../../plugins/
fi
done
2019-11-22 02:14:25 +05:30
cd ../.. || exit 1
rm -rf nnn-"$VER"/ nnn-"$VER".tar.gz