lf文件管理器配置对比 C

wiki case

lf filemanager 配置对比 C

18. profile 命令

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

写法对比:

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

优势说明:

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

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

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

写法对比:

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

优势说明:

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

20. cd-usermedia 命令

按键绑定: gi

写法对比:

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

优势说明:

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

按键绑定: gL

写法对比:

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

优势说明:

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

22. fzf-edit 命令

按键绑定: fe

写法对比:

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

优势说明:

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

23. fzf-file 命令

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

写法对比:

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

优势说明:

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

24. fzf-folder 命令

按键绑定: fd

写法对比:

  • lumesh: 使用变量赋值和条件判断
select = $lf_user_wheel fd --type d '.' -d 5 | fzf --preview 'ls {}'
if $select {
lf -remote `send $id cd $select`
}
  • bash: 使用命令替换和逻辑运算符
select=$($lf_user_wheel fd --type d . -d 5 | fzf --preview 'ls {}') \
&& lf -remote "send $id cd $select" \
|| 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: 使用现代化输出和确认
println '=====DELETE====='.red().bold() $fx '================'.red()
if Ui.confirm('Delete these files [y/n]:'){
$lf_user_wheel rm -rf $fx.lines()
}
  • bash: 使用传统echo和read
echo -e "=====\033[31mDELETE\033[0m====="
echo "$fx"
echo "================"
printf "Delete %d files? [y/N]" $(wc -w <<< $fx)
read ans
if [ "$ans" = "y" ]; then
echo $fx | xargs $lf_user_wheel rm -rf
fi

优势说明:

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

27. trash 命令

按键绑定: dd

写法对比:

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

优势说明:

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

按键绑定: pL

写法对比:

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

优势说明:

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

29. paste-rsync 命令

按键绑定: pr

写法对比:

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

优势说明:

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

30. paste-to/paste-from 命令

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

写法对比:

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

优势说明:

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

完整功能对比总结

高级特性对比

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

代码维护性

Lumesh优势:

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

Bash优势:

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

Notes

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

阅读更多: