Skip to content

Commit abc1a7b

Browse files
prime-runkRHYME7
andauthored
refactor(zsh): cleanup zsh for incoing fzf features
* add bat and fzf integration * won't accpet bat as core * Remove bat for now * / * Update .zshenv --------- Co-authored-by: Khing <[email protected]>
1 parent bb76750 commit abc1a7b

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

Configs/.config/fish/config.fish

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ if type -q starship
88
set -gx STARSHIP_CONFIG $XDG_CONFIG_HOME/starship/starship.toml
99
end
1010

11+
12+
# fzf
13+
if type -q fzf
14+
fzf --fish | source
15+
end
16+
# example integration with bat : <cltr+f>
17+
# bind -M insert \ce '$EDITOR $(fzf --preview="bat --color=always --plain {}")'
18+
19+
1120
set fish_pager_color_prefix cyan
1221
set fish_color_autosuggestion brblack
1322

Configs/.zshenv

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ function command_not_found_handler {
3838
return 127
3939
}
4040

41-
function load_zsh_plugins {
42-
unset -f load_zsh_plugins
41+
function _load_zsh_plugins {
42+
unset -f _load_zsh_plugins
4343
# Oh-my-zsh installation path
4444
zsh_paths=(
4545
"$HOME/.oh-my-zsh"
@@ -59,7 +59,7 @@ function load_zsh_plugins {
5959

6060
# Function to display a slow load warning
6161
# the intention is for hyprdots users who might have multiple zsh initialization
62-
function slow_load_warning {
62+
function _slow_load_warning {
6363
local lock_file="/tmp/.hyde_slow_load_warning.lock"
6464
local load_time=$SECONDS
6565

@@ -105,9 +105,10 @@ function no_such_file_or_directory_handler {
105105
return 127
106106
}
107107

108-
function load_persistent_aliases {
109-
#! Persistent Aliases are loaded after zshrc is loaded you cannot overwrite them
110-
unset -f load_persistent_aliases
108+
function _load_persistent_aliases {
109+
# Persistent aliases are loaded after the plugin is loaded
110+
# This way omz will not override them
111+
unset -f _load_persistent_aliases
111112

112113
if [[ -x "$(command -v eza)" ]]; then
113114
alias l='eza -lh --icons=auto' \
@@ -118,52 +119,43 @@ function load_persistent_aliases {
118119

119120
}
120121

121-
load_zsh_dot_files() {
122-
local dots
123-
local dot_dir="${ZDOTDIR:-$HOME}"
124-
dots=(
125-
"$dot_dir/.zprofile"
126-
"$dot_dir/.zshrc"
127-
"$dot_dir/.zlogin"
128-
"$dot_dir/.zlogout"
129-
)
130-
131-
for dot in "${dots[@]}"; do
132-
if [[ -f $dot ]]; then
133-
source "$dot"
134-
fi
135-
done
136-
137-
}
138-
139-
# Load oh-my-zsh when line editor initializes // before user input
140-
function load_omz_on_init() {
122+
function _load_omz_on_init() {
123+
# Load oh-my-zsh when line editor initializes // before user input
141124
if [[ -n $DEFER_OMZ_LOAD ]]; then
142125
unset DEFER_OMZ_LOAD
143126
[[ -r $ZSH/oh-my-zsh.sh ]] && source $ZSH/oh-my-zsh.sh
127+
ZDOTDIR="${__ZDOTDIR:-$HOME}"
128+
_load_post_init
129+
fi
130+
}
144131

145-
load_persistent_aliases
132+
function _load_post_init() {
133+
#! Never load time consuming functions here
134+
_load_persistent_aliases
135+
autoload -U compinit && compinit
146136

147-
# Load the .zshrc file
148-
ZDOTDIR="${__ZDOTDIR}"
149-
load_zsh_dot_files
150-
autoload -U compinit && compinit
137+
# Load hydectl completion
138+
if command -v hydectl &>/dev/null; then
139+
compdef _hydectl hydectl
140+
eval "$(hydectl completion zsh)"
141+
fi
151142

152-
# Load hydectl completion
153-
if command -v hydectl &>/dev/null; then
154-
compdef _hydectl hydectl
155-
eval "$(hydectl completion zsh)"
156-
fi
143+
# Initiate fzf
144+
if command -v fzf &>/dev/null; then
145+
eval "$(fzf --zsh)"
157146
fi
147+
148+
# User rc file always overrides
149+
[[ -f $HOME/.zshrc ]] && source $HOME/.zshrc
150+
158151
}
159152

160-
function load_if_terminal {
153+
function _load_if_terminal {
161154
if [ -t 1 ]; then
162155

163-
unset -f load_if_terminal
156+
unset -f _load_if_terminal
164157

165158
# Currently We are loading Starship and p10k prompts on start so users can see the prompt immediately
166-
# You can remove either starship or p10k to slightly improve start time
167159

168160
if command -v starship &>/dev/null; then
169161
# ===== START Initialize Starship prompt =====
@@ -189,15 +181,14 @@ function load_if_terminal {
189181
fi
190182

191183
# Load plugins
192-
load_zsh_plugins
184+
_load_zsh_plugins
193185

194186
# Load zsh hooks module once
195187

196188
#? Methods to load oh-my-zsh lazily
197189
__ZDOTDIR="${ZDOTDIR:-$HOME}"
198-
readonly __ZDOTDIR
199190
ZDOTDIR=/tmp
200-
zle -N zle-line-init load_omz_on_init # Loads when the line editor initializes // The best option
191+
zle -N zle-line-init _load_omz_on_init # Loads when the line editor initializes // The best option
201192

202193
autoload -Uz add-zsh-hook
203194
# add-zsh-hook zshaddhistory load_omz_deferred # loads after the first command is added to history
@@ -210,7 +201,7 @@ function load_if_terminal {
210201
# po='yay -Qtdq | ${PM_COMMAND[@]} -Rns -' # remove orphaned packages
211202

212203
# Warn if the shell is slow to load
213-
add-zsh-hook -Uz precmd slow_load_warning
204+
add-zsh-hook -Uz precmd _slow_load_warning
214205

215206
alias c='clear' \
216207
in='${PM_COMMAND[@]} install' \
@@ -266,4 +257,4 @@ export XDG_CONFIG_HOME XDG_CONFIG_DIR XDG_DATA_HOME XDG_STATE_HOME \
266257
XDG_MUSIC_DIR XDG_PICTURES_DIR XDG_VIDEOS_DIR \
267258
SCREENRC ZSH_AUTOSUGGEST_STRATEGY HISTFILE
268259

269-
load_if_terminal
260+
_load_if_terminal

0 commit comments

Comments
 (0)