mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
2cbd76abf6
* getpulgs now asks before overwriting * Forgot a space
67 lines
1.3 KiB
Bash
Executable file
67 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# Description: Update nnn plugins
|
|
#
|
|
# Shell: POSIX compliant
|
|
# Author: Arun Prakash Jana
|
|
|
|
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 $1 $2
|
|
cp -vRf $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
|
|
}
|
|
|
|
if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
|
sucmd=sudo
|
|
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
|
sucmd=doas
|
|
else
|
|
sucmd=: # noop
|
|
fi
|
|
|
|
# backup any earlier plugins
|
|
if [ -d $PLUGIN_DIR ]; then
|
|
tar -C $CONFIG_DIR -czf $CONFIG_DIR"plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
|
|
fi
|
|
|
|
cd $CONFIG_DIR
|
|
curl -Ls -O https://github.com/jarun/nnn/archive/master.tar.gz
|
|
tar -zxf master.tar.gz
|
|
|
|
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 ../..
|
|
|
|
$sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
|
|
rm -rf nnn-master/ master.tar.gz README.md
|