Ranger 檔案管理器 - 讓它用自訂腳本開啟存檔檔案?

Ranger 檔案管理器 - 讓它用自訂腳本開啟存檔檔案?

我已經獲得了一個自定義的 bash 腳本,它提取所有存檔文件並等待輸入。以下:

    #!/bin/bash

GET="."

SCRIPTNAME="${0##*/}"

err() {
    printf >&2 "$SCRIPTNAME: $*\n"
    exit 1
}

ARC="$1"
[[ -f $ARC ]] || err $"'$ARC' does not exist"
ARC="$(readlink -f "$ARC")"

read -p "Extract to [default: $DEFAULT_TARGET]: " TARGET
[[ -z $TARGET ]] &&\
    TARGET="$DEFAULT_TARGET"
[[ -d $TARGET ]] || err $"Directory '$TARGET' does not exist"
[[ -w $TARGET ]] || err $"Permission denied: '$TARGET' is not writable"

cd "$TARGET"
case "$ARC" in
    *.tar.bz2)   tar xjf "$ARC"     ;;
    *.tar.gz)    tar xzf "$ARC"     ;;
    *.bz2)       bunzip2 "$ARC"     ;;
    *.rar)       unrar e "$ARC"     ;;
    *.gz)        gunzip "$ARC"      ;;
    *.tar)       tar xf "$ARC"      ;;
    *.tbz2)      tar xjf "$ARC"     ;;
    *.tgz)       tar xzf "$ARC"     ;;
    *.zip)       unzip "$ARC"       ;;
    *.Z)         uncompress "$ARC"  ;;
    *.7z)        7z x "$ARC"        ;;
    *)           echo "'$ARC' cannot be extracted by $SCRIPTNAME" ;;
esac

我正在使用 Ranger FM。我試著讓它使用腳本 /usr/bin/extract.sh 打開所有存檔檔案。從終端運行腳本沒有問題,但當我嘗試在 Ranger 中使用它時,我得到:

/usr/bin/extract.sh - 標籤未定義。

我已將以下內容新增至我的 .config/ranger/rifle.conf :

標籤提取,ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, = /usr/bin/extract.sh -- "$@"

然而,它不起作用。我做錯了什麼?

先感謝您。

答案1

我已經解決了。對於任何有興趣的人來說,這是簡單的語法錯誤和必須的組合:

  1. 將名為 extract.sh 的腳本放在 /bin/extract 中(不含 .sh)

  2. 將別名加入 .zshrc:alias extract="/bin/extract"

  3. 在 .config/ranger/rifle.conf 中有以下幾行(語法錯誤:):

    ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz,有 aunpack = 提取“$@”

    ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip,有 tar,' flag f = extract "$@"

    標籤提取,ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz,= /bin/extract

相關內容