<commit_before>#!/bin/bash
FORCEACTION=0
echo -e "\n\n"
if [[ "$OSTYPE" != "darwin"* ]]; then
	echo "This script works for MAC OSx only!"
	echo "BYE!"
	exit 1
fi

if [ -z "$HOME" ]; then
    echo "Cannot define user home directory in $HOME"
    exit
fi

DBLSETTINGS="$HOME/Library/Preferences/doublecmd"
THISPATH="$(pwd)"
THEMEROOT="$(pwd)/Themes"

confirm() {
    select result in Yes No
    do
        echo $result
        if [[ $result != "Yes" ]]; then
            echo -e "BYE!\n" 1>&2; exit 1;
        fi
        break;
    done
}


usage() { 
        echo "Nothing to do."
        echo -e "Usage $0 [themename] to apply existing theme
        -             [-l  list]
        -             [-c  <name> create new theme] 
        -             [-f -c <name> replase existing theme]
        \n\n" 1>&2; exit 1;
}

backup() {
    if [ -f "$DBLSETTINGS/backup.tar.gz" ] ; then
        return
    fi
    echo "Creating backup ..."
    echo "Backup creates only once with Your original files."
    cd $DBLSETTINGS
    tar -C $DBLSETTINGS  -cvjf "backup.tar.gz" --exclude="backup.tar.gz" ./
    cd $THISPATH
    echo "... done"
}

restore() {
    echo "Restore backup ..."
    tar -xvf "$DBLSETTINGS/backup.tar.gz"
    echo "... done"
}

createtheme() {
    echo "Creating theme: \"$1\"..."
    themeselect=$1

    if [ -z "${themeselect}" ] ; then
        usage
    fi

    THEMEAPPLY="$THEMEROOT/$themeselect"

    if [ -d "$THEMEAPPLY" ] && [ $FORCEACTION == 0 ] ; then
        echo "Theme exist, use new Theme name"  1>&2; exit 1;
    fi
    DCONFIG=$THEMEAPPLY/config
    mkdir -p $DCONFIG
    files=( doublecmd.xml extassoc.xml highlighters.xml multiarc.ini pixmaps.txt shortcuts.scf )
    for i in "${files[@]}"
    do
        cp $DBLSETTINGS/$i $DCONFIG/
    done
    echo "... done"

    echo -e "Prepare \"Double Commander\" window size for capturing screenshot.
    Make sure there is no secure info displayed :)"
    read -rsp $'Press any key to continue...\n' -n1 key

    echo "Select \"Double Commander\" window to make a screenshot for \"$1\" theme on the next step"
    read -rsp $'Press any key to continue...\n' -n1 key
    
    open "/Applications/Double Commander.app" 2>/dev/null
    screencapture -W  "$THEMEAPPLY/$themeselect.png"
    echo "Finish"
}

#while getopts ":s:p:l:r" o; do
while getopts ":lr:c:f" o; do
    case "${o}" in
        f)
            FORCEACTION=1
            ;;
        c)
            createtheme ${OPTARG}
            exit
            ;;
        r)
            restore
            exit
            ;;
        l)
            echo "Available Themes:"
            ls -1 ./Themes
            echo ""
            exit
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

# read theme
themeselect=${1}

if [ -z "${themeselect}" ] ; then
    usage
fi

THEMEAPPLY="$THEMEROOT/$themeselect"

if [ ! -d "$THEMEAPPLY" ] ; then
    usage
fi

echo -e "The original config files of Double Commander will be replased with files from \"${themeselect}\" Theme.
Shortcuts and all other settings will be overwritten.
Do you want to continue?"
confirm

pkill -9 "doublecmd"

backup

