dotfiles

My dotfiles used for LARBS
Log | Files | Refs | README | LICENSE

ext (1346B)


      1 #!/usr/bin/env sh
      2 
      3 # A general, all-purpose extraction script. Not all extraction programs here
      4 # are installed by LARBS automatically.
      5 #
      6 # Default behavior: Extract archive into new directory
      7 # Behavior with `-c` option: Extract contents into current directory
      8 
      9 while getopts "hc" o; do case "${o}" in
     10 	c) extracthere="True" ;;
     11 	*) printf "Options:\\n   -c: Extract archive into current directory rather than a new one.\\n" && exit ;;
     12 esac done
     13 
     14 if [ -z "$extracthere" ]; then
     15 	archive="$(readlink -f "$*")" &&
     16 	directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" &&
     17 	mkdir -p "$directory" &&
     18 	cd "$directory" || exit
     19 else
     20 	archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)")"
     21 fi
     22 
     23 [ "$archive" = "" ] && printf "Give archive to extract as argument.\\n" && exit
     24 
     25 if [ -f "$archive" ] ; then
     26 	case "$archive" in
     27 		*.tar.bz2|*.tar.xz|*.tbz2) tar xvjf "$archive" ;;
     28 		*.tar.gz|*.tgz) tar xvzf "$archive" ;;
     29 		*.lzma) unlzma "$archive" ;;
     30 		*.bz2) bunzip2 "$archive" ;;
     31 		*.rar) unrar x -ad "$archive" ;;
     32 		*.gz) gunzip "$archive" ;;
     33 		*.tar) tar xvf "$archive" ;;
     34 		*.zip) unzip "$archive" ;;
     35 		*.Z) uncompress "$archive" ;;
     36 		*.7z) 7z x "$archive" ;;
     37 		*.xz) unxz "$archive" ;;
     38 		*.exe) cabextract "$archive" ;;
     39 		*) printf "extract: '%s' - unknown archive method\\n" "$archive" ;;
     40 	esac
     41 else
     42 	printf "File \"%s\" not found.\\n" "$archive"
     43 fi