cd - | Previous directory |
cd ~ | Home directory |
.. | Parent directory (Oh My Zsh) |
... | Two directories up |
take dirname | mkdir + cd |
d | List recent directories |
1-9 | cd to directory from d list |
Ctrl+A | Move to start of line |
Ctrl+E | Move to end of line |
Ctrl+U | Delete line before cursor |
Ctrl+K | Delete line after cursor |
Ctrl+W | Delete word before cursor |
Ctrl+R | Search command history |
Ctrl+L | Clear screen |
Tab | Auto-complete |
Tab Tab | List all completions |
Ctrl+Z | Suspend process |
!! | Last command |
!$ | Last argument |
history | Show history |
history -10 | Last 10 commands |
history | grep pattern | Search history |
!! | Run last command |
!n | Run command n |
!-n | Run n commands ago |
!string | Run last command starting with string |
!?string | Run last command containing string |
^old^new | Replace in last command |
fc | Edit last command in editor |
# In .zshrc
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt SHARE_HISTORY # Share across sessions
setopt HIST_IGNORE_DUPS # Ignore duplicates
setopt HIST_IGNORE_SPACE # Ignore if starts with space
setopt HIST_REDUCE_BLANKS # Remove extra blanks
setopt HIST_VERIFY # Show before executing * # Any string
? # Any single char
[abc] # Any of a, b, c
[a-z] # Range
[^abc] # Not a, b, c **/* # Recursive
**/*.js # All .js files recursively
*.{js,ts} # .js or .ts files
*~*.bak # All except .bak
*(.) # Regular files only
*(/) # Directories only
*(@) # Symbolic links only ls *(.) # Files only
ls *(/) # Directories only
ls *(.m-7) # Modified in last week
ls *(.L+100) # Larger than 100 bytes
ls *(.om[1,10]) # 10 most recent files setopt EXTENDED_GLOB alias ll='ls -la'
alias ..='cd ..'
alias ...='cd ../..' alias -g G='| grep'
alias -g L='| less'
alias -g H='| head'
alias -g T='| tail'
alias -g NUL='> /dev/null 2>&1'
# Usage: ls G pattern alias -s txt=vim
alias -s py=python
alias -s json=code
alias -s md=code
# Usage: file.txt (opens in vim) alias # List all
alias name # Show specific
unalias name # Remove alias alias g='git'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline'
alias gs='git status'
alias gd='git diff'
alias gco='git checkout' alias ~='cd ~'
alias -- -='cd -'
alias 1='cd -'
alias 2='cd -2' alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i' function greet() {
echo "Hello, $1!"
}
# Usage: greet World function mkcd() {
mkdir -p "$1" && cd "$1"
} function extract() {
case $1 in
*.tar.gz) tar xzf $1 ;;
*.tar.bz2) tar xjf $1 ;;
*.tar.xz) tar xJf $1 ;;
*.zip) unzip $1 ;;
*.gz) gunzip $1 ;;
*.rar) unrar x $1 ;;
*) echo "Unknown format" ;;
esac
} function replace() {
find . -type f -name "$1" -exec \
sed -i "s/$2/$3/g" {} +
} omz update | Update Oh My Zsh |
omz reload | Reload configuration |
omz changelog | Show changelog |
omz plugin list | List plugins |
omz plugin info plugin | Plugin info |
omz theme list | List themes |
omz theme set theme | Set theme |
# Path to oh-my-zsh
export ZSH="$HOME/.oh-my-zsh"
# Theme
ZSH_THEME="robbyrussell"
# Plugins
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
z
docker
kubectl
)
source $ZSH/oh-my-zsh.sh # Built-in
git # Git aliases and functions
z # Jump to directories
docker # Docker completions
kubectl # Kubectl completions
npm # npm completions
# External
zsh-autosuggestions
zsh-syntax-highlighting
zsh-completions setopt AUTO_CD # cd without typing cd
setopt CORRECT # Command correction
setopt CORRECT_ALL # Argument correction
setopt NO_CASE_GLOB # Case insensitive glob
setopt GLOB_DOTS # Include dotfiles
setopt EXTENDED_GLOB # Extended globbing
setopt NUMERIC_GLOB_SORT # Sort numerically
setopt AUTO_PUSHD # Auto push directories
setopt PUSHD_IGNORE_DUPS # No duplicate pushd autoload -Uz compinit && compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:git:*' formats '(%b)'
PROMPT='%F{green}%n@%m%f:%F{blue}%~%f ${vcs_info_msg_0_}
%# ' # Add to PATH
export PATH="$HOME/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
# Environment variables
export EDITOR="vim"
export VISUAL="code"
export LANG="en_US.UTF-8" # Load order:
# 1. ~/.zshenv - Always
# 2. ~/.zprofile - Login shell
# 3. ~/.zshrc - Interactive shell
# 4. ~/.zlogin - Login shell
# 5. ~/.zlogout - Login shell logout