-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.zsh
57 lines (46 loc) · 1.5 KB
/
init.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env zsh
# vim:fdm=marker:foldlevel=0:sw=2:ts=2:sts=2
#
# Copyright 2019, laggardkernel and the zsh-thefuck contributors
# SPDX-License-Identifier: MIT
# Generate initialize thefuck with cache mechanism, which saves your time
# dramatically
#
# Authors:
# laggardkernel <[email protected]>
#
# Standardized $0 handling
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
# path=("${0:h}/bin" "${path[@]}")
# fpath=("${0:h}/functions" "${fpath[@]}")
if (( ! $+commands[thefuck] )); then
return 1
fi
# Set alias for thefuck
zstyle -s ':prezto:module:thefuck' alias \
'THEFUCK_ALIAS' || THEFUCK_ALIAS='fuck'
# Load custom location for runcom .zpreztorc
zstyle -s ':prezto:runcom' zpreztorc \
'PREZTO_RUNCOM_ZPREZTORC' || PREZTO_RUNCOM_ZPREZTORC="${SDOTDIR:-$HOME/.zpreztorc}"
# Register alias
init_args=(--alias "$THEFUCK_ALIAS")
cache_file="${TMPDIR:-/tmp}/thefuck-cache.$UID.zsh"
if [[ "${commands[thefuck]}" -nt "$cache_file" \
|| "$PREZTO_RUNCOM_ZPREZTORC" -nt "$cache_file" \
|| ! -s "$cache_file" ]]; then
# Cache init code.
thefuck "${init_args[@]}" >| "$cache_file" 2>/dev/null
fi
source "$cache_file"
unset cache_file init_args THEFUCK_ALIAS
fuck-command-line() {
local FUCK="$(THEFUCK_REQUIRE_CONFIRMATION=0 thefuck $(fc -ln -1 | tail -n 1) 2> /dev/null)"
[[ -z $FUCK ]] && echo -n -e "\a" && return
BUFFER=$FUCK
zle end-of-line
}
zle -N fuck-command-line
if zstyle -T ':prezto:module:thefuck' bindkey; then
# Defined shortcut keys: [Esc] [Esc]
bindkey "\e\e" fuck-command-line
fi