10 Zsh Hacks
Video: 10 Zsh hacks I wish I knew about sooner
By Dreams of Code [http://www.youtube.com/@dreamsofcode](http://www.youtube.com/@dreamsofcode)
1 When typing long commands
- Edit command buffer
C-x C-elike bash
2 When accidentally deleting more than wanted
- C-_ will undo last action
- zsh has a redo action
3
- magic-space
sudo !!executes previous command from history- caveat: we want to see what will be executed (like histverify)
- magic-space will expand history
4
- chpwd hool: executes a command when we change dir
- example, in nixos will open a nix shell when cd'ing in
- example, when cd'ing into a virtual env
- can only define one chpwd hook
5
autoload -Uz add-zsh-hookadd-zsh-hook chpwd nix_hookadd-zsh-hook chpwd python_hookadd-zsh-hook chpwd function() { ... }
6
- auto open file
- suffix aliases -- run based on suffix
alias -s go='$EDITOR'
7
- global aliases, can be used anywhere in a command
alias -g NE='2>/dev/null'du / NE-- expands todu / 2>/dev/null- define these with uppercase names
8
- zmv
- autoload zmv
zmv '(*).log' '$1.txt'zmv -W '*.log' '*.txt'zmv -n ...does dry runzmv -iwill prompt for each change
9
- bookmarking locations
hash -d yt=~/Projects/youtubecd ~yt
10
- zoxide
11
- customising actions for command line buffer
- widgets: functions that perform actions
zle= zsh line editor
12
- configure hotkeys to insert into command buffer
bindkey -s '^Xgc' 'git commit -m ""\C-b'