thefuck.plugin.zsh
743 bytes
1if [[ -z $commands[thefuck] ]]; then
2 echo 'thefuck is not installed, you should "pip install thefuck" or "brew install thefuck" first.'
3 echo 'See https://github.com/nvbn/thefuck#installation'
4 return 1
5fi
6
7# Register alias
8[[ ! -a "$ZSH_CACHE_DIR/thefuck" ]] && thefuck --alias > "$ZSH_CACHE_DIR/thefuck"
9source "$ZSH_CACHE_DIR/thefuck"
10
11fuck-command-line() {
12 local FUCK="$(THEFUCK_REQUIRE_CONFIRMATION=0 thefuck $(fc -ln -1 | tail -n 1) 2> /dev/null)"
13 [[ -z $FUCK ]] && echo -n -e "\a" && return
14 BUFFER=$FUCK
15 zle end-of-line
16}
17zle -N fuck-command-line
18# Defined shortcut keys: [Esc] [Esc]
19bindkey -M emacs '\e\e' fuck-command-line
20bindkey -M vicmd '\e\e' fuck-command-line
21bindkey -M viins '\e\e' fuck-command-line