I use avfs to conveniently look inside archives from a shell prompt. This creates a view of the whole directory tree under ~/.avfs (so if a file /path/to/foo exists then it's also visible as ~/.avfs/path/to/foo), and additionally, if /path/to/foo is an archive file then ~/.avfs/path/to/foo# is a directory which is a view of the toplevel directory of the content of the archive.

When I want to explore the inside of an archive, it's a bit cumbersome: I have to switch into the ~/.avfs hierarchy, and the completion of cd doesn't help me to type those archive names and add a # at the end.

I'd like to be able to run acd foo.zip from /path/to/dir and run cd ~/.avfs/path/to/dir#. With decent completion for acd. How can I do this?


Here's my implementation of acd. It does the right thing whether the argument is a directory or an archive. acd with no argument is equivalent to acd ..

avfs_cd () {
  case "$2" in
    "$HOME/.avfs/"*) :;;
    /*) set -- "$1" "$HOME/.avfs$2";;
    *) set -- "$1" "$HOME/.avfs$PWD/$2"
  if ! [ -d "$2" ]; then
    set -- "$1" "${2}#"
  "$1" "$2"
alias acd='avfs_cd cd'
alias apushd='avfs_cd pushd'

And here's my zsh completion function:

_acd () {
  _files -g "*.(7z|rar|tar.bz2|tar.gz|tar.xz|tbz2|tgz|zip)(e\\''REPLY=\${REPLY}\\#'\\')"
compdef _acd acd apushd
  • Personally I would have named it cdar so I could pronounce it in a pirate-y voice ("CD arrrrr") or as a homophone for CD-R. – jamesdlin Jun 7 '17 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.