【Mac】 安装 Ranger

2023-05-16

一、使用 brew 命令安装

brew install ranger

插件
brew install libcaca highlight atool lynx w3m elinks poppler transmission mediainfo exiftool

二、配置支持图片查看

我是安装到(自己选择目录): /opt/software/ranger_imgcat/。
vim imgact

#!/bin/bash

# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
# only accepts ESC backslash for ST. We use TERM instead of TMUX because TERM
# gets passed through ssh.
function print_osc() {
    if [[ $TERM == screen* ]]; then
        printf "\033Ptmux;\033\033]"
    else
        printf "\033]"
    fi
}

# More of the tmux workaround described above.
function print_st() {
    if [[ $TERM == screen* ]]; then
        printf "\a\033\\"
    else
        printf "\a"
    fi
}

function load_version() {
    if [ -z ${IMGCAT_BASE64_VERSION+x} ]; then
        IMGCAT_BASE64_VERSION=$(base64 --version 2>&1)
        export IMGCAT_BASE64_VERSION
    fi
}

function b64_encode() {
    load_version
    if [[ $IMGCAT_BASE64_VERSION =~ GNU ]]; then
        # Disable line wrap
        base64 -w0
    else
        base64
    fi
}

function b64_decode() {
    load_version
    if [[ $IMGCAT_BASE64_VERSION =~ fourmilab ]]; then
        BASE64ARG=-d
    elif [[ $IMGCAT_BASE64_VERSION =~ GNU ]]; then
        BASE64ARG=-di
    else
        BASE64ARG=-D
    fi
    base64 $BASE64ARG
}

# print_image filename inline base64contents print_filename
#   filename: Filename to convey to client
#   inline: 0 or 1
#   base64contents: Base64-encoded contents
#   print_filename: If non-empty, print the filename
#                   before outputting the image
function print_image() {
    print_osc
    printf '1337;File='
    if [[ -n $1 ]]; then
        printf "name=%s;" "$(printf "%s" "$1" | b64_encode)"
    fi

    printf "%s" "$3" | b64_decode | wc -c | awk '{printf "size=%d",$1}'
    printf ";inline=%s" "$2"
    printf ":"
    printf "%s" "$3"
    print_st
    printf '\n'
    if [[ -n $4 ]]; then
        echo "$1"
    fi
}

function error() {
    echo "ERROR: $*" 1>&2
}

function show_help() {
    echo "Usage: imgcat [-p] filename ..." 1>&2
    echo "   or: cat filename | imgcat" 1>&2
}

function check_dependency() {
    if ! (builtin command -V "$1" >/dev/null 2>&1); then
        echo "imgcat: missing dependency: can't find $1" 1>&2
        exit 1
    fi
}

## Main

if [ -t 0 ]; then
    has_stdin=f
else
    has_stdin=t
fi

# Show help if no arguments and no stdin.
if [ $has_stdin = f ] && [ $# -eq 0 ]; then
    show_help
    exit
fi

check_dependency awk
check_dependency base64
check_dependency wc

# Look for command line flags.
while [ $# -gt 0 ]; do
    case "$1" in
    -h | --h | --help)
        show_help
        exit
        ;;
    -p | --p | --print)
        print_filename=1
        ;;
    -u | --u | --url)
        check_dependency curl
        encoded_image=$(curl -s "$2" | b64_encode) || (
            error "No such file or url $2"
            exit 2
        )
        has_stdin=f
        print_image "$2" 1 "$encoded_image" "$print_filename"
        set -- "${@:1:1}" "-u" "${@:3}"
        if [ "$#" -eq 2 ]; then
            exit
        fi
        ;;
    -*)
        error "Unknown option flag: $1"
        show_help
        exit 1
        ;;
    *)
        if [ -r "$1" ]; then
            has_stdin=f
            print_image "$1" 1 "$(b64_encode <"$1")" "$print_filename"
        else
            error "imgcat: $1: No such file or directory"
            exit 2
        fi
        ;;
    esac
    shift
done

# Read and print stdin
if [ $has_stdin = t ]; then
    print_image "" 1 "$(cat | b64_encode)" ""
fi

exit 0

把imgcat放到path中方便调用

# 设置可执行权限
chmod +x imgcat
# 复制到path之中
cp imgcat /usr/local/bin/

ranger --copy-config=all

日志如下:
creating: /Users/u/.config/ranger/rifle.conf
creating: /Users/u/.config/ranger/commands.py
creating: /Users/u/.config/ranger/commands_full.py
creating: /Users/u/.config/ranger/rc.conf
creating: /Users/u/.config/ranger/scope.sh

> Please note that configuration files may change as ranger evolves.
  It's completely up to you to keep them up to date.

> To stop ranger from loading both the default and your custom rc.conf,
  please set the environment variable RANGER_LOAD_DEFAULT_RC to FALSE.


图片预览效果如下

在这里插入图片描述

Ranger配置详情


cd ~/.config/ranger

-rw-r--r--  1 u  staff   2.7K 11 21 21:20 commands.py
-rwxr-xr-x  1 u  staff    61K 11 21 21:20 commands_full.py
-rw-r--r--  1 u  staff    24K 11 21 21:20 rc.conf
-rw-r--r--  1 u  staff    14K 11 21 21:20 rifle.conf
-rwxr-xr-x  1 u  staff    13K 11 21 21:20 scope.sh
  • commands.py:与以下命令一起启动的命令 :
  • commands_full.py:全套命令
  • rc.conf:配置和绑定
  • rifle.conf:文件关联(用于打开文件的程序)
  • scope.sh:负责各种文件预览

目前,对我们来说唯一重要的文件是rc.conf。在您喜欢的编辑器中将其打开,并更改以下两行,如下所示:
set preview_images false 修改成 set preview_images true
set preview_images_method w3m 修改成 set preview_images_method iterm2

配置环境变量

vim ~/.zshrc export RANGER_LOAD_DEFAULT_RC=FALSE

增加图标显示

git clone https://github.com/alexanderjeurissen/ranger_devicons ~/.config/ranger/plugins/ranger_devicons

echo "default_linemode devicons" >> $HOME/.config/ranger/rc.conf

显示边框线

set draw_borders true

效果如下
!](https://img-blog.csdnimg.cn/59153aa34a494f48b84d879b4e6f8299.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcV9oYW5Db2Rl,size_20,color_FFFFFF,t_70,g_se,x_16)


Ranger 常用命令

快捷键含义
H后退
L前进
gg跳到顶端
G跳到底端
ghgo home
gn新建标签
f查找
/搜索
g快速进入目录
yy复制
dd剪切
pp粘贴
delete删除
cw重命名
A在当前名称基础上重命名
I类似A,光标会跳到起始位置
Ctrl-f向下翻页
Ctrl-b向上翻页
m新建书签
`打开书签
um删除书签
gn /C-n新建标签
TAB / S-TAB切换标签
gc / C-w关闭标签
on /ob根据文件名进行排序
oc根据改变时间进行排序
os根据文件大小排序
ot根据后缀名进行排序
oa根据访问时间进行排序
om根据修改进行排序 Modify Time
zh/back显示隐藏文件

参考
https://blog.csdn.net/lxyoucan/article/details/115671189

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【Mac】 安装 Ranger 的相关文章

随机推荐