2019-04-19 13:34:20 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Update nnn plugins
|
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
|
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
|
|
|
|
|
2019-10-23 10:04:12 +00:00
|
|
|
is_cmd_exists () {
|
|
|
|
which "$1" > /dev/null 2>&1
|
|
|
|
echo $?
|
|
|
|
}
|
|
|
|
|
2019-11-17 14:22:36 +00:00
|
|
|
merge () {
|
|
|
|
vimdiff $1 $2
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt () {
|
|
|
|
echo "Plugin $1 already exists and is different."
|
|
|
|
echo -n "Keep (k), merge (m), overwrite (o) [default: k]? "
|
|
|
|
read operation
|
|
|
|
|
|
|
|
if [ "$operation" = "m" ]; then
|
|
|
|
op="merge"
|
|
|
|
elif [ "$operation" = "o" ]; then
|
|
|
|
op="cp -vRf"
|
|
|
|
else
|
|
|
|
op="true"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-11-01 15:58:32 +00:00
|
|
|
if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
2019-10-23 10:04:12 +00:00
|
|
|
sucmd=sudo
|
2019-11-01 15:58:32 +00:00
|
|
|
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
2019-10-23 10:04:12 +00:00
|
|
|
sucmd=doas
|
|
|
|
else
|
|
|
|
sucmd=: # noop
|
|
|
|
fi
|
|
|
|
|
2019-06-05 12:22:33 +00:00
|
|
|
# backup any earlier plugins
|
2019-06-20 13:40:47 +00:00
|
|
|
if [ -d $PLUGIN_DIR ]; then
|
2019-10-23 10:04:12 +00:00
|
|
|
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-10-23 10:04:12 +00:00
|
|
|
cd $CONFIG_DIR
|
2019-09-27 15:31:55 +00:00
|
|
|
curl -Ls -O https://github.com/jarun/nnn/archive/master.tar.gz
|
2019-10-23 10:04:12 +00:00
|
|
|
tar -zxf master.tar.gz
|
2019-11-17 14:22:36 +00:00
|
|
|
|
|
|
|
cd nnn-master/plugins
|
|
|
|
for f in *; do
|
|
|
|
if [ -f ../../plugins/$f ]; then
|
|
|
|
if [ "$(diff --brief $f ../../plugins/$f)" ]; then
|
|
|
|
prompt $f
|
|
|
|
$op $f ../../plugins/
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
cp -vRf $f ../../plugins/
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
cd ../..
|
|
|
|
|
2019-10-23 10:04:12 +00:00
|
|
|
$sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
|
2019-11-17 15:32:43 +00:00
|
|
|
rm -rf nnn-master/ master.tar.gz $PLUGIN_DIR/README.md
|