The Final Zsh Lesson: Advanced Globs, Expansion & ZLE — Tutorial #30
Video: The Final Zsh Lesson: Advanced Globs, Expansion & ZLE — Tutorial #30 by Taught by Celeste AI - AI Coding Coach
Watch full page →The Final Zsh Lesson: Advanced Globs, Expansion & ZLE
This lesson dives into Zsh's most powerful features, including extended globbing with qualifiers, advanced brace and parameter expansions, and full shell customization using prompts, ZLE widgets, and completions. These features enable precise file matching, dynamic variable manipulation, and a highly personalized command line experience.
Code
# Extended globbing examples:
# List all .sh files recursively
print **/*.sh
# Regular files only
print *(.)
# Directories only
print *(/)
# Symlinks only
print *(@)
# Files larger than 10KB
print *(Lk+10)
# Files modified in the last 24 hours
print *(mh-24)
# 3 newest regular files, sorted by modification time
print *(.om[1,3])
# All files except *.log
print ^*.log(.)
# Brace expansions:
# Sequence from 1 to 10
echo {1..10}
# Cross product expansion
echo {web,api}_{prod,staging}
# Parameter expansions:
var="hello"
# Uppercase the value of var
echo ${(U)var}
# Split PATH on colon delimiter into array
print -l ${(s/:/)PATH}
# Join array elements with commas
arr=(one two three)
echo ${(j/,/)arr}
# Shell options for enhanced globbing
setopt NO_CASE_GLOB # Case-insensitive globbing
setopt NULL_GLOB # No error if glob matches nothing
# Prompt customization with prompt escapes
print -P '%n@%m %~' # Shows username@hostname current_directory
# Load Git branch info for prompt
autoload -Uz vcs_info
zstyle ':vcs_info:git:*' formats '(%b)'
precmd() { vcs_info }
PS1='%n@%m %~ ${vcs_info_msg_0_} %# '
Key Points
- Extended glob qualifiers allow precise filtering of files by type, size, modification time, and sorting.
- Brace expansion supports sequences and cross products for generating multiple strings efficiently.
- Parameter expansion flags enable transformations like uppercasing, splitting, and joining arrays.
- Shell options like NO_CASE_GLOB and NULL_GLOB improve globbing flexibility and error handling.
- Zsh Line Editor (ZLE) widgets and vcs_info integration enable powerful prompt customization with dynamic Git branch info.