comparison dot_zshrc @ 758:3a07cc5c825a

feat: add global expanding shortcuts copied from https://stackoverflow.com/questions/28573145/how-can-i-move-the-cursor-after-a-zsh-abbreviation
author zegervdv <zegervdv@me.com>
date Fri, 10 Mar 2023 16:02:39 +0000
parents a1a7841c55d2
children 0f6f809f1d39
comparison
equal deleted inserted replaced
757:b9d3378f6c9e 758:3a07cc5c825a
230 alias -s py=nvim 230 alias -s py=nvim
231 alias -s sv=nvim 231 alias -s sv=nvim
232 alias -s v=nvim 232 alias -s v=nvim
233 alias -s vhd=nvim 233 alias -s vhd=nvim
234 alias -s sh=nvim 234 alias -s sh=nvim
235 # Global aliases 235
236 alias -g X='| clip' 236 setopt extendedglob
237 typeset -Ag abbreviations
238 abbreviations=(
239 # "ac" "ack -C 5__CURSOR__--ignore-dir=.build"
240 "Ig" "| rg"
241 "Ip" "| $PAGER"
242 "Ih" "| head"
243 "Ik" "| keep"
244 "It" "| tail"
245 "Is" "| sort"
246 "Iv" "| ${VISUAL:-${EDITOR}}"
247 "Iw" "| wc"
248 "Ix" "| xargs"
249 "Ic" "| clip"
250 )
251
252 magic-abbrev-expand() {
253 local MATCH
254 LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
255 command=${abbreviations[$MATCH]}
256 LBUFFER+=${command:-$MATCH}
257
258 if [[ "${command}" =~ "__CURSOR__" ]]
259 then
260 RBUFFER=${LBUFFER[(ws:__CURSOR__:)2]}
261 LBUFFER=${LBUFFER[(ws:__CURSOR__:)1]}
262 else
263 zle self-insert
264 fi
265 }
266
267 no-magic-abbrev-expand() {
268 LBUFFER+=' '
269 }
270
271 zle -N magic-abbrev-expand
272 zle -N no-magic-abbrev-expand
273 bindkey " " magic-abbrev-expand
274 bindkey "^x " no-magic-abbrev-expand
275 bindkey -M isearch " " self-insert
237 276
238 # Exports 277 # Exports
239 export XDG_CONFIG_HOME=$HOME/.config 278 export XDG_CONFIG_HOME=$HOME/.config
240 export PATH=$HOME/bin:$PATH 279 export PATH=$HOME/bin:$PATH
241 280