```ythead 10 Zsh Hacks Dreams of Code [http://www.youtube.com/@dreamsofcode](http://www.youtube.com/@dreamsofcode) 10 Zsh hacks I wish I knew about sooner https://www.youtube.com/watch?v=3fVAtaGhUyU ``` ## 1 When typing long commands * Edit command buffer `C-x C-e` like 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-hook` * `add-zsh-hook chpwd nix_hook` * `add-zsh-hook chpwd python_hook` * `add-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 to `du / 2>/dev/null` * define these with uppercase names ## 8 * zmv * autoload zmv * `zmv '(*).log' '$1.txt'` * `zmv -W '*.log' '*.txt'` * `zmv -n ...` does dry run * `zmv -i` will prompt for each change ## 9 * bookmarking locations * `hash -d yt=~/Projects/youtube` * `cd ~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'`