nnn/plugins/getplugs

70 lines
1.5 KiB
Text
Raw Normal View History

2019-04-19 19:04:20 +05:30
#!/usr/bin/env sh
# Description: Update nnn plugins
#
# Shell: POSIX compliant
2019-11-17 21:56:05 +05:30
# Author: 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
is_cmd_exists () {
which "$1" > /dev/null 2>&1
echo $?
}
merge () {
vimdiff +0 "$1" "$2"
}
prompt () {
2019-11-22 02:14:25 +05:30
printf "%s" "Plugin $1 already exists and is different.\n"
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
}
2019-11-01 17:58:32 +02:00
if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
sucmd=sudo
2019-11-01 17:58:32 +02:00
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
sucmd=doas
else
sucmd=: # noop
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
2019-09-27 21:01:55 +05:30
curl -Ls -O https://github.com/jarun/nnn/archive/master.tar.gz
tar -zxf master.tar.gz
2019-11-22 02:14:25 +05:30
cd nnn-master/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
$sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
2019-12-06 08:50:23 +05:30
rm -rf nnn-master/ master.tar.gz