ZSH: allows command swap key binding to support multiple groups
The groups are now separated by : character and each element in the group is separated by a space I have added a group for swapping ping and mtr
這個提交存在於:
父節點
2eeebca7fe
當前提交
e80443e891
共有 1 個檔案被更改,包括 8 行新增 和 1 行删除
|
@ -119,13 +119,20 @@ bindkey '\em' make_current_word_directory
|
|||
# This came about because I often find myself starting off with cd, tabbing and
|
||||
# realising I would have been better off starting the command with vim
|
||||
swap_command(){
|
||||
local commands=("cd" "vim" "ls")
|
||||
# Each group should be seperated by a colon with each item in a group
|
||||
# seperated by a space
|
||||
local groups="cd vim ls:ping mtr"
|
||||
local tokens=(${(z)LBUFFER})
|
||||
local cmd="${tokens[1]}"
|
||||
local newindex=0
|
||||
# If there is no command, return
|
||||
[ "$cmd" = "" ] && return 0
|
||||
|
||||
# Find the first group group with the current command
|
||||
local group="$(echo -en "$groups" | tr ':' '\n' | grep "$cmd" | head -n 1)"
|
||||
# Turn the chosen group into an array, splitting on a space
|
||||
local commands=(${(@s/ /)group})
|
||||
# Find out where the current command is in the list
|
||||
local currentindex=${commands[(ie)${cmd}]}
|
||||
|
||||
if [ "$currentindex" -gt "${#commands}" ]; then
|
||||
|
|
載入中…
新增表格
新增連結
新增問題並參考