zsh-lsd and gum

2026-10-11 16:18

If you want to see similar things, you can check out my full zsh setup.

https://codeberg.org/hyzi/hyzi/src/branch/main/zsh

Scroll down; there is a 'copy' button on the right.

#////
#Details

#pkg i lsd
#pkg i gum

#alias and fix pwd termux.
p() { print -P '%F{5}%~%f' }

#I use the 'i2'+'i' alias by my keyboard layout. Just change the aliases to ls.
#ls -l
i() {
    local dir=${PWD/#"$HOME"}
    if [[ $dir != "$PWD" ]]; then dir="~$dir"; fi
    #Want to add an extra? (pwd, pwd and date..)
    #>>pwd
    #local header="\033[1;35m$dir\033[0m"
    #<<
    #>>pwd and date
    #local header="\033[1;31m$(date '+%d-%m-%y/%H:%M:%S')\033[0m\n\033[1;35m$dir\033[0m"
    #<<
    local box_width=$((COLUMNS - 4))
    local out

    out=$(script -q -c "lsd -l --color=always --icon=always --blocks name,size,date --date '+%d-%m-%y/%H:%M:%S' $*" /dev/null | tr -d '\r' | sed -E $'s/([0-9])(\x1b\\[[0-9;]*m)* (\x1b\\[[0-9;]*m)*([KMGT]B)/\\1\\2\\3\\4/g')

    if [[ -n "$out" ]]; then
        printf '%b\n\n%s' "$header" "$out" | gum style --border rounded --padding "1 2" --width "$box_width" --no-strip-ansi
    fi
}

#ls -1 (normal)
#Look! Instead of using `lsd -1` (which shows just one line), you can use `lsd -X` or `lsd -a`; however, you have to zoom out so it doesn't look too cramped.
i2() {
    local dir=${PWD/#"$HOME"}
    if [[ $dir != "$PWD" ]]; then dir="~$dir"; fi
    #Want to add an extra? (pwd, pwd and date..)
    #>>pwd
    #local header="\033[1;35m$dir\033[0m"
    #<<
    #>>pwd and date
    #local header="\033[1;31m$(date '+%d-%m-%y/%H:%M:%S')\033[0m\n\033[1;35m$dir\033[0m"
    #<<
    local box_width=$((COLUMNS - 4))
    local out

    out=$(script -q -c "lsd -1 --color=always --icon=always $*" /dev/null | tr -d '\r')

    if [[ -n "$out" ]]; then
        printf '%b\n\n%s' "$header" "$out" | gum style --border rounded --padding "1 2" --width "$box_width" --no-strip-ansi
    fi
}

#Termux-copy
#You need the Termux API!

#example: ii gpg-key.txt
ii() {
  if [[ ! -r "$1" ]]; then
    print -u2 "ii: Error. '$1'"
    return 1
  fi
  termux-clipboard-set < "$1"
  print -u2 "Copy in the clipboard!"
}
#////

_