sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

getplugs (1630B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Update nnn plugins to installed nnn version
      4 #
      5 # Shell: POSIX compliant
      6 # Authors: Arun Prakash Jana, KlzXS
      7 
      8 CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/
      9 PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
     10 
     11 merge () {
     12 	if type nvim >/dev/null 2>&1; then
     13 		nvim -d "$1" "$2"
     14 	else
     15 		vimdiff +0 "$1" "$2"
     16 	fi
     17 }
     18 
     19 prompt () {
     20 	printf "%s\n" "Plugin $1 already exists and is different."
     21 	printf "Keep (k), merge (m), overwrite (o) [default: k]? "
     22 	read -r operation
     23 
     24 	if [ "$operation" = "m" ]; then
     25 		op="merge"
     26 	elif [ "$operation" = "o" ]; then
     27 		op="cp -vRf"
     28 	else
     29 		op="true"
     30 	fi
     31 }
     32 
     33 if [ "$1" = "master" ] ; then
     34     VER="master"
     35     ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz
     36 elif type nnn >/dev/null 2>&1; then
     37     VER=$(nnn -V)
     38     ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
     39 else
     40     echo "nnn is not installed"
     41     exit 1
     42 fi
     43 
     44 # backup any earlier plugins
     45 if [ -d "$PLUGIN_DIR" ]; then
     46     tar -C "$CONFIG_DIR" -czf "$CONFIG_DIR""plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
     47 fi
     48 
     49 mkdir -p "$PLUGIN_DIR"
     50 cd "$CONFIG_DIR" || exit 1
     51 curl -Ls "$ARCHIVE_URL" -o nnn-"$VER".tar.gz
     52 tar -zxf nnn-"$VER".tar.gz
     53 
     54 cd nnn-"$VER"/plugins || exit 1
     55 
     56 # shellcheck disable=SC2044
     57 # We do not use obnoxious names for plugins
     58 for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do
     59 	if [ -f ../../plugins/"$f" ]; then
     60 		if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then
     61 			prompt "$f"
     62 			$op "$f" ../../plugins/
     63 		fi
     64 	else
     65 		cp -vRf "$f" ../../plugins/
     66 	fi
     67 done
     68 cd ../.. || exit 1
     69 
     70 rm -rf nnn-"$VER"/ nnn-"$VER".tar.gz