diff --git a/scripts/xpress b/scripts/xpress index 4a7b71e7..d0145fb6 100755 --- a/scripts/xpress +++ b/scripts/xpress @@ -45,16 +45,50 @@ echo "${txtgreen}xpress: a simple shell script for compressing common file forma tput bold & tput setaf 7 # grabs the extension string -extension=$(echo "${1}" | sed 's/^[^\..:]*[\..]//') +extension=$(echo "${1}" | sed 's/^[^\..:]*[\..*]//') # grabs the filename/directoryname string fdname=$(echo "${1}" | sed 's/\..*$//') -# Simply copy and paste, changing extension string and extraction method below -if [ "${extension}" == "tgz" ] ; then - dependencycheck tar gzip - echo "${txtblue}compressing .tgz...${txtyellow}" - # main extraction method - tar -cvzf "${1}" "${fdname}" &> /dev/null - echo ".tgz compression finished!${txtwhite}" +# create an array and a for loop of various +# ".txt" and ".js" and ".c" and ".py" files etc... for here +# if the file is a .txt file... +forbidden=".txt" +# if grep -q ".txt" <<< "${1}" ; then +if grep -q "${forbidden}" <<< "${1}" ; then + # if extension has "txt." in it, remove "txt." from extension + # this is mess, but put another if statement and another array that compares .txt to txt. + extension=$(echo "${extension}" | sed -r 's/^txt.//g') + # doesn't work: + # extension=$(echo "${extension}" | sed -r "s/^$forbidden//g") + # appends .txt to the filename if .txt exists in the original argument + # fdname="${fdname}.txt" + fdname="${fdname}${forbidden}" +fi + +# Simply copy and paste, changing extension string and extraction method below +if [[ -d $fdname ]] ; then + if [ "${extension}" == "tar" ] ; then + dependencycheck tar + echo "${txtblue}compressing .tar...${txtyellow}" + # main compression method + tar cf "${1}" "${fdname}" + echo ".tar compression finished!${txtwhite}" + fi + + if [ "${extension}" == "tgz" ] ; then + dependencycheck tar gzip + echo "${txtblue}compressing .tgz...${txtyellow}" + # main compression method + tar -czf "${1}" "${fdname}" + echo ".tgz compression finished!${txtwhite}" + fi +elif [[ -f $fdname ]] ; then + if [ "${extension}" == "gz" ] ; then + dependencycheck gzip + echo "${txtblue}compressing .gz...${txtyellow}" + # main compression method + gzip --keep "${fdname}" + echo ".gz compression finished!${txtwhite}" + fi fi diff --git a/scripts/xtract b/scripts/xtract index 07baa882..c64a60c0 100755 --- a/scripts/xtract +++ b/scripts/xtract @@ -47,11 +47,36 @@ tput bold & tput setaf 7 # grabs the extension string extension=$(echo "${1}" | sed 's/^[^\..:]*[\..]//') +# create an array and a for loop of various +# ".txt" and ".js" and ".c" and ".py" files etc... for here +# if the file is a .txt file... +forbidden="txt" +if grep -q "${forbidden}" <<< "${1}" ; then + # if extension has "txt." in it, remove "txt." from extension + extension=$(echo "${extension}" | sed -r "s/^$forbidden.//g") +fi + # Simply copy and paste, changing extension string and extraction method below +if [ "${extension}" == "tar" ] ; then + dependencycheck tar + echo "${txtblue}decompressing .tar...${txtyellow}" + # main extraction method + tar xf "${1}" + echo ".tar decompression finished!${txtwhite}" +fi + if [ "${extension}" == "tgz" ] ; then dependencycheck tar gunzip echo "${txtblue}decompressing .tgz...${txtyellow}" # main extraction method - tar zxvf "${1}" &> /dev/null + tar zxf "${1}" echo ".tgz decompression finished!${txtwhite}" fi + +if [ "${extension}" == "gz" ] ; then + dependencycheck gunzip + echo "${txtblue}decompressing .gz...${txtyellow}" + # main extraction method + gunzip --keep "${1}" + echo ".gz decompression finished!${txtwhite}" +fi