跳过正文
  1. Lumesh 用例/
  2. Lumesh 用例 -- lf/

lf文件管理器配置对比 C

2033 字·5 分钟
目录

lf filemanager 配置对比 C

18. profile 命令
#

按键绑定: z2 (extra), z3 (disk), z4 (convert), z5 (develop), z6 (auto-redraw), z7 (tarzip)

写法对比:

  • lumesh: 使用字符串插值和数组访问
1  lf -remote `send $id source ~/.config/lf/profiles/${$argv[0]}`
  • bash:
1  lf -remote "send $id source ~/.config/lf/profiles/$1"

优势说明:

  • lumesh: 支持配置文件切换功能,字符串插值语法简洁
  • bash: 字符串插值语法简洁

19. zox/z 命令 (zoxide集成)
#

按键绑定: ; (push :zox), gz (push :zox)

写法对比:

  • lumesh: 使用条件表达式和函数调用
1if len($argv) {
2    let select=zoxide query --exclude (pwd()) $argv ?: lf -remote "send $id echo Cancelled."
3    lf -remote `send $id cd $select`
4}
  • bash: 使用条件判断和命令替换
1if [ -n "$@" ]; then
2    select="$(zoxide query --exclude $PWD $@)" \
3    && lf -remote "send $id cd $select" \
4    || lf -remote "send $id echo Cancelled."
5fi

优势说明:

  • lumesh: len()函数语义清晰,pwd()函数调用直观
  • bash: 逻辑运算符链式调用标准,错误处理明确

20. cd-usermedia 命令
#

按键绑定: gi

写法对比:

  • lumesh: 使用环境变量
1lf -remote `send $id cd $XDG_RUNTIME_DIR/media`
2# or
3lf -remote `send $id cd /run/user/${id -u}/media`
  • bash: 使用命令替换
1lf -remote "send $id cd /run/user/$(id -u)/media"

优势说明:

  • lumesh: 直接使用环境变量,更符合XDG规范
  • bash: 动态获取用户ID,兼容性更好

21. follow-link 命令#

按键绑定: gL

写法对比:

  • lumesh: 使用变量赋值
1lf -remote `send $id select ${readlink $f}`
  • bash: 使用命令替换
1lf -remote "send ${id} select '$(readlink $f)'"

优势说明:

  • lumesh: 变量赋值语法清晰,可读性好
  • bash: 内联命令替换紧凑,减少变量使用

22. fzf-edit 命令
#

按键绑定: fe

写法对比:

  • lumesh: 简洁的命令调用
1hx (fzf)
  • bash: 使用命令替换
1hx $(fzf)

优势说明:

  • lumesh: 括号语法更现代化
  • bash: 传统命令替换语法标准

23. fzf-file 命令
#

按键绑定: ff<space>, fft (txt), ffg (gz), ffm (md), ffs (sh), ffy (py)

写法对比:

  • lumesh: 使用三元运算符和字符串连接
1let ext = len($argv) ? '-e'+$argv[0] : ''
2let selected = fd --type 'file' $ext '-S-50k' | fzf --preview "~/.config/lf/previewer {} 30 18"
  • bash: 使用条件判断和变量赋值
1[ -n ${1:-''} ] && E="-e$1" || E='-S-50k'
2select=$($lf_user_wheel fd --type f $E | fzf --preview "~/.config/lf/previewer {} 30 18")

优势说明:

  • lumesh: 三元运算符简洁,字符串连接直观
  • bash: 参数展开语法灵活,逻辑运算符标准

24. fzf-folder 命令
#

按键绑定: fd

写法对比:

  • lumesh: 使用变量赋值和条件判断
1select = $lf_user_wheel fd --type d '.' -d 5 | fzf --preview 'ls {}'
2if $select {
3    lf -remote `send $id cd $select`
4}
  • bash: 使用命令替换和逻辑运算符
1select=$($lf_user_wheel fd --type d . -d 5 | fzf --preview 'ls {}') \
2&& lf -remote "send $id cd $select" \
3|| lf -remote "send $id echo Cancelled."

优势说明:

  • lumesh: 变量赋值语法清晰,无需显式错误处理
  • bash: 逻辑运算符链式调用,错误处理明确

25. filter系列命令
#

按键绑定: \\ (filter), F<space> (filter), Ft (.txt), Fp (.png), Fj (.jpg), Fa (.mp3), Fv (.mp4), Fw (.docx), Fx (.xlsx), Fg (.gz), Fz (.zip), Fm (.md), Fs (.sh), Fy (.py), Fc (清除)

写法对比: 写法一致

26. delete 命令
#

按键绑定: dD

写法对比:

  • lumesh: 使用现代化输出和确认
1println '=====DELETE====='.red().bold() $fx '================'.red()
2if Ui.confirm('Delete these files [y/n]:'){
3    $lf_user_wheel rm -rf $fx.lines()
4}
  • bash: 使用传统echo和read
1echo -e "=====\033[31mDELETE\033[0m====="
2echo "$fx"
3echo "================"
4printf "Delete %d files? [y/N]" $(wc -w <<< $fx)
5read ans
6if [ "$ans" = "y" ]; then
7    echo $fx | xargs $lf_user_wheel rm -rf
8fi

优势说明:

  • lumesh: 内置颜色方法和确认函数,语法更现代化
  • bash: ANSI转义序列直接控制,wc统计文件数量精确

27. trash 命令
#

按键绑定: dd

