Skip to main content
  1. Lumesh Cases/
  2. Lumesh Cases -- lf/

lf File Manager Configuration Comparison B

916 words·5 mins
Table of Contents

lf File Manager Configuration Comparison B
#

10. extract-to Command
#

Key Binding: ah (current directory), ax (/tmp/), aX (custom path)

Code Comparison:

  • Lumesh: Uses regex matching and built-in file functions
1if (Regex.match '\.([gb7xs]z|t[gbx]z|zip|zst|bz2|lz4|lzma|tar|rar|br)$' $f) {
2    let base_name = Fs.base_name(True,$f).first()
3    let npath = Fs.join($dest,$base_name)
4    $lf_user_wheel ouch -q decompress --dir $npath $f
5}
  • Bash: Uses case statement and string processing
1case "$f" in
2*.[gb7xs]z|*.t[gbx]z|*.zip|*.tar|*.bz2|*.lzma|*.lz4|*.zst|*.rar)
3    $lf_user_wheel ouch d -qd $1 $f && \
4    fn=$(basename "$f" | cut -d. -f1) && \
5    lf -remote "send $id :cd $1; select $fn && tag ^"
6    ;;
7esac

Advantages:

  • Lumesh: Regex is more flexible, built-in path operation functions are type-safe
  • Bash: Case statement has better performance, pattern matching is concise and intuitive

11. compress-to Command
#

Key Binding: ac (/tmp/compress)

Code Comparison:

  • Lumesh: Uses string methods and conditional expressions
1if $dest.ends_with('/'){
2    let base_name = Fs.base_name($sources.first())
3    let dest_file = Fs.join($dest, $base_name)
4}else{
5    let base_name = Fs.base_name($dest)
6    let dest_file = $dest
7}
  • Bash: Uses test command and string operations
1if test "$(echo $1 | grep '/$')" -o -d "$1" ; then
2    name="$(basename -a $fx | head -n1)"
3    dir=$(dirname $1$name)
4else
5    name=$(basename "$1")
6    dir=$(dirname $1)
7fi

Advantages:

  • Lumesh: String methods are more intuitive, conditional expressions are concise
  • Bash: Test command is standardized, dirname/basename tools are mature

12. diff Series Commands
#

Key Binding: df (diff), dt (delta), dm (md5 comparison)

Code Comparison:

  • Lumesh: Uses array indexing and ternary operator
1let files = $fs.lines()
2if len($files)>1 {
3    let lines = $lf_user_wheel md5sum $files[0] $files[1] | .lines()
4    let s1 = $lines[0] | .words() | .at(0)
5    let s2 = $lines[1] | .words() | .at(0)
6    print $s1==$s2 ? 'Same' : 'Differ'
7}
  • Bash: Uses positional parameters and conditional checks
 1set -- $fs
 2if [ "$#" -gt 1 ]; then
 3    sum1=$(md5sum $1 |cut -d' ' -f1)
 4    sum2=$(md5sum $2 |cut -d' ' -f1)
 5    if [ "$sum1" = "$sum2" ]; then
 6        echo 'Same'
 7    else
 8        echo 'Differ'
 9    fi
10fi

Advantages:

  • Lumesh: Array operations are intuitive, method chaining is concise, ternary operator is elegant, conditional statements are more straightforward
  • Bash: Positional parameters are flexible, cut command is efficient, conditional checks are clear

13. check-sum Command
#

Key Binding: dc

Code Comparison:

  • Lumesh: Uses pattern matching
1let ext_name = Fs.base_name(True, $fx).last()
2match $ext_name {
3    sha512 => sha512sum -c $fx
4    sha256 => sha256sum -c $fx
5    sha1 => sha1sum -c $fx
6    md5 => md5sum -c $fx
7    _ => shasum $fx
8}
  • Bash: Uses case statement
