<commit_before>#!/usr/bin/env bash
#  DETAILS: Tar wrappers
#  CREATED: 07/17/13 15:53:58 IST
# MODIFIED: 10/20/14 10:59:10 IST
#
#   AUTHOR: <NAME>., <EMAIL>
#  LICENCE: Copyright (c) 2013, <NAME>.

# Warn unset vars as error, Verbose (echo each command), Enable debug mode
#set -uvx

# Source .bashrc only if invoked as a sub-shell.
if [[ "$(basename tar.sh)" == "$(basename -- $0)" ]] && [ -f $HOME/.bashrc ]; then
    source $HOME/.bashrc
    log_init INFO $SCRIPT_LOGS/tar.log
fi

function archive()
{
    test -e $2 && echo "archiving $2 into $2.$1" || { echo "'$2' is not a valid path"; return $EINVAL; }
    case $1 in
        7z)   7za a -t7z -mx9 $2.$1 $2   ;;
        bz2)  tar cvjf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        gz)   tar cvzf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        tar)  tar cvf -X $CUSTOM_CONFS/tarexclude $2.$1 $2     ;;
        tbz2) tar cvjf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        tgz)  tar cvzf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        rar)  rar x $2    ;;
        zip)  zip $2      ;;
        Z)    compress $2 ;;
        *)    echo "'$1' cannot be compressed via archive()"        ;;
    esac
}

function extract()
{
    local file=$(basename $1); local fpath=$1; local dname=$(untar_dname $fpath)
    [[ -e $fpath ]] && echo "extract $fpath into $dname/" || { echo "File $fpath not found"; return $EINVAL; }
    case $fpath in
        *.7z)       7za x $fpath      ;;
        *.tar.bz2)  tar xvjf $fpath   ;;
        *.tar.gz)   tar xvzf $fpath   ;;
        *.bz2)      bunzip2 $fpath    ;;
        *.rar)      unrar x $fpath    ;;
        *.gz)       gunzip $fpath     ;;
        *.tar)      tar xvfp $fpath   ;;
        *.tbz2)     tar xvjf $fpath   ;;
        *.tgz)      tar xvzf $fpath   ;;
        *.zip)      unzip $fpath      ;;
        *.Z)        uncompress $fpath ;;
        *)          echo "$fpath can not be extracted via extract()" ;;
    esac
    fail_bail;
}

function list()
{
    local filename=$(basename $1);
    test -e $1 && echo "listing $1 contents" || { echo "'$1' is not a valid file"; return $EINVAL; }
    case $1 in
        *.7z)       7za l $1        ;;
        *.tar.bz2)  tar tvjf $1     ;;
        *.tar.gz)   tar tvzf $1     ;;
        *.rar)      rar l $1        ;;
        *.gz)       gzip -l $1      ;;
        *.tar)      tar tvf $1      ;;
        *.tbz2)     tar tvjf $1     ;;
        *.tgz)      tar tvzf $1     ;;
        *.zip)      unzip -l $1     ;;
        *.Z)        zcat $1         ;;
        *)          echo "'$1' cannot be listed via list()" ;;
    esac
}

function untar_dname()
{
    case $1 in
        *.tar.bz2|*.tar.gz|*.tar.tar)  echo "${file%.*.*}"  ;;
        *.7z|*.bz2|*.rar|*.gz|*.tar|*.tbz2|*.tgz|*.zip|*.Z) echo "${file%.*}"  ;;
        *)  ;;
    esac
}<commit_msg>fix bug in tar.sh file<commit_after>#!/usr/bin/env bash
#  DETAILS: Tar wrappers
#  CREATED: 07/17/13 15:53:58 IST
# MODIFIED: 10/20/14 14:03:17 IST
#
#   AUTHOR: <NAME>., <EMAIL>
#  LICENCE: Copyright (c) 2013, <NAME>.

# Warn unset vars as error, Verbose (echo each command), Enable debug mode
#set -uvx

# Source .bashrc only if invoked as a sub-shell.
if [[ "$(basename tar.sh)" == "$(basename -- $0)" ]] && [ -f $HOME/.bashrc ]; then
    source $HOME/.bashrc
    log_init INFO $SCRIPT_LOGS/tar.log
fi

function archive()
{
    test -e $2 && echo "archiving $2 into $2.$1" || { echo "'$2' is not a valid path"; return $EINVAL; }
    case $1 in
        7z)   7za a -t7z -mx9 $2.$1 $2   ;;
        bz2)  tar cvjf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        gz)   tar cvzf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        tar)  tar cvf -X $CUSTOM_CONFS/tarexclude $2.$1 $2     ;;
        tbz2) tar cvjf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        tgz)  tar cvzf -X $CUSTOM_CONFS/tarexclude $2.$1 $2    ;;
        rar)  rar x $2    ;;
        zip)  zip $2      ;;
        Z)    compress $2 ;;
        *)    echo "'$1' cannot be compressed via archive()"        ;;
    esac
}

function extract()
{
    local file=$(basename $1); local fpath=$1; local dname=$(untar_dname $fpath)
    [[ -e $fpath ]] && echo "extract $fpath into $dname/" || { echo "File $fpath not found"; return $EINVAL; }
    case $fpath in
        *.7z)       7za x $fpath      ;;
        *.tar.bz2)  tar xvjf $fpath   ;;
        *.tar.gz)   tar xvzf $fpath   ;;
        *.bz2)      bunzip2 $fpath    ;;
        *.rar)      unrar x $fpath    ;;
        *.gz)       gunzip $fpath     ;;
        *.tar)      tar xvfp $fpath   ;;
        *.tbz2)     tar xvjf $fpath   ;;
        *.tgz)      tar xvzf $fpath   ;;
        *.zip)      unzip $fpath      ;;
        *.Z)        uncompress $fpath ;;
        *)          echo "$fpath can not be extracted via extract()" ;;
    esac
    fail_bail;
}

function list()
{
    local filename=$(basename $1);
    test -e $1 && echo "listing $1 contents" || { echo "'$1' is not a valid file"; return $EINVAL; }
    case $1 in
        *.7z)       7za l $1        ;;
        *.tar.bz2)  tar tvjf $1     ;;
        *.tar.gz)   tar tvzf $1     ;;
        *.rar)      rar l $1        ;;
        *.gz)       gzip -l $1      ;;
        *.tar)      tar tvf $1      ;;
        *.tbz2)     tar tvjf $1     ;;
        *.tgz)      tar tvzf $1     ;;
        *.zip)      unzip -l $1     ;;
        *.Z)        zcat $1         ;;
        *)          echo "'$1' cannot be listed via list()" ;;
    esac
}

function untar_dname()
{
    case $1 in
        *.tar.bz2|*.tar.gz|*.tar.tar)  echo "${1%.*.*}"  ;;
        *.7z|*.bz2|*.rar|*.gz|*.tar|*.tbz2|*.tgz|*.zip|*.Z) echo "${1%.*}"  ;;
        *)  ;;
    esac
}
{'fraction_non_alphanumeric': 0.17416829745596868, 'fraction_numerical': 0.03451343177370575, 'mean_word_length': 1.6003700277520814, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6455145', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2153, 'n_words': 606}