mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
d549ae7486
* Add nvim as a diff tool for getplugs plugin * Comment out `is_cmd_exists()` * Add nvim diff tool for diffs plugin * Add $EDITOR to nuke plugin for editing/reading text file format * Modify diff command to fix CircleCI failures * Fix getplugs prompt * Allow nuke to use custom $PAGER
73 lines
1.5 KiB
Bash
Executable file
73 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# Description: Update nnn plugins
|
|
#
|
|
# Shell: POSIX compliant
|
|
# Author: Arun Prakash Jana, KlzXS
|
|
|
|
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 () {
|
|
if which 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."
|
|
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 [ "$(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
|
|
|
|
mkdir -p "$PLUGIN_DIR"
|
|
cd "$CONFIG_DIR" || exit 1
|
|
curl -Ls -O https://github.com/jarun/nnn/archive/master.tar.gz
|
|
tar -zxf master.tar.gz
|
|
|
|
cd nnn-master/plugins || exit 1
|
|
|
|
# shellcheck disable=SC2044
|
|
# We do not use obnoxious names for plugins
|
|
for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); 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 ../.. || exit 1
|
|
|
|
rm -rf nnn-master/ master.tar.gz
|