tRewrite to POSIX shell - fffs - fast and simple shell plugin manager
 (HTM) git clone git://src.adamsgaard.dk/fffs
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 1461b95199cd59c42494da587a37f0c1d4b64b23
 (DIR) parent 5cd41bd0b4241a06f6a5fd6f54691cd227a17da8
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Sat, 21 Sep 2019 08:41:46 +0200
       
       Rewrite to POSIX shell
       
       Diffstat:
         M fffs                                |      44 +++++++++++++++----------------
         M run_tests.sh                        |      22 +++++++++++-----------
       
       2 files changed, 32 insertions(+), 34 deletions(-)
       ---
 (DIR) diff --git a/fffs b/fffs
       t@@ -1,7 +1,6 @@
       -#!/usr/bin/env bash
       +#!/bin/sh
        
        set -e
       -#set -v
        
        version='0.1.0'
        
       t@@ -10,7 +9,7 @@ confdir="$HOME/$confsubdir"
        plugindir="$confdir/lib"
        pluginfile="$confdir/plugins"
        
       -function show_help {
       +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'."
       t@@ -36,21 +35,20 @@ function show_help {
            echo "    fi"
        }
        
       -function show_version {
       +show_version() {
            echo "${0##*/} version $version"
            echo "Licensed under the GNU Public License, v3+"
            echo "written by Anders Damsgaard, anders@adamsgaard.dk"
            echo "https://gitlab.com/admesg/fffs"
        }
        
       -function die {
       +die() {
            printf '%s\n' "$1" >&2
            exit 1
        }
        
       -function clone_repositories {
       -    if [[ ! -f "$pluginfile-$shell" ||
       -        $(wc -l <"$pluginfile-$shell") -lt 1 ]]; then
       +clone_repositories() {
       +    if [ ! -f "$pluginfile-$shell" ] || [ "$(wc -l <"$pluginfile-$shell")" -lt 1 ]; then
                (>&2 echo "No plugins specified in $pluginfile-$shell" )
            fi
        
       t@@ -58,7 +56,7 @@ function clone_repositories {
            # exist in $plugindir
            while read -r line; do
                target="$plugindir/$shell/${line##*/}"
       -        if [[ -d "$target" ]]; then
       +        if [ -d "$target" ]; then
                    echo "$target already exists, skipping."
                else
                    echo "$line > $target"
       t@@ -67,8 +65,8 @@ function clone_repositories {
            done < "$pluginfile-$shell"
        }
        
       -function update_repositories {
       -    [[ ! -d "$plugindir/$shell" ]] && return
       +update_repositories() {
       +    [ ! -d "$plugindir/$shell" ] && return
        
            for dir in "$plugindir/$shell"/*/; do
                echo "Updating $dir..."
       t@@ -77,7 +75,7 @@ function update_repositories {
            init_sources
        }
        
       -function check_if_source_in_shellrc {
       +check_if_source_in_shellrc() {
            if ! grep -r "$confsubdir/lib/$shell/sources" "$HOME/.${shell}rc" \
                >/dev/null 2>&1; then
                echo
       t@@ -86,16 +84,16 @@ function check_if_source_in_shellrc {
            fi
        }
        
       -function init_sources {
       +init_sources() {
            echo "Generating source file $plugindir/$shell/sources"
            mkdir -p "$plugindir/$shell"
            echo "#!/usr/bin/env $shell" > "$plugindir/$shell/sources"
        
       -    if [[ "$shell" == "zsh" ]]; then
       +    if [ "$shell" = "zsh" ]; then
                find "$plugindir/$shell/" -maxdepth 2 -type f \
                    -iname '*.zsh' \
                    | sed 's/^/. /' >> "$plugindir/$shell/sources"
       -    elif [[ "$shell" == "bash" ]]; then
       +    elif [ "$shell" = "bash" ]; then
                find "$plugindir/$shell/" -maxdepth 2 -type f \
                    -iname '*.sh' -iname '*.bash' \
                    | sed 's/^/. /' >> "$plugindir/$shell/sources"
       t@@ -106,12 +104,12 @@ function init_sources {
            check_if_source_in_shellrc
        }
        
       -function init {
       +init() {
            clone_repositories
            init_sources
        }
        
       -function clean {
       +clean() {
            echo rm -rf "$plugindir"
            rm -rf "$plugindir"
        }
       t@@ -119,32 +117,32 @@ function clean {
        
        ## Parse command-line arguments
        
       -[[ $# -lt 1 ]] && (show_help && exit 1)
       +[ $# -lt 1 ] && (show_help && exit 1)
        
        shell=""
        while :; do
            case "$1" in
                zsh)
       -            [[ ! "$2" ]] && die 'Error: No command specified'
       +            [ ! "$2" ] && die 'Error: No command specified'
                    shell='zsh'
                    ;;
                bash)
       -            [[ ! "$2" ]] && die 'Error: No command specified'
       +            [ ! "$2" ] && die 'Error: No command specified'
                    shell='bash'
                    ;;
                init)
       -            [[ "$shell" == "" ]] && die 'Error: No SHELL specified'
       +            [ -z "$shell" ] && die 'Error: No SHELL specified'
                    (init && exit 0)
                    ;;
                update)
       -            [[ "$shell" == "" ]] && die 'Error: No SHELL specified'
       +            [ -z "$shell" ] && die 'Error: No SHELL specified'
                    (update_repositories && exit 0)
                    ;;
                upgrade)
                    die 'Did you mean "update"?'
                    ;;
                clean)
       -            [[ "$shell" == "" ]] && die 'Error: No SHELL specified'
       +            [ -z "$shell" ] && die 'Error: No SHELL specified'
                    (clean && exit 0)
                    ;;
                clear)
 (DIR) diff --git a/run_tests.sh b/run_tests.sh
       t@@ -1,4 +1,4 @@
       -#!/usr/bin/env bash
       +#!/bin/sh
        set -v
        set -e
        
       t@@ -9,27 +9,27 @@ set -e
        
        confdir=~/.config/fffs
        pluginfile="$confdir/plugins-zsh"
       -[[ -f "$pluginfile" ]] && mv $pluginfile{,-bck}
       +[ -f "$pluginfile" ] && mv "$pluginfile" "$pluginfile-bck"
        
        ./fffs zsh clean
       -[[ -d "$confdir/lib" ]] && exit 1
       +[ -d "$confdir/lib" ] && exit 1
        
        mkdir -p "$confdir"
       -echo -e "https://github.com/zsh-users/zsh-autosuggestions\n"\
       +printf "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
       +    "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
       +[ ! -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
       +[ $(find "$confdir/lib/zsh" | wc -l) -gt 10 ] || exit 1
        
        ./fffs zsh update
        
       -[[ -f "$pluginfile-bck" ]] && mv $pluginfile{-bck,}
       +[ -f "$pluginfile-bck" ] && mv "$pluginfile-bck" "$pluginfile"
        ./fffs zsh init