-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathautocomplete.zsh
122 lines (107 loc) · 3.91 KB
/
autocomplete.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/zsh
# IMPORTANT: We MUST use MODIFIED_PATH (see notes in ~/.zshrc).
# Also, other tools like `curl`, `sh` etc can't be found otherwise.
export PATH="$MODIFIED_PATH"
# Setup fpath for brew-installed completions, if available
#
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
fpath=($(brew --prefix)/share/zsh/site-functions $fpath)
fi
# Bash Autocomplete Helpers
#
autoload -U +X bashcompinit && bashcompinit
# Zsh Autocomplete Helpers
#
# Extended with help from fzf-tab (https://github.com/Aloxaf/fzf-tab)
#
autoload -U compinit; compinit
dir_zsh="$HOME/.zsh"
# Install integralist/zsh-cli-json-parser
# For custom CLI autocomplete (for when a CLI doesn't provide autocomplete itself)
#
path_json_parser="$dir_zsh/get_cli_options.zsh"
if ! test -f $path_json_parser; then
curl -so $path_json_parser https://raw.githubusercontent.com/Integralist/zsh-cli-json-parser/refs/heads/main/get_cli_options.zsh
chmod +x $path_json_parser
fi
source $path_json_parser
# fzf-tab
#
dir_fzf_tab="$dir_zsh/fzf-tab"
path_fzf_tab="$dir_fzf_tab/fzf-tab.plugin.zsh"
if test -f $path_fzf_tab; then
source $path_fzf_tab
else
mkdir -p "$dir_zsh"
git clone https://github.com/Aloxaf/fzf-tab $dir_fzf_tab
source $path_fzf_tab
fi
# The following are common configurations for fzf-tab
# https://github.com/Aloxaf/fzf-tab?tab=readme-ov-file#configure
#
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# force zsh not to show completion menu, which allows fzf-tab to capture the unambiguous prefix
zstyle ':completion:*' menu no
# preview directory's content with eza when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# custom fzf flags as it doesn't follow FZF_DEFAULT_OPTS by default
zstyle ':fzf-tab:*' fzf-flags --style=full --color=fg:1,fg+:2 --bind=tab:accept
# switch group using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'
# Git Autocomplete
#
# IMPORTANT: The bash completion script is required even when using zsh shell.
#
path_zsh_git_completion="$dir_zsh/_git"
if ! test -f $path_zsh_git_completion; then
curl -so $path_zsh_git_completion https://raw.githubusercontent.com/git/git/refs/heads/master/contrib/completion/git-completion.zsh
chmod +x $path_zsh_git_completion
fi
path_bash_git_completion="$HOME/git-completion.bash"
if ! test -f $path_bash_git_completion; then
curl -so $path_bash_git_completion https://raw.githubusercontent.com/git/git/refs/heads/master/contrib/completion/git-completion.bash
chmod +x $path_bash_git_completion
fi
# Rust Autocomplete
#
path_rustup_completion="$dir_zsh/_rustup"
if ! test -f $path_rustup_completion; then
rustup completions zsh > $path_rustup_completion
fi
source "$path_rustup_completion"
path_cargo_completion="$dir_zsh/_cargo"
if ! test -f $path_cargo_completion; then
rustup completions zsh cargo > $path_cargo_completion
fi
fpath=($dir_zsh $fpath)
zstyle ':completion:*:*:git:*' script $path_bash_git_completion
zstyle ':completion:*:default' menu select=2 # Highlight the selected option when using auto-complete.
# fzf shell support
#
# The `brew install fzf` installation provides an `install` script, which:
#
# Enables ctrl-r for fuzzy searching command history.
# Enables ctrl-t for selecting multiple files to append to command line (see also vf alias).
# Enables esc-c for cd'ing to the selected directory (esc == alt/meta).
#
path_fzf_script="$HOME/.fzf.zsh"
if test -f $path_fzf_script; then
source $path_fzf_script
else
$(brew --prefix)/opt/fzf/install
source $path_fzf_script
fi
# zsh-users/zsh-autosuggestions
#
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# zsh-users/zsh-syntax-highlighting
#
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# Terraform Autocomplete
#
complete -o nospace -C $(brew --prefix)/bin/terraform terraform
# 1Password Autocomplete
#
eval "$(op completion zsh)"; compdef _op op