echo "Moving files ..."
    cp -L $THEMEAPPLY/config/* $DBLSETTINGS
echo "... done"

open "/Applications/Double Commander.app" 2>/dev/null<commit_msg>update comments<commit_after>#!/bin/bash
FORCEACTION=0
echo -e "\n\n"
if [[ "$OSTYPE" != "darwin"* ]]; then
	echo "This script works for MAC OSx only!"
	echo "BYE!"
	exit 1
fi

if [ -z "$HOME" ]; then
    echo "Cannot define user home directory in $HOME"
    exit
fi

DBLSETTINGS="$HOME/Library/Preferences/doublecmd"
THISPATH="$(pwd)"
THEMEROOT="$(pwd)/Themes"

confirm() {
    select result in Yes No
    do
        echo $result
        if [[ $result != "Yes" ]]; then
            echo -e "BYE!\n" 1>&2; exit 1;
        fi
        break;
    done
}


usage() { 
        echo "Nothing to do."
        echo -e "Usage $0 [themename] to apply existing theme
        -             [-l  list]
        -             [-c  <name> create new theme with active settings] 
        -             [-f -c <name> replase existing theme with active settings]
        \n\n" 1>&2; exit 1;
}

backup() {
    if [ -f "$DBLSETTINGS/backup.tar.gz" ] ; then
        return
    fi
    echo "Creating backup ..."
    echo "Backup creates only once with Your original files."
    cd $DBLSETTINGS
    tar -C $DBLSETTINGS  -cvjf "backup.tar.gz" --exclude="backup.tar.gz" ./
    cd $THISPATH
    echo "... done"
}

restore() {
    echo -e "Do you want to restore last used theme?"
    confirm
    echo "Restoring backup ..."
    tar -xvf "$DBLSETTINGS/backup.tar.gz"
    echo "... done"
}

createtheme() {
    echo "Creating theme: \"$1\"..."
    themeselect=$1

    if [ -z "${themeselect}" ] ; then
        usage
    fi

    THEMEAPPLY="$THEMEROOT/$themeselect"

    if [ -d "$THEMEAPPLY" ] && [ $FORCEACTION == 0 ] ; then
        echo "Theme exist, use new Theme name"  1>&2; exit 1;
    fi
    DCONFIG=$THEMEAPPLY/config
    mkdir -p $DCONFIG
    files=( doublecmd.xml extassoc.xml highlighters.xml multiarc.ini pixmaps.txt shortcuts.scf )
    for i in "${files[@]}"
    do
        cp $DBLSETTINGS/$i $DCONFIG/
    done
    echo "... done"

    echo -e "Prepare \"Double Commander\" window size for capturing screenshot.
    Make sure there is no secure info displayed :)"
    read -rsp $'Press any key to continue...\n' -n1 key

    echo "Select \"Double Commander\" window to make a screenshot for \"$1\" theme on the next step"
    read -rsp $'Press any key to continue...\n' -n1 key
    
    open "/Applications/Double Commander.app" 2>/dev/null
    screencapture -W  "$THEMEAPPLY/$themeselect.png"
    echo "Finish"
}

#while getopts ":s:p:l:r" o; do
while getopts ":lrc:f" o; do
    case "${o}" in
        f)
            FORCEACTION=1
            ;;
        c)
            createtheme ${OPTARG}
            exit
            ;;
        r)
            restore
            exit
            ;;
        l)
            echo "Available Themes:"
            ls -1 ./Themes
            echo ""
            exit
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

# read theme
themeselect=${1}

if [ -z "${themeselect}" ] ; then
    usage
fi

THEMEAPPLY="$THEMEROOT/$themeselect"

if [ ! -d "$THEMEAPPLY" ] ; then
    usage
fi

echo -e "The original config files of Double Commander will be replased with files from \"${themeselect}\" Theme.
Shortcuts and all other settings will be overwritten.
Do you want to continue?"
confirm

pkill -9 "doublecmd"

backup

echo "Moving files ..."
    cp -L $THEMEAPPLY/config/* $DBLSETTINGS
echo "... done"

open "/Applications/Double Commander.app" 2>/dev/null
{'fraction_non_alphanumeric': 0.1347728965003723, 'fraction_numerical': 0.007446016381236039, 'mean_word_length': 1.953386103781882, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6757294', 'n_tokens_mistral': 2303, 'n_tokens_neox': 2220, 'n_words': 709}