-
Notifications
You must be signed in to change notification settings - Fork 1
/
change-case.zsh
40 lines (33 loc) · 1.17 KB
/
change-case.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
####################################################
# #
# Maintainer: Matheus Teixeira <[email protected]> #
# Website: http://mteixeira.me #
# Github: https://github.com/mtxr/zsh-change-case #
# #
####################################################
_mtxr-change-case () {
local ORIG_CASE=$1
local DEST_CASE=$2
local WLEFTCURSOR="${LBUFFER/* /}"
local WRIGHTCURSOR="${RBUFFER/ */}"
local CURRENTWORD="${WLEFTCURSOR}${WRIGHTCURSOR}"
local BEFOREWORD="${LBUFFER:0:($(( $CURSOR - $#WLEFTCURSOR)))}"
local AFTERWORD="${RBUFFER:($#WRIGHTCURSOR)}"
CURRENTWORD=$(echo "$CURRENTWORD" | tr "[:$ORIG_CASE:]" "[:$DEST_CASE:]")
LBUFFER="${BEFOREWORD}${CURRENTWORD}"
RBUFFER="${AFTERWORD}"
zle redisplay
}
_mtxr-to-upper () {
zle _mtxr-change-case -- 'lower' 'upper'
}
_mtxr-to-lower () {
zle _mtxr-change-case -- 'upper' 'lower'
}
zle -N _mtxr-change-case
zle -N _mtxr-to-upper
zle -N _mtxr-to-lower
# suggested default bind keys
# bindkey -r '^K' # to remove [Ctrl+K] binding if needed
# bindkey '^K^U' _mtxr-to-upper
# bindkey '^K^L' _mtxr-to-lower