How to simplify packer's use? #134
Replies: 4 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
I recently happened on a cool way to use packer's I think the plugin might benefit from some specific intro/common use case examples for setting up plugins that could be show cased and explained in a wiki or in collapsible sections in the I know that currently there is a block there of some potential ways to use packer but I wonder if that doesn't go into enough detail/explain enough the use cases for things. I think something like the following section but for a few different use cases/ this could also be added to the help docs Conditional plugin installation exampleIf you want a plugin installed on one machine but not another you can specify this using packer's use {"my-windows-plugin", disable = os.getenv('IS_WINDOWS') } |
Beta Was this translation helpful? Give feedback.
-
#!/usr/bin/env bash
# quick backup script to mess with nvim config
# this does not work with dotfiles
## backup all files except those defined in ExcludeArray
## files in ExcludeArray will not be touched
## all other files in nvim config are deleted before restoring
## USAGE: 1. in $NVIM_PATH: bash backup.sh
## 2. in $NVIM_PATH/$BACKUP_FOLDER: bash restore.sh
#safer defaults https://bertvv.github.io/cheat-sheets/Bash.html
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
NVIM_PATH="${HOME}/.config/nvim"
BACKUP_FOLDER="backup"
RESTORE="restore.sh"
declare -a ExcludeArray=("backup.sh" "beta_software" "install" "list")
ExcludeArray+=(${BACKUP_FOLDER})
echo "excluding ${ExcludeArray[@]}"
if [ -f "${NVIM_PATH}/${BACKUP_FOLDER}" ]; then
echo "backup folder can not be created, please remove \"${BACKUP_FOLDER}\""
echo "exiting.."
exit 0
fi
mkdir ${BACKUP_FOLDER}
cd "${NVIM_PATH}"
# get all files at top level, that are not in ExcludeArray
for i in *; do
# how hard can it be to check in one line, if an element is in an array...
# https://www.mybluelinux.com/bash-guide-to-bash-arrays/#bash_array_contains_a_value_exact_match
if [[ ${ExcludeArray[@]} =~ (^|[[:space:]])"${i}"($|[[:space:]]) ]]; then
echo "dont copy: ${i}"
else
echo "copy recu: ${i}"
cp -r "${i}" "${NVIM_PATH}/${BACKUP_FOLDER}"
fi
done
echo "generate restore commands.."
cd "${NVIM_PATH}/${BACKUP_FOLDER}"
cat > "${RESTORE}" <<EOL
#!/bin/bash
# execute this script with
EOL
printf "# bash " >> "${RESTORE}"
printf "${RESTORE}\n" >> "${RESTORE}"
cat >> "${RESTORE}" <<EOL
# if rm fails: stop nvim and delete nvim config with `rm -fr`
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
NVIM_PATH="\${HOME}/.config/nvim"
BACKUP_FOLDER="${BACKUP_FOLDER}"
RESTORE="${RESTORE}"
EOL
# metaprogramming in bash sucks due to missing reflection
printf "declare -a ExcludeArray=(" >> "${RESTORE}"
for i in "${ExcludeArray[@]}"; do
printf "${i} " >> "${RESTORE}"
done
printf ")\n" >> "${RESTORE}"
cat >> "${RESTORE}" <<EOL
cd "\${NVIM_PATH}/"
# clean nvim config
for i in *; do
if [[ \${ExcludeArray[@]} =~ (^|[[:space:]])"\${i}"(\$|[[:space:]]) ]]; then
echo "dont remove: \${i}"
else
echo "remove recu: \${i}"
rm -r "\${i}"
fi
done
cd \${NVIM_PATH}/\${BACKUP_FOLDER}/
for i in *; do
if [[ "\${i}" == "\${RESTORE}" ]]; then
echo "dont copy \${i}"
continue
fi
if [[ \${ExcludeArray[@]} =~ (^|[[:space:]])"\${i}"(\$|[[:space:]]) ]]; then
echo "dont copy: \${i}"
else
echo "copy recu: \${i}"
cp -r "\${NVIM_PATH}/\${BACKUP_FOLDER}/\${i}" "\${NVIM_PATH}/"
fi
done
EOL
echo "done. have fun configuring nvim!" |
Beta Was this translation helpful? Give feedback.
-
#!/usr/bin/env bash
# reinstall fresh packer and clean all packages
# make sure to select correct location(s)
## Dont forget to close all neovim instances
## Manually deleting should not be necessary
mkdir -p "${HOME}/.local/share/nvim/site/pack/packer/opt"
mkdir -p "${HOME}/.local/share/nvim/site/pack/packer/start"
rm -r "${HOME}/.local/share/nvim/site/pack/packer/start"
git clone https://github.com/wbthomason/packer.nvim "${HOME}/.local/share/nvim/site/pack/packer/start/packer.nvim"
#rm -r "${HOME}/.local/share/nvim/site/pack/packer/opt"
#git clone https://github.com/wbthomason/packer.nvim "${HOME}/.local/share/nvim/site/pack/packer/opt/packer.nvim" |
Beta Was this translation helpful? Give feedback.
-
How can we make
packer
simpler and easier to use?Beta Was this translation helpful? Give feedback.
All reactions