Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.
0 votes
in vifm by

Like zip, tar.gz, etc.

1 Answer

+1 vote
by

You need to invoke external tools. There are those which handle archives of different types for you, e.g. atool:

command! unpack aunpack %c

In case you don't want to install anything, here is a script I tend to use (stored as ~/.vifm/scripts/extract):

#!/bin/bash

if [ $# -lt 2 ]; then
    echo "Usage: $(basename $0) [-f] destdir achieve.."
    echo '-f forces creation of nonexistent destdir'
    exit 1
fi

if [ "$1" = '-f' ]; then
    FORCE=1
    shift
else
    FORCE=0
fi

if [ -z "$1" ]; then
    OUTPUT=.
else
    OUTPUT="$1"
fi
shift

if [ ! -d "$OUTPUT" ]; then
    if [ -e "$OUTPUT" ]; then
        echo "'$OUTPUT' already exists and is not a directory"
        exit 1
    elif [ "$FORCE" != "0" ]; then
        mkdir -p "$OUTPUT"
    else
        echo "'$OUTPUT' doesn't exist"
        exit 1
    fi
fi

exitcode=0

for file; do
    if [ ! -f "$file" ]; then
        echo "'$file' is not a valid file"
        continue
    fi

    FULL=$(readlink -f "$file")

    cd "$OUTPUT"

    case "$file" in
        *.tar.bz2) tar xvjf "$FULL" ;;
        *.tar.gz) tar xvzf "$FULL" ;;
        *.bz2) bunzip2 "$FULL" ;;
        *.rar) unrar x "$FULL" ;;
        *.gz) gunzip "$FULL" ;;
        *.tar) tar xvf "$FULL" ;;
        *.tbz2) tar xvjf "$FULL" ;;
        *.tgz) tar xvzf "$FULL" ;;
        *.war) unzip "$FULL" ;;
        *.zip) unzip "$FULL" ;;
        *.Z) uncompress "$FULL" ;;
        *.7z) 7z x "$FULL" ;;
        *.tar.lzma) tar xf "$FULL" ;;
        *.tar.xz) tar xf "$FULL" ;;
        *) echo "'$file' cannot be extracted via this script"; exitcode=1 ;;
    esac

    cd "$OLDPWD"
done

exit $exitcode

Through these commands in vifmrc:

command! extract extract %a %f %n
command! extract! extract -f %a %f %n

Examples:

  • :extract - extracts archive under cursor into current directory
  • :extract %D - extracts archive under cursor into directory of other pane
  • :extract! sub - extracts archive under cursor into sub/ inside current directory
by

Awesome, thanks a lot!
One thing: It tells me "permission denied". Do I need to change the permissions of the extract file?

by

Yes, to be able to run any script it needs to be executable, so do chmod +x extract.

by

Obviously, thanks again

by

I'm using this solution on my Linux PC and it works great.
Is there a solution for Windows as well?

by

Is there a solution for Windows as well?

Don't think I wrote a script for Windows. But you can try using unpack plugin which worked on Windows as far as I remember (also see plugin basics).

by

will try that, thanks a lot for the hint xaizek!

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...