| tAdd tests and CI - fffs - fast and simple shell plugin manager | |
| git clone git://src.adamsgaard.dk/fffs | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| commit 4dd27e406935a2df1c0b039883ba24830ece66ba | |
| Author: Anders Damsgaard <[email protected]> | |
| Date: Thu, 14 Mar 2019 17:08:23 +0100 | |
| Add tests and CI | |
| Diffstat: | |
| A .gitlab-ci.yml | 25 +++++++++++++++++++++++++ | |
| A fffs | 165 +++++++++++++++++++++++++++++… | |
| A run_tests.sh | 34 +++++++++++++++++++++++++++++… | |
| 3 files changed, 224 insertions(+), 0 deletions(-) | |
| --- | |
| diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml | |
| t@@ -0,0 +1,25 @@ | |
| +build-alpine: | |
| + stage: test | |
| + image: alpine:edge | |
| + before_script: | |
| + - apk --no-cache add git zsh bash | |
| + script: | |
| + - run_tests.sh | |
| + | |
| +build-debian: | |
| + stage: test | |
| + image: debian | |
| + before_script: | |
| + - apt-get update | |
| + - apt-get -y install git zsh bash | |
| + script: | |
| + - run_tests.sh | |
| + | |
| +build-arch: | |
| + stage: test | |
| + image: archlinux/base | |
| + before_script: | |
| + - pacman -Syu --noconfirm git zsh bash | |
| + script: | |
| + - run_tests.sh | |
| + | |
| diff --git a/fffs b/fffs | |
| t@@ -0,0 +1,165 @@ | |
| +#!/usr/bin/env bash | |
| + | |
| +set -e | |
| +#set -v | |
| + | |
| +version='0.1.0' | |
| + | |
| +confsubdir=".config/fffs" | |
| +confdir="$HOME/$confsubdir" | |
| +plugindir="$confdir/lib" | |
| +pluginfile="$confdir/plugins" | |
| + | |
| +function show_help { | |
| + echo "usage: ${0##*/} [OPTION] SHELL COMMAND" | |
| + echo "${0##*/} is a fast and simple manager for shell plugins" | |
| + echo "where SHELL can be 'bash' or 'zsh'." | |
| + echo "Valid COMMANDs are:" | |
| + echo " init fetch repositories specified in plugin file and" | |
| + echo " create configuration for parent shell. Call this" | |
| + echo " function after every update to the plugin file" | |
| + echo " update update all local plugin content" | |
| + echo " clean remove all local plugin content" | |
| + echo "Valid OPTIONs are:" | |
| + echo " -h, --help show this message" | |
| + echo " -v, --version show version and license information" | |
| + echo | |
| + echo "Set the plugin sources as git repository URLs in " | |
| + echo "$pluginfile-zsh or $pluginfile-bash" | |
| + echo "before running 'init'. Afterwards, add the generated sources file in… | |
| + echo "the shell-rc file. For ~/.zshrc:" | |
| + echo " if [ -f \"\$HOME/.config/fffs/lib/zsh/sources\" ]; then" | |
| + echo " . \"\$HOME/.config/fffs/lib/zsh/sources\"" | |
| + echo " else" | |
| + echo " fffs zsh init" | |
| + echo " . \"\$HOME/.config/fffs/lib/zsh/sources\"" | |
| + echo " fi" | |
| +} | |
| + | |
| +function show_version { | |
| + echo "${0##*/} version $version" | |
| + echo "Licensed under the GNU Public License, v3+" | |
| + echo "written by Anders Damsgaard, [email protected]" | |
| + echo "https://gitlab.com/admesg/fffs" | |
| +} | |
| + | |
| +function die { | |
| + printf '%s\n' "$1" >&2 | |
| + exit 1 | |
| +} | |
| + | |
| +function clone_repositories { | |
| + if [[ ! -f "$pluginfile-$shell" || | |
| + $(wc -l <"$pluginfile-$shell") -lt 1 ]]; then | |
| + (>&2 echo "No plugins specified in $pluginfile-$shell" ) | |
| + fi | |
| + | |
| + # loop over all repositories in $configfile, and clone them if they do not | |
| + # exist in $plugindir | |
| + while read -r line; do | |
| + target="$plugindir/$shell/${line##*/}" | |
| + if [[ -d "$target" ]]; then | |
| + echo "$target already exists, skipping." | |
| + else | |
| + echo "$line > $target" | |
| + git clone "$line" "$target" | |
| + fi | |
| + done < "$pluginfile-$shell" | |
| +} | |
| + | |
| +function update_repositories { | |
| + [[ ! -d "$plugindir/$shell" ]] && return | |
| + | |
| + for dir in "$plugindir/$shell"/*/; do | |
| + echo "Updating $dir..." | |
| + (cd "$dir" && git pull) | |
| + done | |
| + init_sources | |
| +} | |
| + | |
| +function check_if_source_in_shellrc { | |
| + if ! grep -r "$confsubdir/lib/$shell/sources" "$HOME/.${shell}rc" \ | |
| + >/dev/null 2>&1; then | |
| + echo | |
| + echo "Make sure to source the following line in your ~/.${shell}rc:" | |
| + echo " $plugindir/$shell/sources" | |
| + fi | |
| +} | |
| + | |
| +function init_sources { | |
| + echo "Generating source file $plugindir/$shell/sources" | |
| + echo "#!/usr/bin/env $shell" > "$plugindir/$shell/sources" | |
| + | |
| + if [[ "$shell" == "zsh" ]]; then | |
| + find "$plugindir/$shell/" -maxdepth 2 -type f \ | |
| + -iname '*.zsh' \ | |
| + | sed 's/^/. /' >> "$plugindir/$shell/sources" | |
| + elif [[ "$shell" == "bash" ]]; then | |
| + find "$plugindir/$shell/" -maxdepth 2 -type f \ | |
| + -iname '*.sh' -iname '*.bash' \ | |
| + | sed 's/^/. /' >> "$plugindir/$shell/sources" | |
| + else | |
| + die "Unknown shell $shell" | |
| + fi | |
| + | |
| + check_if_source_in_shellrc | |
| +} | |
| + | |
| +function init { | |
| + clone_repositories | |
| + init_sources | |
| +} | |
| + | |
| +function clean { | |
| + echo rm -rf "$plugindir" | |
| + rm -rf "$plugindir" | |
| +} | |
| + | |
| + | |
| +## Parse command-line arguments | |
| + | |
| +[[ $# -lt 1 ]] && (show_help && exit 1) | |
| + | |
| +shell="" | |
| +while :; do | |
| + case "$1" in | |
| + zsh) | |
| + [[ ! "$2" ]] && die 'Error: No command specified' | |
| + shell='zsh' | |
| + ;; | |
| + bash) | |
| + [[ ! "$2" ]] && die 'Error: No command specified' | |
| + shell='bash' | |
| + ;; | |
| + init) | |
| + [[ "$shell" == "" ]] && die 'Error: No SHELL specified' | |
| + (init && exit 0) | |
| + ;; | |
| + update) | |
| + [[ "$shell" == "" ]] && die 'Error: No SHELL specified' | |
| + (update_repositories && exit 0) | |
| + ;; | |
| + upgrade) | |
| + die 'Did you mean "update"?' | |
| + ;; | |
| + clean) | |
| + [[ "$shell" == "" ]] && die 'Error: No SHELL specified' | |
| + (clean && exit 0) | |
| + ;; | |
| + clear) | |
| + die 'Did you mean "clean"?' | |
| + ;; | |
| + -h|-\?|--help) | |
| + (show_help && exit 0) | |
| + ;; | |
| + -v|--version) | |
| + (show_version && exit 0) | |
| + ;; | |
| + ?*) | |
| + die 'Error: Unknown option specified' | |
| + ;; | |
| + *) # No more options | |
| + break | |
| + esac | |
| + shift | |
| +done | |
| diff --git a/run_tests.sh b/run_tests.sh | |
| t@@ -0,0 +1,34 @@ | |
| +#!/usr/bin/env bash | |
| +set -v | |
| +set -e | |
| + | |
| +./fffs -h | |
| +./fffs --help | |
| +./fffs -v | |
| +./fffs --version | |
| + | |
| +confdir=~/.config/fffs | |
| +pluginfile="$confdir/plugins-zsh" | |
| +[[ -f "$pluginfile" ]] && mv $pluginfile{,-bck} | |
| + | |
| +./fffs zsh clean | |
| +[[ -d "$confdir/lib" ]] && exit 1 | |
| + | |
| +echo -e "https://github.com/zsh-users/zsh-autosuggestions\n" \ | |
| + "https://github.com/zsh-users/zsh-completions\n" \ | |
| + "https://github.com/zsh-users/zsh-syntax-highlighting\n" \ | |
| + "https://github.com/zsh-users/zsh-history-substring-search" > $pluginfile | |
| + | |
| +./fffs zsh init | |
| + | |
| +[[ ! -d "$confdir" ]] && exit 1 | |
| +[[ ! -d "$confdir/lib" ]] && exit 1 | |
| +[[ ! -d "$confdir/lib/zsh" ]] && exit 1 | |
| +[[ ! -f "$confdir/lib/zsh/sources" ]] && exit 1 | |
| + | |
| +[[ $(find "$confdir/lib/zsh" | wc -l) -gt 10 ]] || exit 1 | |
| + | |
| +./fffs zsh update | |
| + | |
| +[[ -f "$pluginfile-bck" ]] && mv $pluginfile{-bck,} | |
| +./fffs zsh init |