写法对比:

  • lumesh: 使用内置函数和字符串插值
1let files = $fx.lines() | List.map(Fs.base_name)
2let ans = read `Trash: $files [y/N]`
3if $ans == 'y' {
4    mkdir -p /tmp/.trash
5    $lf_user_wheel mv -- $fx.lines() /tmp/.trash/
6    print 'Trash complete!'
7}
  • bash: 使用传统工具和命令替换
1printf "Temparay Trash %d files? [y/N]" $(wc -w <<< $fx)
2read ans
3if [ "$ans" = "y" ]; then
4    [ -d "/tmp/.trash" ] || mkdir -p /tmp/.trash
5    echo $fx | xargs $lf_user_wheel rm -rf
6    echo "Trash complete!"
7fi

优势说明:

  • lumesh: 函数式处理文件列表,字符串插值显示文件名
  • bash: 文件数量统计准确,条件创建目录简洁

28. link 命令#

按键绑定: pL

写法对比:

  • lumesh: 使用文件系统函数和循环
 1let load= Fs.read ~/.local/share/lf/files | .lines()
 2let files=$load.drop(1)
 3let base_names = $files.map(Fs.base_name)
 4for filex in $base_names{
 5    if (Fs.exists Fs.join('.',$filex)) {
 6        eprint $filex 'Already exists!'
 7        exit 1
 8    }
 9}
10match $mode {
11    copy => $lf_user_wheel ln -s -- $files '.'
12    move => $lf_user_wheel ln -- $files '.'
13}
  • bash: 使用sed和basename
 1load=$(cat ~/.local/share/lf/files)
 2mode=$(echo "$load" | sed -n '1p')
 3list=$(echo "$load" | sed '1d')
 4if [ "$mode" = 'copy' ]; then
 5    $lf_user_wheel ln -s $list .
 6elif [ "$mode" = 'move' ]; then
 7    $lf_user_wheel ln $list .
 8fi
 9fn=$(basename -a -- $list)
10for file in "$fn";do
11    lf -remote "send $id :select $file; tag @"
12done

优势说明:

  • lumesh: 内置文件系统函数功能丰富,存在性检查类型安全
  • bash: sed文本处理高效,basename批量处理标准

29. paste-rsync 命令
#

按键绑定: pr

写法对比:

  • lumesh: 使用模式匹配
 1let load= Fs.read ~/.local/share/lf/files | .lines()
 2let mode=$load.at(0)
 3let files=$load.drop(1)
 4match $mode{
 5    copy => {
 6        $lf_user_wheel rsync -ar --ignore-existing --info=progress2 -- $files '.'
 7    }
 8    move => {
 9        $lf_user_wheel rsync -ar --remove-source-files --ignore-existing --info=progress2 -- $files '.'
10    }
11}
  • bash: 使用case语句和管道处理
1set -- $(cat ~/.local/share/lf/files)
2mode="${1:-}"
3shift
4case "$mode" in
5copy) $lf_user_wheel rsync -av --ignore-existing --progress -- "$@" . | stdbuf -i0 -o0 -e0 tr '\r' '\n' | while IFS= read -r line; do
6    lf -remote "send $id echo $line"
7done ;;
8move) $lf_user_wheel mv -n -- "$@" . ;;
9esac

优势说明:

  • lumesh: 模式匹配语法现代化,数组操作直观
  • bash: 位置参数处理灵活,实时进度显示完善

30. paste-to/paste-from 命令
#

按键绑定: pt (paste-to), pf (paste-from)

写法对比:

  • lumesh: 使用错误处理运算符和条件判断
1let dest = $argv[0] ?: {print 'Cancelled';exit 0}
2$lf_user_wheel cp -r --backup=numbered -i -- $fx $dest
3if Fs.is_dir($dest){
4    let base_names = $fx.lines() | .map(Fs.base_name) | .join("\n")
5    lf -remote `send $id :unselect; cd $dest; select $base_names`
6}
  • bash: 使用参数展开和条件判断
1if [ -n "${1:-}" ]; then
2    $lf_user_wheel cp -r --backup=numbered -i -- $fx $1
3    [ -d "$1" ] \
4    && lf -remote "send $id :unselect; cd $1; select $(basename $fx)" \
5    || lf -remote "send $id :unselect; select $1; "
6else
7    echo "Cancelled."
8fi

优势说明:

  • lumesh: 错误处理运算符简洁,文件系统函数类型安全
  • bash: 参数展开标准,逻辑运算符链式调用清晰

完整功能对比总结
#

高级特性对比
#

功能类别Lumesh特色Bash特色
错误处理?:, ?., ?! 运算符&&, || 逻辑运算符
数据处理链式调用、函数式编程管道、文本处理工具
文件操作内置Fs模块、类型安全标准Unix工具
用户交互Ui.confirm、Ui.pickread、fzf
字符串处理内置方法、插值cut、sed、awk

代码维护性
#

Lumesh优势:

  • 现代化语法提高可读性
  • 类型安全减少运行时错误
  • 统一的API设计
  • 内置错误处理机制

Bash优势:

  • 广泛的社区支持
  • 丰富的文档资源

Notes
#

通过对所有命令的完整对比,可以看出Lumesh在语法现代化、类型安全和代码可读性方面具有明显优势,而Bash在兼容性方面更加成熟。两种实现都能完成相同的文件管理任务,选择主要取决于用户对现代化语法的偏好程度和对传统Unix工具的依赖程度。

阅读更多:

相关文章