How many times had you entered these:

wget <S-Ins><CR>
tar xf f<Tab><CR>
cd f<Tab><CR>

Where ‘f’ is the first letter of a tarball’s filename. I believed I had typed those one million time.

I finally wrote a simple Bash function to reduce the typing:

wt <S-Ins><CR>

Done. The code is

# Usage: wt 'http://example.com/blah.blah.tar.gz' [keep]
# If [keep] is presented, whatever it is, the tarball will be kept.
wt() {
  (( $# == 0 )) && return
  URL="$1"
  keep="$2"
  filename="$(basename "$URL")"
  wget "$URL" -O "$filename"
  tar xf "$filename"
  [[ -z "$keep" ]] && rm "$filename"
  # Guessing the directory
  d="${filename%%.[a-z]*}"
  if [[ -d "$d" ]]; then
    cd "$d"
  else
    echo "Sorry, I don't know what's the name of extracted directory."
  fi
  }

I put it in my .bash_helper_func.sh. I could have just put it in a shell script, but it’s not really long.

By the way, I want to take this chance to talk about tar. I have seen many people use

tar zxvf foobar.tar.gz
tar jxvf foobar.tar.bz2

Using v that I could understand, but z and j are really unnecessary. tar is smart enough to identify the compression type. Just xf would do the job well, you can also drop v, I doubt anyone seriously need to read extraction in progress.

If you un-tar on the fly, then you need to specify the compression type, e.g.

wget "$URL" -O - | tar zxf -

This command is for gzip type. If anyone knows how to make tar guessing compression type from received content, so the z can be dropped, please let me know. And any thoughts about this wt(), feel free to comment!