1case "$fx" in
2*.sha256) sha256sum -c "$fx" ;;
3*.sha512) sha512sum -c "$fx" ;;
4*.sha1) sha1sum -c "$fx" ;;
5*.md5) md5sum -c "$fx" ;;
6*) sha256sum "$fx" ;;
7esac

Advantages:

  • Lumesh: Powerful pattern matching, type-safe file extension extraction. Also supports regex and wildcard patterns.
  • Bash: Case statement has excellent performance, wildcard matching is simple and direct

14. cmus-play Command
#

Key Binding: Om

Code Comparison:

  • Lumesh: Uses conditional expressions and error handling
1pgrep -x cmus ?: foot cmus
2cmus-remote -c -q $fx
3cmus-remote -p -q
  • Bash: Uses conditional checks and logical operators
1if [ -z "$(pgrep -x cmus)" ]; then
2    foot cmus && cmus-remote -c -q "$fx" && cmus-remote -p
3else
4    cmus-remote -c -q "$fx"
5    cmus-remote -p
6fi

Advantages:

  • Lumesh: Error handling operator ?: is concise, code is more compact
  • Bash: Conditional logic is clear, logical operator && allows for standard chaining

15. umount-dev Command
#

Key Binding: mu

Code Comparison:

  • Lumesh: Uses structured data and optional chaining
1let sel = lsblk -rno 'name,type,size,mountpoint,label,fstype' | Into.table([name,'type',size,mountpoint,label,fstype]) \
2| where(mountpoint != None)
3| Ui.pick() ?.
4if sel {
5    if $PWD ~: $sel.mountpoint {
6        lf -remote `send $id cd /tmp`
7    }
8    $lf_user_wheel umount $sel.mountpoint
9}
  • Bash: Uses awk and string processing
1x=$(mount | awk '$1 ~ /^\/dev/ && $3 !~/^\/(home|boot|var)?$/ {sub(/^\/dev\//, "", $1); print $1,$5,$3}' | fzf --prompt='choose to UMount: ' --preview='' | awk '{print $3}')
2if [ -n "$x" ]; then
3    [ -n $(echo $PWD | grep "^$x/") ] && dir=$(dirname $x) && lf -remote "send $id cd $dir"
4    $lf_user_wheel umount "$x"
5fi

Advantages:

  • Lumesh: Powerful structured data processing, ?. elegantly ignores unselected errors, field access is type-safe
  • Bash: Awk regex processing is flexible, pipeline combinations are efficient, string matching is mature

16. on-cd Command
#

Key Binding: None (automatically triggered)

Code Comparison:

  • Lumesh: Uses system functions
1Sys.print_tty `\033]0;lf $PWD\007`
  • Bash: Uses printf redirection
1printf "\033]0;lf $PWD\007" > /dev/tty

Advantages:

  • Lumesh: System function encapsulation is safer, API is clearer
  • Bash: Directly operating device files allows for more precise control

17. drag Series Commands
#

Key Binding: di (drag in), do (drag out)

Code Comparison:

  • Lumesh: Uses built-in file functions
1dest=dragon-drop --target -x -p
2cp $dest .
3let base_name = Fs.base_name($dest)
4lf -remote `send $id :select ${base_name}; tag =`
  • Bash: Uses basename command
1dest=$(dragon-drop --target -x -p)
2cp $dest .
3lf -remote "send $id :select $(basename "$dest"); tag ="

Advantages:

  • Lumesh: Built-in file functions are type-safe, variable scope is clear
  • Bash: Basename command is standardized, command substitution is direct

Complete Comparison Summary
#

Syntax Feature Comparison
#

FeatureLumeshBash
Conditional Expressioncondition ? true_val : false_val`[ condition ] && true_cmd
Pattern Matchingmatch expr { pattern => action }case expr in pattern) action ;;
Array Operations.lines(), .map(), .filter()awk, cut, sed
Error Handlingcmd ?: default`cmd
String Methods.split(), .join(), .ends_with()cut, grep, test
File OperationsFs.base_name(), Fs.join()basename, dirname

Continue reading:

Related