brendanorourke / dotfiles

Brendan's macOS and Ubuntu dotfiles.
0 stars 0 forks source link

Standardize file extraction logic #14

Open brendanorourke opened 6 years ago

brendanorourke commented 6 years ago

As it stands, logic to extract compressed files from HTTP downloads is all over the place, see here.

That's one ugly function.

Logic for extracting files should be abstracted into a util function, which can also be exposed as terminal bin, for the user.

A great example from nparikh:

smartextract () {
    if [ -f $1 ]; then
        case $1 in
            *.tar.bz2)  tar -jxvf $1        ;;
            *.tar.gz)   tar -zxvf $1        ;;
            *.bz2)      bunzip2 $1          ;;
            *.dmg)      hdiutil mount $1    ;;
            *.gz)       gunzip $1           ;;
            *.tar)      tar -xvf $1         ;;
            *.tbz2)     tar -jxvf $1        ;;
            *.tgz)      tar -zxvf $1        ;;
            *.zip)      unzip $1            ;;
            *.Z)        uncompress $1       ;;
            *)          echo "'$1' cannot be extracted/mounted via smartextract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}
brendanorourke commented 6 years ago

Note: some checks for installation of the appropriate tools (tar, gunzip, etc.) will be required, given that this repo spans both macOS and Ubuntu.

Or they can simply all be installed on init, or both-- :see_no_evil: