From e80443e891730a994094458b15e3ca1d45af57c8 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Wed, 14 Oct 2020 12:29:16 +0100 Subject: [PATCH] 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 --- shells/zsh/includes/keybindings.zsh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shells/zsh/includes/keybindings.zsh b/shells/zsh/includes/keybindings.zsh index 31eb7920..82612de6 100644 --- a/shells/zsh/includes/keybindings.zsh +++ b/shells/zsh/includes/keybindings.zsh @@ -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